Merge "Add passing ''italic'''s case to 'Unclosed and unmatched quotes' test"
[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.', true, 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
44 $lines = file( $this->getOption( 'list-file' ) );
45 if ( $lines === false ) {
46 $this->error( 'Unable to open list file.' );
47 }
48 $mmfl = array( 'setupFiles' => array_map( 'trim', $lines ) );
49 if ( $this->hasOption( 'output' ) ) {
50 $mmfl['output'] = $this->getOption( 'output' );
51 }
52 }
53 }
54
55 require_once( RUN_MAINTENANCE_IF_MAIN );
56
57 foreach ( $mmfl['setupFiles'] as $fileName ) {
58 if ( strval( $fileName ) === '' ) {
59 continue;
60 }
61 $fileName = str_replace( '$IP', $IP, $fileName );
62 fwrite( STDERR, "Loading data from $fileName\n" );
63 include_once( $fileName );
64 }
65 fwrite( STDERR, "\n" );
66 $s =
67 "<" . "?php\n" .
68 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
69 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
70 '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n";
71
72 $dirs = array(
73 $IP,
74 dirname( dirname( __FILE__ ) ),
75 realpath( $IP )
76 );
77
78 foreach ( $dirs as $dir ) {
79 $s = preg_replace(
80 "/'" . preg_quote( $dir, '/' ) . "([^']*)'/",
81 '"$IP\1"',
82 $s );
83 }
84
85 if ( isset( $mmfl['output'] ) ) {
86 file_put_contents( $mmfl['output'], $s );
87 } else {
88 echo $s;
89 }
90