MediaWiki  REL1_22
serialize.php
Go to the documentation of this file.
00001 <?php
00024 if ( !defined( 'MEDIAWIKI' ) ) {
00025     $wgNoDBParam = true;
00026     $optionsWithArgs = array( 'o' );
00027     require_once __DIR__ .'/../maintenance/commandLine.inc';
00028 
00029     $stderr = fopen( 'php://stderr', 'w' );
00030     if ( !isset( $args[0] ) ) {
00031         fwrite( $stderr, "No input file specified\n" );
00032         exit( 1 );
00033     }
00034     if ( wfIsWindows() ) {
00035         $files = array();
00036         foreach ( $args as $arg ) {
00037             $files = array_merge( $files, glob( $arg ) );
00038         }
00039         if ( !$files ) {
00040             fwrite( $stderr, "No files found\n" );
00041         }
00042     } else {
00043         $files = $args;
00044     }
00045 
00046     if ( isset( $options['o'] ) ) {
00047         $out = fopen( $options['o'], 'wb' );
00048         if ( !$out ) {
00049             fwrite( $stderr, "Unable to open file \"{$options['o']}\" for output\n" );
00050             exit( 1 );
00051         }
00052     } else {
00053         $out = fopen( 'php://stdout', 'wb' );
00054     }
00055 
00056     $vars = array();
00057     foreach ( $files as $inputFile ) {
00058         $vars = array_merge( $vars, getVars( $inputFile ) );
00059     }
00060     fwrite( $out, serialize( $vars ) );
00061     fclose( $out );
00062     exit( 0 );
00063 }
00064 
00065 //----------------------------------------------------------------------------
00066 
00067 function getVars( $_gv_filename ) {
00068     require $_gv_filename;
00069     $vars = get_defined_vars();
00070     unset( $vars['_gv_filename'] );
00071 
00072     # Clean up line endings
00073     if ( wfIsWindows() ) {
00074         $vars = unixLineEndings( $vars );
00075     }
00076     return $vars;
00077 }
00078 
00079 function unixLineEndings( $var ) {
00080     static $recursionLevel = 0;
00081     if ( $recursionLevel > 50 ) {
00082         global $stderr;
00083         fwrite( $stderr, "Error: Recursion limit exceeded. Possible circular reference in array variable.\n" );
00084         exit( 2 );
00085     }
00086 
00087     if ( is_array( $var ) ) {
00088         ++$recursionLevel;
00089         $var = array_map( 'unixLineEndings', $var );
00090         --$recursionLevel;
00091     } elseif ( is_string( $var ) ) {
00092         $var = str_replace( "\r\n", "\n", $var );
00093     }
00094     return $var;
00095 }