Merge "prop=imageinfo&iiprop=url|thumbmime needs iiurlwidth="
[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( 'extensions-dir', 'Path where extensions can be found.', false, true );
37 $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
38 $this->mDescription = 'Merge $wgExtensionMessagesFiles from various extensions to produce a ' .
39 'single array containing all message files.';
40 }
41
42 public function execute() {
43 global $mmfl;
44
45 # Add setup files contained in file passed to --list-file
46 $lines = file( $this->getOption( 'list-file' ) );
47 if ( $lines === false ) {
48 $this->error( 'Unable to open list file.' );
49 }
50 $mmfl = array( 'setupFiles' => array_map( 'trim', $lines ) );
51
52 # Now find out files in a directory
53 $hasError = false;
54 if ( $this->hasOption( 'extensions-dir' ) ) {
55 $extdir = $this->getOption( 'extensions-dir' );
56 $entries = scandir( $extdir );
57 foreach( $entries as $extname ) {
58 if ( $extname == '.' || $extname == '..' || !is_dir( "$extdir/$extname" ) ) {
59 continue;
60 }
61 $extfile = "{$extdir}/{$extname}/{$extname}.php";
62 if ( file_exists( $extfile ) ) {
63 $mmfl['setupFiles'][] = $extfile;
64 } else {
65 $hasError = true;
66 $this->error( "Extension {$extname} in {$extdir} lacks expected {$extname}.php" );
67 }
68 }
69 }
70
71 if ( $hasError ) {
72 $this->error( "Some files are missing (see above). Giving up.", 1 );
73 }
74
75 if ( $this->hasOption( 'output' ) ) {
76 $mmfl['output'] = $this->getOption( 'output' );
77 }
78 }
79 }
80
81 require_once( RUN_MAINTENANCE_IF_MAIN );
82
83 foreach ( $mmfl['setupFiles'] as $fileName ) {
84 if ( strval( $fileName ) === '' ) {
85 continue;
86 }
87 $fileName = str_replace( '$IP', $IP, $fileName );
88 fwrite( STDERR, "Loading data from $fileName\n" );
89 include_once( $fileName );
90 }
91 fwrite( STDERR, "\n" );
92 $s =
93 "<" . "?php\n" .
94 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
95 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
96 '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n";
97
98 $dirs = array(
99 $IP,
100 dirname( dirname( __FILE__ ) ),
101 realpath( $IP )
102 );
103
104 foreach ( $dirs as $dir ) {
105 $s = preg_replace(
106 "/'" . preg_quote( $dir, '/' ) . "([^']*)'/",
107 '"$IP\1"',
108 $s );
109 }
110
111 if ( isset( $mmfl['output'] ) ) {
112 file_put_contents( $mmfl['output'], $s );
113 } else {
114 echo $s;
115 }
116