3 * Merge $wgExtensionMessagesFiles from various extensions to produce a
4 * single array containing all message files.
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.
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.
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
22 * @ingroup Maintenance
26 define( 'MW_NO_EXTENSION_MESSAGES', 1 );
28 require_once __DIR__
. '/Maintenance.php';
29 $maintClass = 'MergeMessageFileList';
33 * Maintenance script that merges $wgExtensionMessagesFiles from various
34 * extensions to produce a single array containing all message files.
36 * @ingroup Maintenance
38 class MergeMessageFileList
extends Maintenance
{
40 function __construct() {
41 parent
::__construct();
42 $this->addOption( 'list-file', 'A file containing a list of extension setup files, one per line.', true, true );
43 $this->addOption( 'extensions-dir', 'Path where extensions can be found.', false, true );
44 $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
45 $this->mDescription
= 'Merge $wgExtensionMessagesFiles from various extensions to produce a ' .
46 'single array containing all message files.';
49 public function execute() {
52 # Add setup files contained in file passed to --list-file
53 $lines = file( $this->getOption( 'list-file' ) );
54 if ( $lines === false ) {
55 $this->error( 'Unable to open list file.' );
57 $mmfl = array( 'setupFiles' => array_map( 'trim', $lines ) );
59 # Now find out files in a directory
61 if ( $this->hasOption( 'extensions-dir' ) ) {
62 $extdir = $this->getOption( 'extensions-dir' );
63 $entries = scandir( $extdir );
64 foreach ( $entries as $extname ) {
65 if ( $extname == '.' ||
$extname == '..' ||
!is_dir( "$extdir/$extname" ) ) {
68 $extfile = "{$extdir}/{$extname}/{$extname}.php";
69 if ( file_exists( $extfile ) ) {
70 $mmfl['setupFiles'][] = $extfile;
73 $this->error( "Extension {$extname} in {$extdir} lacks expected {$extname}.php" );
79 $this->error( "Some files are missing (see above). Giving up.", 1 );
82 if ( $this->hasOption( 'output' ) ) {
83 $mmfl['output'] = $this->getOption( 'output' );
85 if ( $this->hasOption( 'quiet' ) ) {
86 $mmfl['quiet'] = true;
91 require_once RUN_MAINTENANCE_IF_MAIN
;
93 foreach ( $mmfl['setupFiles'] as $fileName ) {
94 if ( strval( $fileName ) === '' ) {
97 $fileName = str_replace( '$IP', $IP, $fileName );
98 if ( empty( $mmfl['quiet'] ) ) {
99 fwrite( STDERR
, "Loading data from $fileName\n" );
101 if ( !( include_once $fileName ) ) {
102 fwrite( STDERR
, "Unable to read $fileName\n" );
106 fwrite( STDERR
, "\n" );
109 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
110 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
111 '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n";
119 foreach ( $dirs as $dir ) {
121 "/'" . preg_quote( $dir, '/' ) . "([^']*)'/",
126 if ( isset( $mmfl['output'] ) ) {
127 file_put_contents( $mmfl['output'], $s );