Apply patch from Karsten Düsterloh in Bug #28103.
[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 $maintClass = 'MergeMessageFileList';
30 $mmfl = false;
31 class MergeMessageFileList extends Maintenance {
32
33 function __construct() {
34 parent::__construct();
35 $this->addOption( 'list-file', 'A file containing a list of extension setup files, one per line.', false, true );
36 $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
37 $this->mDescription = 'Merge $wgExtensionMessagesFiles from various extensions to produce a ' .
38 'single array containing all message files.';
39 }
40
41 public function execute() {
42 global $mmfl;
43 if ( !$this->hasOption( 'list-file' ) ) {
44 $this->error( 'The --list-file option must be specified.' );
45 return;
46 }
47
48 $lines = file( $this->getOption( 'list-file' ) );
49 if ( $lines === false ) {
50 $this->error( 'Unable to open list file.' );
51 }
52 $mmfl = array( 'setupFiles' => array_map( 'trim', $lines ) );
53 if ( $this->hasOption( 'output' ) ) {
54 $mmfl['output'] = $this->getOption( 'output' );
55 }
56 }
57 }
58
59 require_once( RUN_MAINTENANCE_IF_MAIN );
60
61 foreach ( $mmfl['setupFiles'] as $fileName ) {
62 if ( strval( $fileName ) === '' ) {
63 continue;
64 }
65 $fileName = str_replace( '$IP', $IP, $fileName );
66 fwrite( STDERR, "Loading data from $fileName\n" );
67 include_once( $fileName );
68 }
69 fwrite( STDERR, "\n" );
70 $s =
71 "<" . "?php\n" .
72 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
73 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
74 '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n" .
75 '$wgExtensionAliasesFiles = ' . var_export( $wgExtensionAliasesFiles, true ) . ";\n";
76
77 $dirs = array(
78 $IP,
79 dirname( dirname( __FILE__ ) ),
80 realpath( $IP )
81 );
82
83 foreach ( $dirs as $dir ) {
84 $s = preg_replace(
85 "/'" . preg_quote( $dir, '/' ) . "([^']*)'/",
86 '"$IP\1"',
87 $s );
88 }
89
90 if ( isset( $mmfl['output'] ) ) {
91 file_put_contents( $mmfl['output'], $s );
92 } else {
93 echo $s;
94 }
95