3 if ( !defined( 'MEDIAWIKI' ) ) {
5 $optionsWithArgs = array( 'o' );
6 require_once( dirname(__FILE__
).'/../maintenance/commandLine.inc' );
8 $stderr = fopen( 'php://stderr', 'w' );
9 if ( !isset( $args[0] ) ) {
10 fwrite( $stderr, "No input file specified\n" );
13 if ( wfIsWindows() ) {
15 foreach ( $args as $arg ) {
16 $files = array_merge( $files, glob( $arg ) );
19 fwrite( $stderr, "No files found\n" );
25 if ( isset( $options['o'] ) ) {
26 $out = fopen( $options['o'], 'wb' );
28 fwrite( $stderr, "Unable to open file \"{$options['o']}\" for output\n" );
32 $out = fopen( 'php://stdout', 'wb' );
36 foreach ( $files as $inputFile ) {
37 $vars = array_merge( $vars, getVars( $inputFile ) );
39 fwrite( $out, serialize( $vars ) );
44 //----------------------------------------------------------------------------
46 function getVars( $_gv_filename ) {
47 require( $_gv_filename );
48 $vars = get_defined_vars();
49 unset( $vars['_gv_filename'] );
51 # Clean up line endings
52 if ( wfIsWindows() ) {
53 $vars = unixLineEndings( $vars );
58 function unixLineEndings( $var ) {
59 static $recursionLevel = 0;
60 if ( $recursionLevel > 50 ) {
62 fwrite( $stderr, "Error: Recursion limit exceeded. Possible circular reference in array variable.\n" );
66 if ( is_array( $var ) ) {
68 $var = array_map( 'unixLineEndings', $var );
70 } elseif ( is_string( $var ) ) {
71 $var = str_replace( "\r\n", "\n", $var );