MediaWiki  REL1_19
serialize.php
Go to the documentation of this file.
00001 <?php
00002 
00003 if ( !defined( 'MEDIAWIKI' ) ) {
00004         $wgNoDBParam = true;
00005         $optionsWithArgs = array( 'o' );
00006         require_once( dirname(__FILE__).'/../maintenance/commandLine.inc' );
00007 
00008         $stderr = fopen( 'php://stderr', 'w' );
00009         if ( !isset( $args[0] ) ) {
00010                 fwrite( $stderr, "No input file specified\n" );
00011                 exit( 1 );
00012         }
00013         if ( wfIsWindows() ) {
00014                 $files = array();
00015                 foreach ( $args as $arg ) {
00016                         $files = array_merge( $files, glob( $arg ) );
00017                 }
00018                 if ( !$files ) {
00019                         fwrite( $stderr, "No files found\n" );
00020                 }
00021         } else {
00022                 $files = $args;
00023         }
00024 
00025         if ( isset( $options['o'] ) ) {
00026                 $out = fopen( $options['o'], 'wb' );
00027                 if ( !$out ) {
00028                         fwrite( $stderr, "Unable to open file \"{$options['o']}\" for output\n" );
00029                         exit( 1 );
00030                 }
00031         } else {
00032                 $out = fopen( 'php://stdout', 'wb' );
00033         }
00034 
00035         $vars = array();
00036         foreach ( $files as $inputFile ) {
00037                 $vars = array_merge( $vars, getVars( $inputFile ) );
00038         }
00039         fwrite( $out, serialize( $vars ) );
00040         fclose( $out );
00041         exit( 0 );
00042 }
00043 
00044 //----------------------------------------------------------------------------
00045 
00046 function getVars( $_gv_filename ) {
00047         require( $_gv_filename );
00048         $vars = get_defined_vars();
00049         unset( $vars['_gv_filename'] );
00050 
00051         # Clean up line endings
00052         if ( wfIsWindows() ) {
00053                 $vars = unixLineEndings( $vars );
00054         }
00055         return $vars;
00056 }
00057 
00058 function unixLineEndings( $var ) {
00059         static $recursionLevel = 0;
00060         if ( $recursionLevel > 50 ) {
00061                 global $stderr;
00062                 fwrite( $stderr, "Error: Recursion limit exceeded. Possible circular reference in array variable.\n" );
00063                 exit( 2 );
00064         }
00065         
00066         if ( is_array( $var ) ) {
00067                 ++$recursionLevel;
00068                 $var = array_map( 'unixLineEndings', $var );
00069                 --$recursionLevel;
00070         } elseif ( is_string( $var ) ) {
00071                 $var = str_replace( "\r\n", "\n", $var );
00072         }
00073         return $var;
00074 }
00075