Merge "Added pool counter support for all thumb.php requests"
[lhc/web/wiklou.git] / maintenance / rebuildLocalisationCache.php
index 83849de..cfcb950 100644 (file)
@@ -29,7 +29,7 @@
  * @ingroup Maintenance
  */
 
-require_once( __DIR__ . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
 
 /**
  * Maintenance script to rebuild the localisation cache.
@@ -44,6 +44,8 @@ class RebuildLocalisationCache extends Maintenance {
                $this->addOption( 'threads', 'Fork more than one thread', false, true );
                $this->addOption( 'outdir', 'Override the output directory (normally $wgCacheDirectory)',
                        false, true );
+               $this->addOption( 'lang', 'Only rebuild these languages, comma separated.',
+                       false, true );
        }
 
        public function memoryLimit() {
@@ -53,6 +55,15 @@ class RebuildLocalisationCache extends Maintenance {
                return '1000M';
        }
 
+       public function finalSetup() {
+               # This script needs to be run to build the inital l10n cache. But if
+               # $wgLanguageCode is not 'en', it won't be able to run because there is
+               # no l10n cache. Break the cycle by forcing $wgLanguageCode = 'en'.
+               global $wgLanguageCode;
+               $wgLanguageCode = 'en';
+               parent::finalSetup();
+       }
+
        public function execute() {
                global $wgLocalisationCacheConf;
 
@@ -79,9 +90,21 @@ class RebuildLocalisationCache extends Maintenance {
                if ( $this->hasOption( 'outdir' ) ) {
                        $conf['storeDirectory'] = $this->getOption( 'outdir' );
                }
-               $lc = new LocalisationCache_BulkLoad( $conf );
+               $lc = new LocalisationCacheBulkLoad( $conf );
 
-               $codes = array_keys( Language::fetchLanguageNames( null, 'mwfile' ) );
+               $allCodes = array_keys( Language::fetchLanguageNames( null, 'mwfile' ) );
+               if ( $this->hasOption( 'lang' ) ) {
+                       # Validate requested languages
+                       $codes = array_intersect( $allCodes,
+                               explode( ',', $this->getOption( 'lang' ) ) );
+                       # Bailed out if nothing is left
+                       if ( count( $codes ) == 0 ) {
+                               $this->error( 'None of the languages specified exists.', 1 );
+                       }
+               } else {
+                       # By default get all languages
+                       $codes = $allCodes;
+               }
                sort( $codes );
 
                // Initialise and split into chunks
@@ -125,9 +148,9 @@ class RebuildLocalisationCache extends Maintenance {
        /**
         * Helper function to rebuild list of languages codes. Prints the code
         * for each language which is rebuilt.
-        * @param $codes array List of language codes to rebuild.
-        * @param $lc LocalisationCache Instance of LocalisationCache_BulkLoad (?)
-        * @param $force bool Rebuild up-to-date languages
+        * @param array $codes  List of language codes to rebuild.
+        * @param LocalisationCache $lc Instance of LocalisationCacheBulkLoad (?)
+        * @param bool $force Rebuild up-to-date languages
         * @return int Number of rebuilt languages
         */
        private function doRebuild( $codes, $lc, $force ) {
@@ -153,4 +176,4 @@ class RebuildLocalisationCache extends Maintenance {
 }
 
 $maintClass = "RebuildLocalisationCache";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;