Merge "Whitelist the <wbr> element."
[mediawiki.git] / serialized / serialize.php
blob766c1a5116a051bdc4d18364ee7266ff35531679
1 <?php
2 /**
3 * Serialize variables found in input file and store the result in the
4 * specified file.
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
21 * @file
24 if ( !defined( 'MEDIAWIKI' ) ) {
25 $wgNoDBParam = true;
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" );
32 exit( 1 );
34 if ( wfIsWindows() ) {
35 $files = array();
36 foreach ( $args as $arg ) {
37 $files = array_merge( $files, glob( $arg ) );
39 if ( !$files ) {
40 fwrite( $stderr, "No files found\n" );
42 } else {
43 $files = $args;
46 if ( isset( $options['o'] ) ) {
47 $out = fopen( $options['o'], 'wb' );
48 if ( !$out ) {
49 fwrite( $stderr, "Unable to open file \"{$options['o']}\" for output\n" );
50 exit( 1 );
52 } else {
53 $out = fopen( 'php://stdout', 'wb' );
56 $vars = array();
57 foreach ( $files as $inputFile ) {
58 $vars = array_merge( $vars, getVars( $inputFile ) );
60 fwrite( $out, serialize( $vars ) );
61 fclose( $out );
62 exit( 0 );
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 );
76 return $vars;
79 function unixLineEndings( $var ) {
80 static $recursionLevel = 0;
81 if ( $recursionLevel > 50 ) {
82 global $stderr;
83 fwrite( $stderr, "Error: Recursion limit exceeded. Possible circular reference in array variable.\n" );
84 exit( 2 );
87 if ( is_array( $var ) ) {
88 ++$recursionLevel;
89 $var = array_map( 'unixLineEndings', $var );
90 --$recursionLevel;
91 } elseif ( is_string( $var ) ) {
92 $var = str_replace( "\r\n", "\n", $var );
94 return $var;