3 * Serialize variables found in input file and store the result in the
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
24 if ( !defined( 'MEDIAWIKI' ) ) {
26 $optionsWithArgs = array( 'o' );
27 require_once __DIR__
.'/../maintenance/commandLine.inc';
29 $stderr = fopen( 'php://stderr', 'w' );
30 if ( !isset( $args[0] ) ) {
31 fwrite( $stderr, "No input file specified\n" );
34 if ( wfIsWindows() ) {
36 foreach ( $args as $arg ) {
37 $files = array_merge( $files, glob( $arg ) );
40 fwrite( $stderr, "No files found\n" );
46 if ( isset( $options['o'] ) ) {
47 $out = fopen( $options['o'], 'wb' );
49 fwrite( $stderr, "Unable to open file \"{$options['o']}\" for output\n" );
53 $out = fopen( 'php://stdout', 'wb' );
57 foreach ( $files as $inputFile ) {
58 $vars = array_merge( $vars, getVars( $inputFile ) );
60 fwrite( $out, serialize( $vars ) );
65 //----------------------------------------------------------------------------
67 function getVars( $_gv_filename ) {
68 require $_gv_filename;
69 $vars = get_defined_vars();
70 unset( $vars['_gv_filename'] );
72 # Clean up line endings
73 if ( wfIsWindows() ) {
74 $vars = unixLineEndings( $vars );
79 function unixLineEndings( $var ) {
80 static $recursionLevel = 0;
81 if ( $recursionLevel > 50 ) {
83 fwrite( $stderr, "Error: Recursion limit exceeded. Possible circular reference in array variable.\n" );
87 if ( is_array( $var ) ) {
89 $var = array_map( 'unixLineEndings', $var );
91 } elseif ( is_string( $var ) ) {
92 $var = str_replace( "\r\n", "\n", $var );