merge msg script now detects extensions main files
authorAntoine Musso <hashar@free.fr>
Thu, 31 May 2012 10:29:05 +0000 (12:29 +0200)
committerAntoine Musso <hashar@free.fr>
Fri, 6 Jul 2012 18:16:01 +0000 (20:16 +0200)
maintenance/mergeMessageFileList.php is used by `scap` to establish a
list of message files to load. To do that, it read extensions paths from
a manually maintained list: wmf-config/extension-list.

This patch adds an optional automatic detection system to add extension
messages. That will reduce the risk of forgetting to update the
extension-list file and will be of good use on labs.

The new parameter is named --extensions-dir and takes a path holding
MediaWiki extensions. The script will take the directory names there and
attempt to load a file named `Foobar/Foobar.php`. --list-file is still
required, you can skip it using /dev/null.

Synopsis:

php maintenance/mergeMessageFileList.php \
 --list-file /dev/null \
 --extensions-dir /srv/mw-trunk/extensions

Script will bail out whenever an expected PHP file is not found and will
list all of those "missing" files.

Change-Id: I8ab15f899f0333428fd8b2a98c58c07c2fce2962

maintenance/mergeMessageFileList.php

index 8669fe3..6a9baa8 100644 (file)
@@ -33,6 +33,7 @@ class MergeMessageFileList extends Maintenance {
        function __construct() {
                parent::__construct();
                $this->addOption( 'list-file', 'A file containing a list of extension setup files, one per line.', true, true );
+               $this->addOption( 'extensions-dir', 'Path where extensions can be found.', false, true );
                $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
                $this->mDescription = 'Merge $wgExtensionMessagesFiles from various extensions to produce a ' .
                        'single array containing all message files.';
@@ -41,11 +42,36 @@ class MergeMessageFileList extends Maintenance {
        public function execute() {
                global $mmfl;
 
+               # Add setup files contained in file passed to --list-file
                $lines = file( $this->getOption( 'list-file' ) );
                if ( $lines === false ) {
                        $this->error( 'Unable to open list file.' );
                }
                $mmfl = array( 'setupFiles' => array_map( 'trim', $lines ) );
+
+               # Now find out files in a directory
+               $hasError = false;
+               if ( $this->hasOption( 'extensions-dir' ) ) {
+                       $extdir = $this->getOption( 'extensions-dir' );
+                       $entries = scandir( $extdir );
+                       foreach( $entries as $extname ) {
+                               if ( $extname == '.' || $extname == '..' || !is_dir( "$extdir/$extname" ) ) {
+                                       continue;
+                               }
+                               $extfile = "{$extdir}/{$extname}/{$extname}.php";
+                               if ( file_exists( $extfile ) ) {
+                                       $mmfl['setupFiles'][] = $extfile;
+                               } else {
+                                       $hasError = true;
+                                       $this->error( "Extension {$extname} in {$extdir} lacks expected {$extname}.php" );
+                               }
+                       }
+               }
+
+               if ( $hasError ) {
+                       $this->error( "Some files are missing (see above). Giving up.", 1 );
+               }
+
                if ( $this->hasOption( 'output' ) ) {
                        $mmfl['output'] = $this->getOption( 'output' );
                }