a9142022187bd91139cff2d57bf06b89f9566faf
[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 $this->addOption( 'list-file', 'A file containing a list of extension setup files, one per line.', false, 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 global $mmfl;
42 if ( !$this->hasOption( 'list-file' ) ) {
43 $this->error( 'The --list-file option must be specified.' );
44 return;
45 }
46
47 $lines = file( $this->getOption( 'list-file' ) );
48 if ( $lines === false ) {
49 $this->error( 'Unable to open list file.' );
50 }
51 $mmfl = array( 'setupFiles' => array_map( 'trim', $lines ) );
52 if ( $this->hasOption( 'output' ) ) {
53 $mmfl['output'] = $this->getOption( 'output' );
54 }
55 }
56 }
57
58 require_once( DO_MAINTENANCE );
59
60 foreach ( $mmfl['setupFiles'] as $fileName ) {
61 if ( strval( $fileName ) === '' ) {
62 continue;
63 }
64 $fileName = str_replace( '$IP', $IP, $fileName );
65 fwrite( STDERR, "Loading data from $fileName\n" );
66 include_once( $fileName );
67 }
68 fwrite( STDERR, "\n" );
69 $s =
70 "<" . "?php\n" .
71 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
72 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
73 '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n" .
74 '$wgExtensionAliasesFiles = ' . var_export( $wgExtensionAliasesFiles, true ) . ";\n";
75
76 $dirs = array(
77 $IP,
78 dirname( dirname( __FILE__ ) ),
79 realpath( $IP )
80 );
81
82 foreach ( $dirs as $dir ) {
83 $s = preg_replace(
84 "/'" . preg_quote( $dir, '/' ) . "([^']*)'/",
85 '"$IP\1"',
86 $s );
87 }
88
89 if ( isset( $mmfl['output'] ) ) {
90 file_put_contents( $mmfl['output'], $s );
91 } else {
92 echo $s;
93 }
94