* Introduced a new system for localisation caching. The system is based around fast fetches of individual messages, minimising memory overhead and startup time in the typical case. It handles both core messages (formerly in Language.php) and extension messages (formerly in MessageCache.php). Profiling indicates a significant win for average throughput.
* The serialized message cache, which would have been redundant, has been removed. Similar performance characteristics can be achieved with $wgLocalisationCacheConf['manualRecache'] = true;
* Added a maintenance script rebuildLocalisationCache.php for offline rebuilding of the localisation cache.
* Extension i18n files can now contain any of the variables which can be set in Messages*.php. It is possible, and recommended, to use this feature instead of the hooks for special page aliases and magic words.
* $wgExtensionAliasesFiles, LanguageGetMagic and LanguageGetSpecialPageAliases are retained for backwards compatibility. $wgMessageCache->addMessages() and related functions have been removed. wfLoadExtensionMessages() is a no-op and can continue to be called for b/c.
* Introduced $wgCacheDirectory as a default location for the various local caches that have accumulated. Suggested $IP/cache as a good place for it in the default LocalSettings.php and created this directory with a deny-all .htaccess.
* Patched Exception.php to avoid using the message cache when an exception is thrown from within LocalisationCache, since this tends to fail horribly.
* Removed Language::getLocalisationArray(), Language::loadLocalisation(), Language::load()
* Fixed FileDependency::__sleep()
* In Cdb.php, fixed newlines in debug messages
In MessageCache::get():
* Replaced calls to $wgContLang capitalisation functions with plain PHP functions, reducing the typical case from 99us to 93us. Message cache keys are already documented as being restricted to ASCII.
* Implemented a more efficient way to filter out bogus language codes, reducing the "foo/en" case from 430us to 101us
* Optimised wfRunHooks() in the typical do-nothing case, from ~30us to ~3us. This reduced MessageCache::get() typical case time from 93us to 38us.
* Removed hook MessageNotInMwNs to save an extra 3us per cache hit. Reimplemented the only user (LocalisationUpdate) using the new hook LocalisationCacheRecache.
2009-06-28 07:11:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rebuild the localisation cache. Useful if you disabled automatic updates
|
|
|
|
|
* using $wgLocalisationCacheConf['manualRecache'] = true;
|
|
|
|
|
*
|
|
|
|
|
* Usage:
|
2009-08-13 16:42:44 +00:00
|
|
|
* php rebuildLocalisationCache.php [--force] [--threads=N]
|
* Introduced a new system for localisation caching. The system is based around fast fetches of individual messages, minimising memory overhead and startup time in the typical case. It handles both core messages (formerly in Language.php) and extension messages (formerly in MessageCache.php). Profiling indicates a significant win for average throughput.
* The serialized message cache, which would have been redundant, has been removed. Similar performance characteristics can be achieved with $wgLocalisationCacheConf['manualRecache'] = true;
* Added a maintenance script rebuildLocalisationCache.php for offline rebuilding of the localisation cache.
* Extension i18n files can now contain any of the variables which can be set in Messages*.php. It is possible, and recommended, to use this feature instead of the hooks for special page aliases and magic words.
* $wgExtensionAliasesFiles, LanguageGetMagic and LanguageGetSpecialPageAliases are retained for backwards compatibility. $wgMessageCache->addMessages() and related functions have been removed. wfLoadExtensionMessages() is a no-op and can continue to be called for b/c.
* Introduced $wgCacheDirectory as a default location for the various local caches that have accumulated. Suggested $IP/cache as a good place for it in the default LocalSettings.php and created this directory with a deny-all .htaccess.
* Patched Exception.php to avoid using the message cache when an exception is thrown from within LocalisationCache, since this tends to fail horribly.
* Removed Language::getLocalisationArray(), Language::loadLocalisation(), Language::load()
* Fixed FileDependency::__sleep()
* In Cdb.php, fixed newlines in debug messages
In MessageCache::get():
* Replaced calls to $wgContLang capitalisation functions with plain PHP functions, reducing the typical case from 99us to 93us. Message cache keys are already documented as being restricted to ASCII.
* Implemented a more efficient way to filter out bogus language codes, reducing the "foo/en" case from 430us to 101us
* Optimised wfRunHooks() in the typical do-nothing case, from ~30us to ~3us. This reduced MessageCache::get() typical case time from 93us to 38us.
* Removed hook MessageNotInMwNs to save an extra 3us per cache hit. Reimplemented the only user (LocalisationUpdate) using the new hook LocalisationCacheRecache.
2009-06-28 07:11:43 +00:00
|
|
|
*
|
|
|
|
|
* Use --force to rebuild all files, even the ones that are not out of date.
|
2009-07-31 09:57:59 +00:00
|
|
|
* Use --threads=N to fork more threads.
|
2009-08-02 19:35:17 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
* Introduced a new system for localisation caching. The system is based around fast fetches of individual messages, minimising memory overhead and startup time in the typical case. It handles both core messages (formerly in Language.php) and extension messages (formerly in MessageCache.php). Profiling indicates a significant win for average throughput.
* The serialized message cache, which would have been redundant, has been removed. Similar performance characteristics can be achieved with $wgLocalisationCacheConf['manualRecache'] = true;
* Added a maintenance script rebuildLocalisationCache.php for offline rebuilding of the localisation cache.
* Extension i18n files can now contain any of the variables which can be set in Messages*.php. It is possible, and recommended, to use this feature instead of the hooks for special page aliases and magic words.
* $wgExtensionAliasesFiles, LanguageGetMagic and LanguageGetSpecialPageAliases are retained for backwards compatibility. $wgMessageCache->addMessages() and related functions have been removed. wfLoadExtensionMessages() is a no-op and can continue to be called for b/c.
* Introduced $wgCacheDirectory as a default location for the various local caches that have accumulated. Suggested $IP/cache as a good place for it in the default LocalSettings.php and created this directory with a deny-all .htaccess.
* Patched Exception.php to avoid using the message cache when an exception is thrown from within LocalisationCache, since this tends to fail horribly.
* Removed Language::getLocalisationArray(), Language::loadLocalisation(), Language::load()
* Fixed FileDependency::__sleep()
* In Cdb.php, fixed newlines in debug messages
In MessageCache::get():
* Replaced calls to $wgContLang capitalisation functions with plain PHP functions, reducing the typical case from 99us to 93us. Message cache keys are already documented as being restricted to ASCII.
* Implemented a more efficient way to filter out bogus language codes, reducing the "foo/en" case from 430us to 101us
* Optimised wfRunHooks() in the typical do-nothing case, from ~30us to ~3us. This reduced MessageCache::get() typical case time from 93us to 38us.
* Removed hook MessageNotInMwNs to save an extra 3us per cache hit. Reimplemented the only user (LocalisationUpdate) using the new hook LocalisationCacheRecache.
2009-06-28 07:11:43 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
require_once( dirname( __FILE__ ) . '/Maintenance.php' );
|
* Introduced a new system for localisation caching. The system is based around fast fetches of individual messages, minimising memory overhead and startup time in the typical case. It handles both core messages (formerly in Language.php) and extension messages (formerly in MessageCache.php). Profiling indicates a significant win for average throughput.
* The serialized message cache, which would have been redundant, has been removed. Similar performance characteristics can be achieved with $wgLocalisationCacheConf['manualRecache'] = true;
* Added a maintenance script rebuildLocalisationCache.php for offline rebuilding of the localisation cache.
* Extension i18n files can now contain any of the variables which can be set in Messages*.php. It is possible, and recommended, to use this feature instead of the hooks for special page aliases and magic words.
* $wgExtensionAliasesFiles, LanguageGetMagic and LanguageGetSpecialPageAliases are retained for backwards compatibility. $wgMessageCache->addMessages() and related functions have been removed. wfLoadExtensionMessages() is a no-op and can continue to be called for b/c.
* Introduced $wgCacheDirectory as a default location for the various local caches that have accumulated. Suggested $IP/cache as a good place for it in the default LocalSettings.php and created this directory with a deny-all .htaccess.
* Patched Exception.php to avoid using the message cache when an exception is thrown from within LocalisationCache, since this tends to fail horribly.
* Removed Language::getLocalisationArray(), Language::loadLocalisation(), Language::load()
* Fixed FileDependency::__sleep()
* In Cdb.php, fixed newlines in debug messages
In MessageCache::get():
* Replaced calls to $wgContLang capitalisation functions with plain PHP functions, reducing the typical case from 99us to 93us. Message cache keys are already documented as being restricted to ASCII.
* Implemented a more efficient way to filter out bogus language codes, reducing the "foo/en" case from 430us to 101us
* Optimised wfRunHooks() in the typical do-nothing case, from ~30us to ~3us. This reduced MessageCache::get() typical case time from 93us to 38us.
* Removed hook MessageNotInMwNs to save an extra 3us per cache hit. Reimplemented the only user (LocalisationUpdate) using the new hook LocalisationCacheRecache.
2009-06-28 07:11:43 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
class RebuildLocalisationCache extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->mDescription = "Rebuild the localisation cache";
|
|
|
|
|
$this->addOption( 'force', 'Rebuild all files, even ones not out of date' );
|
|
|
|
|
$this->addOption( 'threads', 'Fork more than one thread', false, true );
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-09-14 22:10:10 +00:00
|
|
|
public function memoryLimit() {
|
|
|
|
|
return '200M';
|
|
|
|
|
}
|
* Introduced a new system for localisation caching. The system is based around fast fetches of individual messages, minimising memory overhead and startup time in the typical case. It handles both core messages (formerly in Language.php) and extension messages (formerly in MessageCache.php). Profiling indicates a significant win for average throughput.
* The serialized message cache, which would have been redundant, has been removed. Similar performance characteristics can be achieved with $wgLocalisationCacheConf['manualRecache'] = true;
* Added a maintenance script rebuildLocalisationCache.php for offline rebuilding of the localisation cache.
* Extension i18n files can now contain any of the variables which can be set in Messages*.php. It is possible, and recommended, to use this feature instead of the hooks for special page aliases and magic words.
* $wgExtensionAliasesFiles, LanguageGetMagic and LanguageGetSpecialPageAliases are retained for backwards compatibility. $wgMessageCache->addMessages() and related functions have been removed. wfLoadExtensionMessages() is a no-op and can continue to be called for b/c.
* Introduced $wgCacheDirectory as a default location for the various local caches that have accumulated. Suggested $IP/cache as a good place for it in the default LocalSettings.php and created this directory with a deny-all .htaccess.
* Patched Exception.php to avoid using the message cache when an exception is thrown from within LocalisationCache, since this tends to fail horribly.
* Removed Language::getLocalisationArray(), Language::loadLocalisation(), Language::load()
* Fixed FileDependency::__sleep()
* In Cdb.php, fixed newlines in debug messages
In MessageCache::get():
* Replaced calls to $wgContLang capitalisation functions with plain PHP functions, reducing the typical case from 99us to 93us. Message cache keys are already documented as being restricted to ASCII.
* Implemented a more efficient way to filter out bogus language codes, reducing the "foo/en" case from 430us to 101us
* Optimised wfRunHooks() in the typical do-nothing case, from ~30us to ~3us. This reduced MessageCache::get() typical case time from 93us to 38us.
* Removed hook MessageNotInMwNs to save an extra 3us per cache hit. Reimplemented the only user (LocalisationUpdate) using the new hook LocalisationCacheRecache.
2009-06-28 07:11:43 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
|
|
|
|
global $wgLocalisationCacheConf;
|
* Introduced a new system for localisation caching. The system is based around fast fetches of individual messages, minimising memory overhead and startup time in the typical case. It handles both core messages (formerly in Language.php) and extension messages (formerly in MessageCache.php). Profiling indicates a significant win for average throughput.
* The serialized message cache, which would have been redundant, has been removed. Similar performance characteristics can be achieved with $wgLocalisationCacheConf['manualRecache'] = true;
* Added a maintenance script rebuildLocalisationCache.php for offline rebuilding of the localisation cache.
* Extension i18n files can now contain any of the variables which can be set in Messages*.php. It is possible, and recommended, to use this feature instead of the hooks for special page aliases and magic words.
* $wgExtensionAliasesFiles, LanguageGetMagic and LanguageGetSpecialPageAliases are retained for backwards compatibility. $wgMessageCache->addMessages() and related functions have been removed. wfLoadExtensionMessages() is a no-op and can continue to be called for b/c.
* Introduced $wgCacheDirectory as a default location for the various local caches that have accumulated. Suggested $IP/cache as a good place for it in the default LocalSettings.php and created this directory with a deny-all .htaccess.
* Patched Exception.php to avoid using the message cache when an exception is thrown from within LocalisationCache, since this tends to fail horribly.
* Removed Language::getLocalisationArray(), Language::loadLocalisation(), Language::load()
* Fixed FileDependency::__sleep()
* In Cdb.php, fixed newlines in debug messages
In MessageCache::get():
* Replaced calls to $wgContLang capitalisation functions with plain PHP functions, reducing the typical case from 99us to 93us. Message cache keys are already documented as being restricted to ASCII.
* Implemented a more efficient way to filter out bogus language codes, reducing the "foo/en" case from 430us to 101us
* Optimised wfRunHooks() in the typical do-nothing case, from ~30us to ~3us. This reduced MessageCache::get() typical case time from 93us to 38us.
* Removed hook MessageNotInMwNs to save an extra 3us per cache hit. Reimplemented the only user (LocalisationUpdate) using the new hook LocalisationCacheRecache.
2009-06-28 07:11:43 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
$force = $this->hasOption( 'force' );
|
2009-08-02 19:35:17 +00:00
|
|
|
$threads = $this->getOption( 'threads', 1 );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $threads < 1 || $threads != intval( $threads ) ) {
|
2009-08-19 00:26:59 +00:00
|
|
|
$this->output( "Invalid thread count specified; running single-threaded.\n" );
|
|
|
|
|
$threads = 1;
|
|
|
|
|
}
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $threads > 1 && wfIsWindows() ) {
|
2009-08-19 00:26:59 +00:00
|
|
|
$this->output( "Threaded rebuild is not supported on Windows; running single-threaded.\n" );
|
|
|
|
|
$threads = 1;
|
|
|
|
|
}
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $threads > 1 && !function_exists( 'pcntl_fork' ) ) {
|
2009-08-19 00:26:59 +00:00
|
|
|
$this->output( "PHP pcntl extension is not present; running single-threaded.\n" );
|
|
|
|
|
$threads = 1;
|
|
|
|
|
}
|
2009-07-31 09:57:59 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$conf = $wgLocalisationCacheConf;
|
|
|
|
|
$conf['manualRecache'] = false; // Allow fallbacks to create CDB files
|
|
|
|
|
if ( $force ) {
|
|
|
|
|
$conf['forceRecache'] = true;
|
|
|
|
|
}
|
|
|
|
|
$lc = new LocalisationCache_BulkLoad( $conf );
|
2009-07-31 09:57:59 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$codes = array_keys( Language::getLanguageNames( true ) );
|
|
|
|
|
sort( $codes );
|
2009-07-31 09:57:59 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
// Initialise and split into chunks
|
|
|
|
|
$numRebuilt = 0;
|
2010-05-22 16:50:39 +00:00
|
|
|
$total = count( $codes );
|
|
|
|
|
$chunks = array_chunk( $codes, ceil( count( $codes ) / $threads ) );
|
2009-08-02 19:35:17 +00:00
|
|
|
$pids = array();
|
|
|
|
|
foreach ( $chunks as $codes ) {
|
|
|
|
|
// Do not fork for only one thread
|
|
|
|
|
$pid = ( $threads > 1 ) ? pcntl_fork() : -1;
|
2009-07-31 09:57:59 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
if ( $pid === 0 ) {
|
2009-08-07 11:01:15 +00:00
|
|
|
// Child, reseed because there is no bug in PHP:
|
|
|
|
|
// http://bugs.php.net/bug.php?id=42465
|
2010-05-22 16:50:39 +00:00
|
|
|
mt_srand( getmypid() );
|
2009-08-13 16:42:44 +00:00
|
|
|
$numRebuilt = $this->doRebuild( $codes, $lc, $force );
|
|
|
|
|
// Abuse the exit value for the count of rebuild languages
|
2010-05-22 16:50:39 +00:00
|
|
|
exit( $numRebuilt );
|
|
|
|
|
} elseif ( $pid === -1 ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
// Fork failed or one thread, do it serialized
|
2009-08-13 16:42:44 +00:00
|
|
|
$numRebuilt += $this->doRebuild( $codes, $lc, $force );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
|
|
|
|
// Main thread
|
|
|
|
|
$pids[] = $pid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Wait for all children
|
2009-08-13 16:42:44 +00:00
|
|
|
foreach ( $pids as $pid ) {
|
|
|
|
|
$status = 0;
|
2010-05-22 16:50:39 +00:00
|
|
|
pcntl_waitpid( $pid, $status );
|
2009-08-13 16:42:44 +00:00
|
|
|
// Fetch the count from the return value
|
2010-05-22 16:50:39 +00:00
|
|
|
$numRebuilt += pcntl_wexitstatus( $status );
|
2009-08-13 16:42:44 +00:00
|
|
|
}
|
* Introduced a new system for localisation caching. The system is based around fast fetches of individual messages, minimising memory overhead and startup time in the typical case. It handles both core messages (formerly in Language.php) and extension messages (formerly in MessageCache.php). Profiling indicates a significant win for average throughput.
* The serialized message cache, which would have been redundant, has been removed. Similar performance characteristics can be achieved with $wgLocalisationCacheConf['manualRecache'] = true;
* Added a maintenance script rebuildLocalisationCache.php for offline rebuilding of the localisation cache.
* Extension i18n files can now contain any of the variables which can be set in Messages*.php. It is possible, and recommended, to use this feature instead of the hooks for special page aliases and magic words.
* $wgExtensionAliasesFiles, LanguageGetMagic and LanguageGetSpecialPageAliases are retained for backwards compatibility. $wgMessageCache->addMessages() and related functions have been removed. wfLoadExtensionMessages() is a no-op and can continue to be called for b/c.
* Introduced $wgCacheDirectory as a default location for the various local caches that have accumulated. Suggested $IP/cache as a good place for it in the default LocalSettings.php and created this directory with a deny-all .htaccess.
* Patched Exception.php to avoid using the message cache when an exception is thrown from within LocalisationCache, since this tends to fail horribly.
* Removed Language::getLocalisationArray(), Language::loadLocalisation(), Language::load()
* Fixed FileDependency::__sleep()
* In Cdb.php, fixed newlines in debug messages
In MessageCache::get():
* Replaced calls to $wgContLang capitalisation functions with plain PHP functions, reducing the typical case from 99us to 93us. Message cache keys are already documented as being restricted to ASCII.
* Implemented a more efficient way to filter out bogus language codes, reducing the "foo/en" case from 430us to 101us
* Optimised wfRunHooks() in the typical do-nothing case, from ~30us to ~3us. This reduced MessageCache::get() typical case time from 93us to 38us.
* Removed hook MessageNotInMwNs to save an extra 3us per cache hit. Reimplemented the only user (LocalisationUpdate) using the new hook LocalisationCacheRecache.
2009-06-28 07:11:43 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "$numRebuilt languages rebuilt out of $total\n" );
|
2009-08-13 16:42:44 +00:00
|
|
|
if ( $numRebuilt === 0 ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Use --force to rebuild the caches which are still fresh.\n" );
|
2009-07-31 09:57:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-02 19:56:24 +00:00
|
|
|
|
|
|
|
|
/**
|
2009-08-13 16:42:44 +00:00
|
|
|
* Helper function to rebuild list of languages codes. Prints the code
|
|
|
|
|
* for each language which is rebuilt.
|
|
|
|
|
* @param $codes list List of language codes to rebuild.
|
|
|
|
|
* @param $lc object Instance of LocalisationCache_BulkLoad (?)
|
|
|
|
|
* @param $force bool Rebuild up-to-date languages
|
|
|
|
|
* @return int Number of rebuilt languages
|
2009-08-02 19:56:24 +00:00
|
|
|
*/
|
2009-08-13 16:42:44 +00:00
|
|
|
private function doRebuild( $codes, $lc, $force ) {
|
|
|
|
|
$numRebuilt = 0;
|
2009-08-02 19:56:24 +00:00
|
|
|
foreach ( $codes as $code ) {
|
|
|
|
|
if ( $force || $lc->isExpired( $code ) ) {
|
|
|
|
|
$this->output( "Rebuilding $code...\n" );
|
|
|
|
|
$lc->recache( $code );
|
|
|
|
|
$numRebuilt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-13 16:42:44 +00:00
|
|
|
return $numRebuilt;
|
2009-08-02 19:56:24 +00:00
|
|
|
}
|
2009-07-31 09:57:59 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
|
|
|
|
|
$maintClass = "RebuildLocalisationCache";
|
2011-01-13 22:58:55 +00:00
|
|
|
require_once( RUN_MAINTENANCE_IF_MAIN );
|