Reverted r99195 quick-fix per r99897
[lhc/web/wiklou.git] / maintenance / mergeMessageFileList.php
1 <?php
2 /**
3 * Merge $wgExtensionMessagesFiles from various extensions to produce a
4 * single array containing all message files.
5 *
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.
10 *
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.
15 *
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
20 *
21 * @file
22 * @ingroup Maintenance
23 */
24
25 # Start from scratch
26 define( 'MW_NO_EXTENSION_MESSAGES', 1 );
27
28 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
29
30 class MergeMessageFileList extends Maintenance {
31
32 function __construct() {
33 parent::__construct();
34 $this->addOption( 'list-file', 'A file containing a list of extension setup files, one per line.', true, true );
35 $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
36 $this->mDescription = 'Merge $wgExtensionMessagesFiles from various extensions to produce a ' .
37 'single array containing all message files.';
38 }
39
40 public function execute() {
41 $lines = file( $this->getOption( 'list-file' ) );
42 if ( $lines === false ) {
43 $this->error( 'Unable to open list file.' );
44 }
45 $mmfl = array( 'setupFiles' => array_map( 'trim', $lines ) );
46 if ( $this->hasOption( 'output' ) ) {
47 $mmfl['output'] = $this->getOption( 'output' );
48 }
49
50 global $IP, $wgExtensionMessagesFiles, $wgExtensionAliasesFiles;
51 foreach ( $mmfl['setupFiles'] as $fileName ) {
52 if ( strval( $fileName ) === '' ) {
53 continue;
54 }
55 $fileName = str_replace( '$IP', $IP, $fileName );
56 fwrite( STDERR, "Loading data from $fileName\n" );
57 include_once( $fileName );
58 }
59 fwrite( STDERR, "\n" );
60 $s =
61 "<" . "?php\n" .
62 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
63 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
64 '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n" .
65 '$wgExtensionAliasesFiles = ' . var_export( $wgExtensionAliasesFiles, true ) . ";\n";
66
67 $dirs = array(
68 $IP,
69 dirname( dirname( __FILE__ ) ),
70 realpath( $IP )
71 );
72
73 foreach ( $dirs as $dir ) {
74 $s = preg_replace(
75 "/'" . preg_quote( $dir, '/' ) . "([^']*)'/",
76 '"$IP\1"',
77 $s );
78 }
79
80 if ( isset( $mmfl['output'] ) ) {
81 file_put_contents( $mmfl['output'], $s );
82 } else {
83 echo $s;
84 }
85 }
86 }
87
88 $maintClass = 'MergeMessageFileList';
89 require_once( RUN_MAINTENANCE_IF_MAIN );