2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Cache
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-08-22 17:24:50 +00:00
|
|
|
define( 'MSG_LOAD_TIMEOUT', 60);
|
|
|
|
|
define( 'MSG_LOCK_TIMEOUT', 10);
|
|
|
|
|
define( 'MSG_WAIT_TIMEOUT', 10);
|
2007-01-05 18:08:29 +00:00
|
|
|
define( 'MSG_CACHE_VERSION', 1 );
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Message cache
|
2007-01-05 18:08:29 +00:00
|
|
|
* Performs various MediaWiki namespace-related functions
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Cache
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2005-12-04 18:27:59 +00:00
|
|
|
class MessageCache {
|
2008-07-05 15:39:10 +00:00
|
|
|
// Holds loaded messages that are defined in MediaWiki namespace.
|
|
|
|
|
var $mCache;
|
|
|
|
|
|
|
|
|
|
var $mUseCache, $mDisable, $mExpiry;
|
|
|
|
|
var $mKeys, $mParserOptions, $mParser;
|
2004-09-25 02:23:04 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
// Variable for tracking which variables are loaded
|
|
|
|
|
var $mLoadedLanguages = array();
|
2004-09-25 02:23:04 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
function __construct( &$memCached, $useDB, $expiry, /*ignored*/ $memcPrefix ) {
|
2004-05-09 05:12:55 +00:00
|
|
|
$this->mUseCache = !is_null( $memCached );
|
|
|
|
|
$this->mMemc = &$memCached;
|
2003-12-14 14:32:19 +00:00
|
|
|
$this->mDisable = !$useDB;
|
|
|
|
|
$this->mExpiry = $expiry;
|
2004-05-03 10:21:26 +00:00
|
|
|
$this->mDisableTransform = false;
|
2003-12-14 14:32:19 +00:00
|
|
|
$this->mKeys = false; # initialised on demand
|
2006-07-03 11:17:27 +00:00
|
|
|
$this->mParser = null;
|
2008-06-30 03:02:06 +00:00
|
|
|
}
|
2008-06-03 20:41:57 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ParserOptions is lazy initialised.
|
|
|
|
|
*/
|
2006-07-26 07:15:39 +00:00
|
|
|
function getParserOptions() {
|
|
|
|
|
if ( !$this->mParserOptions ) {
|
|
|
|
|
$this->mParserOptions = new ParserOptions;
|
|
|
|
|
}
|
|
|
|
|
return $this->mParserOptions;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-07 13:09:30 +00:00
|
|
|
/**
|
2008-07-05 15:39:10 +00:00
|
|
|
* Try to load the cache from a local file.
|
|
|
|
|
* Actual format of the file depends on the $wgLocalMessageCacheSerialized
|
|
|
|
|
* setting.
|
|
|
|
|
*
|
|
|
|
|
* @param $hash String: the hash of contents, to check validity.
|
|
|
|
|
* @param $code Mixed: Optional language code, see documenation of load().
|
|
|
|
|
* @return false on failure.
|
2005-11-08 11:54:04 +00:00
|
|
|
*/
|
2008-07-05 15:39:10 +00:00
|
|
|
function loadFromLocal( $hash, $code ) {
|
* 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
|
|
|
global $wgCacheDirectory, $wgLocalMessageCacheSerialized;
|
2005-11-08 11:54:04 +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
|
|
|
$filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
# Check file existence
|
2005-12-30 08:50:59 +00:00
|
|
|
wfSuppressWarnings();
|
2005-11-08 11:54:04 +00:00
|
|
|
$file = fopen( $filename, 'r' );
|
2005-12-30 08:50:59 +00:00
|
|
|
wfRestoreWarnings();
|
2005-11-08 11:54:04 +00:00
|
|
|
if ( !$file ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
return false; // No cache file
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
2008-02-02 18:15:57 +00:00
|
|
|
if ( $wgLocalMessageCacheSerialized ) {
|
|
|
|
|
// Check to see if the file has the hash specified
|
|
|
|
|
$localHash = fread( $file, 32 );
|
|
|
|
|
if ( $hash === $localHash ) {
|
|
|
|
|
// All good, get the rest of it
|
2008-02-13 05:46:43 +00:00
|
|
|
$serialized = '';
|
|
|
|
|
while ( !feof( $file ) ) {
|
|
|
|
|
$serialized .= fread( $file, 100000 );
|
|
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
fclose( $file );
|
|
|
|
|
return $this->setCache( unserialize( $serialized ), $code );
|
|
|
|
|
} else {
|
|
|
|
|
fclose( $file );
|
|
|
|
|
return false; // Wrong hash
|
2008-02-02 18:15:57 +00:00
|
|
|
}
|
2008-02-10 14:29:17 +00:00
|
|
|
} else {
|
|
|
|
|
$localHash=substr(fread($file,40),8);
|
|
|
|
|
fclose($file);
|
|
|
|
|
if ($hash!=$localHash) {
|
2008-07-05 15:39:10 +00:00
|
|
|
return false; // Wrong hash
|
2008-02-10 14:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
# Require overwrites the member variable or just shadows it?
|
|
|
|
|
require( $filename );
|
|
|
|
|
return $this->setCache( $this->mCache, $code );
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-05 15:39:10 +00:00
|
|
|
* Save the cache to a local file.
|
2005-11-08 11:54:04 +00:00
|
|
|
*/
|
2008-07-05 15:39:10 +00:00
|
|
|
function saveToLocal( $serialized, $hash, $code ) {
|
* 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
|
|
|
global $wgCacheDirectory;
|
2008-05-23 22:14:32 +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
|
|
|
$filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
|
|
|
|
|
wfMkdirParents( $wgCacheDirectory ); // might fail
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
wfSuppressWarnings();
|
2005-11-08 11:54:04 +00:00
|
|
|
$file = fopen( $filename, 'w' );
|
2008-07-05 15:39:10 +00:00
|
|
|
wfRestoreWarnings();
|
|
|
|
|
|
2005-11-08 11:54:04 +00:00
|
|
|
if ( !$file ) {
|
|
|
|
|
wfDebug( "Unable to open local cache file for writing\n" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fwrite( $file, $hash . $serialized );
|
|
|
|
|
fclose( $file );
|
2006-01-04 23:24:25 +00:00
|
|
|
@chmod( $filename, 0666 );
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
function saveToScript( $array, $hash, $code ) {
|
* 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
|
|
|
global $wgCacheDirectory;
|
2008-07-05 15:39:10 +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
|
|
|
$filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
|
2008-07-05 15:39:10 +00:00
|
|
|
$tempFilename = $filename . '.tmp';
|
* 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
|
|
|
wfMkdirParents( $wgCacheDirectory ); // might fail
|
2008-07-05 15:39:10 +00:00
|
|
|
|
|
|
|
|
wfSuppressWarnings();
|
|
|
|
|
$file = fopen( $tempFilename, 'w');
|
|
|
|
|
wfRestoreWarnings();
|
|
|
|
|
|
|
|
|
|
if ( !$file ) {
|
|
|
|
|
wfDebug( "Unable to open local cache file for writing\n" );
|
2008-06-01 03:27:48 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2006-05-28 18:29:42 +00:00
|
|
|
|
|
|
|
|
fwrite($file,"<?php\n//$hash\n\n \$this->mCache = array(");
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-05-28 18:29:42 +00:00
|
|
|
foreach ($array as $key => $message) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$key = $this->escapeForScript($key);
|
|
|
|
|
$messages = $this->escapeForScript($message);
|
|
|
|
|
fwrite($file, "'$key' => '$message',\n");
|
2006-05-28 18:29:42 +00:00
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
|
2006-05-28 18:29:42 +00:00
|
|
|
fwrite($file,");\n?>");
|
|
|
|
|
fclose($file);
|
2008-07-05 15:39:10 +00:00
|
|
|
rename($tempFilename, $filename);
|
2006-05-28 18:29:42 +00:00
|
|
|
}
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2006-05-29 05:49:03 +00:00
|
|
|
function escapeForScript($string) {
|
|
|
|
|
$string = str_replace( '\\', '\\\\', $string );
|
|
|
|
|
$string = str_replace( '\'', '\\\'', $string );
|
|
|
|
|
return $string;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
/**
|
|
|
|
|
* Set the cache to $cache, if it is valid. Otherwise set the cache to false.
|
|
|
|
|
*/
|
2008-07-05 15:39:10 +00:00
|
|
|
function setCache( $cache, $code ) {
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( isset( $cache['VERSION'] ) && $cache['VERSION'] == MSG_CACHE_VERSION ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$this->mCache[$code] = $cache;
|
|
|
|
|
return true;
|
2007-01-05 18:08:29 +00:00
|
|
|
} else {
|
2008-07-05 15:39:10 +00:00
|
|
|
return false;
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2008-07-05 15:39:10 +00:00
|
|
|
* Loads messages from caches or from database in this order:
|
* 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
|
|
|
* (1) local message cache (if $wgUseLocalMessageCache is enabled)
|
2008-07-05 15:39:10 +00:00
|
|
|
* (2) memcached
|
|
|
|
|
* (3) from the database.
|
|
|
|
|
*
|
|
|
|
|
* When succesfully loading from (2) or (3), all higher level caches are
|
|
|
|
|
* updated for the newest version.
|
|
|
|
|
*
|
|
|
|
|
* Nothing is loaded if member variable mDisabled is true, either manually
|
|
|
|
|
* set by calling code or if message loading fails (is this possible?).
|
|
|
|
|
*
|
|
|
|
|
* Returns true if cache is already populated or it was succesfully populated,
|
|
|
|
|
* or false if populating empty cache fails. Also returns true if MessageCache
|
|
|
|
|
* is disabled.
|
|
|
|
|
*
|
|
|
|
|
* @param $code String: language to which load messages
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2008-07-05 15:39:10 +00:00
|
|
|
function load( $code = false ) {
|
* 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
|
|
|
global $wgUseLocalMessageCache;
|
2008-07-05 15:39:10 +00:00
|
|
|
|
|
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !is_string( $code ) ) {
|
|
|
|
|
# This isn't really nice, so at least make a note about it and try to
|
|
|
|
|
# fall back
|
|
|
|
|
wfDebug( __METHOD__ . " called without providing a language code\n" );
|
|
|
|
|
$code = 'en';
|
|
|
|
|
}
|
2008-06-03 20:41:57 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
# Don't do double loading...
|
|
|
|
|
if ( isset($this->mLoadedLanguages[$code]) ) return true;
|
|
|
|
|
|
|
|
|
|
# 8 lines of code just to say (once) that message cache is disabled
|
2003-12-14 14:32:19 +00:00
|
|
|
if ( $this->mDisable ) {
|
2005-05-28 11:07:55 +00:00
|
|
|
static $shownDisabled = false;
|
|
|
|
|
if ( !$shownDisabled ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
wfDebug( __METHOD__ . ": disabled\n" );
|
2005-05-28 11:07:55 +00:00
|
|
|
$shownDisabled = true;
|
|
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
# Loading code starts
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
$success = false; # Keep track of success
|
|
|
|
|
$where = array(); # Debug info, delayed to avoid spamming debug log too much
|
|
|
|
|
$cacheKey = wfMemcKey( 'messages', $code ); # Key in memc for messages
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
# (1) local cache
|
|
|
|
|
# Hash of the contents is stored in memcache, to detect if local cache goes
|
|
|
|
|
# out of date (due to update in other thread?)
|
* 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
|
|
|
if ( $wgUseLocalMessageCache ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-fromlocal' );
|
|
|
|
|
|
|
|
|
|
$hash = $this->mMemc->get( wfMemcKey( 'messages', $code, 'hash' ) );
|
2008-02-02 18:15:57 +00:00
|
|
|
if ( $hash ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$success = $this->loadFromLocal( $hash, $code );
|
|
|
|
|
if ( $success ) $where[] = 'got from local cache';
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-fromlocal' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# (2) memcache
|
|
|
|
|
# Fails if nothing in cache, or in the wrong version.
|
|
|
|
|
if ( !$success ) {
|
|
|
|
|
wfProfileIn( __METHOD__ . '-fromcache' );
|
|
|
|
|
$cache = $this->mMemc->get( $cacheKey );
|
|
|
|
|
$success = $this->setCache( $cache, $code );
|
|
|
|
|
if ( $success ) {
|
|
|
|
|
$where[] = 'got from global cache';
|
|
|
|
|
$this->saveToCaches( $cache, false, $code );
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-fromcache' );
|
2008-06-01 03:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
# (3)
|
|
|
|
|
# Nothing in caches... so we need create one and store it in caches
|
|
|
|
|
if ( !$success ) {
|
|
|
|
|
$where[] = 'cache is empty';
|
|
|
|
|
$where[] = 'loading from database';
|
2008-06-01 03:27:48 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
$this->lock($cacheKey);
|
2008-06-01 03:27:48 +00:00
|
|
|
|
2010-02-05 04:25:30 +00:00
|
|
|
# Limit the concurrency of loadFromDB to a single process
|
2008-10-10 13:02:57 +00:00
|
|
|
# This prevents the site from going down when the cache expires
|
|
|
|
|
$statusKey = wfMemcKey( 'messages', $code, 'status' );
|
|
|
|
|
$success = $this->mMemc->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT );
|
2008-07-05 15:39:10 +00:00
|
|
|
if ( $success ) {
|
2008-10-10 13:02:57 +00:00
|
|
|
$cache = $this->loadFromDB( $code );
|
|
|
|
|
$success = $this->setCache( $cache, $code );
|
|
|
|
|
}
|
|
|
|
|
if ( $success ) {
|
|
|
|
|
$success = $this->saveToCaches( $cache, true, $code );
|
|
|
|
|
if ( $success ) {
|
|
|
|
|
$this->mMemc->delete( $statusKey );
|
|
|
|
|
} else {
|
|
|
|
|
$this->mMemc->set( $statusKey, 'error', 60*5 );
|
|
|
|
|
wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
|
|
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
$this->unlock($cacheKey);
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
if ( !$success ) {
|
|
|
|
|
# Bad luck... this should not happen
|
|
|
|
|
$where[] = 'loading FAILED - cache is disabled';
|
|
|
|
|
$info = implode( ', ', $where );
|
|
|
|
|
wfDebug( __METHOD__ . ": Loading $code... $info\n" );
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mDisable = true;
|
|
|
|
|
$this->mCache = false;
|
2008-07-05 15:39:10 +00:00
|
|
|
} else {
|
|
|
|
|
# All good, just record the success
|
|
|
|
|
$info = implode( ', ', $where );
|
|
|
|
|
wfDebug( __METHOD__ . ": Loading $code... $info\n" );
|
|
|
|
|
$this->mLoadedLanguages[$code] = true;
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2003-12-14 14:32:19 +00:00
|
|
|
return $success;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2008-07-05 15:39:10 +00:00
|
|
|
* Loads cacheable messages from the database. Messages bigger than
|
|
|
|
|
* $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded
|
|
|
|
|
* on-demand from the database later.
|
|
|
|
|
*
|
|
|
|
|
* @param $code Optional language code, see documenation of load().
|
|
|
|
|
* @return Array: Loaded messages for storing in caches.
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2008-07-05 15:39:10 +00:00
|
|
|
function loadFromDB( $code = false ) {
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2008-07-05 15:39:10 +00:00
|
|
|
global $wgMaxMsgCacheEntrySize, $wgContLanguageCode;
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2008-07-05 15:39:10 +00:00
|
|
|
$cache = array();
|
|
|
|
|
|
|
|
|
|
# Common conditions
|
|
|
|
|
$conds = array(
|
|
|
|
|
'page_is_redirect' => 0,
|
|
|
|
|
'page_namespace' => NS_MEDIAWIKI,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( $code ) {
|
|
|
|
|
# Is this fast enough. Should not matter if the filtering is done in the
|
|
|
|
|
# database or in code.
|
|
|
|
|
if ( $code !== $wgContLanguageCode ) {
|
|
|
|
|
# Messages for particular language
|
2009-10-21 19:53:03 +00:00
|
|
|
$conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), "/$code" );
|
2008-07-05 15:39:10 +00:00
|
|
|
} else {
|
|
|
|
|
# Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
|
|
|
|
|
# other than language code.
|
2009-10-21 19:53:03 +00:00
|
|
|
$conds[] = 'page_title NOT' . $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
|
2008-07-05 15:39:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Conditions to fetch oversized pages to ignore them
|
|
|
|
|
$bigConds = $conds;
|
|
|
|
|
$bigConds[] = 'page_len > ' . intval( $wgMaxMsgCacheEntrySize );
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Load titles for all oversized pages in the MediaWiki namespace
|
2008-07-05 15:39:10 +00:00
|
|
|
$res = $dbr->select( 'page', 'page_title', $bigConds, __METHOD__ );
|
2007-01-05 18:08:29 +00:00
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$cache[$row->page_title] = '!TOO BIG';
|
2005-03-19 10:40:41 +00:00
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
$dbr->freeResult( $res );
|
2006-06-25 08:38:17 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
# Conditions to load the remaining pages with their contents
|
|
|
|
|
$smallConds = $conds;
|
|
|
|
|
$smallConds[] = 'page_latest=rev_id';
|
|
|
|
|
$smallConds[] = 'rev_text_id=old_id';
|
|
|
|
|
$smallConds[] = 'page_len <= ' . intval( $wgMaxMsgCacheEntrySize );
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
$res = $dbr->select( array( 'page', 'revision', 'text' ),
|
|
|
|
|
array( 'page_title', 'old_text', 'old_flags' ),
|
2009-07-31 07:12:25 +00:00
|
|
|
$smallConds, __METHOD__. "($code)" );
|
2006-06-25 08:38:17 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$cache[$row->page_title] = ' ' . Revision::getRevisionText( $row );
|
2006-01-07 13:31:29 +00:00
|
|
|
}
|
2005-09-11 14:50:47 +00:00
|
|
|
$dbr->freeResult( $res );
|
2008-07-05 15:39:10 +00:00
|
|
|
|
|
|
|
|
$cache['VERSION'] = MSG_CACHE_VERSION;
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2008-07-05 15:39:10 +00:00
|
|
|
return $cache;
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
/**
|
|
|
|
|
* Updates cache as necessary when message page is changed
|
|
|
|
|
*
|
|
|
|
|
* @param $title String: name of the page changed.
|
|
|
|
|
* @param $text Mixed: new contents of the page.
|
|
|
|
|
*/
|
|
|
|
|
public function replace( $title, $text ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
global $wgMaxMsgCacheEntrySize;
|
2008-06-30 03:02:06 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2008-07-05 15:39:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
list( , $code ) = $this->figureMessage( $title );
|
|
|
|
|
|
|
|
|
|
$cacheKey = wfMemcKey( 'messages', $code );
|
|
|
|
|
$this->load($code);
|
|
|
|
|
$this->lock($cacheKey);
|
|
|
|
|
|
|
|
|
|
if ( is_array($this->mCache[$code]) ) {
|
|
|
|
|
$titleKey = wfMemcKey( 'messages', 'individual', $title );
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( $text === false ) {
|
|
|
|
|
# Article was deleted
|
2008-07-05 15:39:10 +00:00
|
|
|
unset( $this->mCache[$code][$title] );
|
|
|
|
|
$this->mMemc->delete( $titleKey );
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
} elseif ( strlen( $text ) > $wgMaxMsgCacheEntrySize ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
# Check for size
|
|
|
|
|
$this->mCache[$code][$title] = '!TOO BIG';
|
|
|
|
|
$this->mMemc->set( $titleKey, ' ' . $text, $this->mExpiry );
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
} else {
|
2008-07-05 15:39:10 +00:00
|
|
|
$this->mCache[$code][$title] = ' ' . $text;
|
|
|
|
|
$this->mMemc->delete( $titleKey );
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
|
|
|
|
|
# Update caches
|
|
|
|
|
$this->saveToCaches( $this->mCache[$code], true, $code );
|
|
|
|
|
}
|
|
|
|
|
$this->unlock($cacheKey);
|
|
|
|
|
|
|
|
|
|
// Also delete cached sidebar... just in case it is affected
|
|
|
|
|
global $parserMemc;
|
2010-02-01 04:57:42 +00:00
|
|
|
$codes = array( $code );
|
|
|
|
|
if ( $code === 'en' ) {
|
|
|
|
|
// Delete all sidebars, like for example on action=purge on the
|
|
|
|
|
// sidebar messages
|
|
|
|
|
$codes = array_keys( Language::getLanguageNames() );
|
|
|
|
|
}
|
2009-07-31 07:12:25 +00:00
|
|
|
|
2010-02-01 04:57:42 +00:00
|
|
|
foreach ( $codes as $code ) {
|
|
|
|
|
$sidebarKey = wfMemcKey( 'sidebar', $code );
|
|
|
|
|
$parserMemc->delete( $sidebarKey );
|
2009-07-31 07:12:25 +00:00
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
|
2009-04-08 14:23:14 +00:00
|
|
|
wfRunHooks( "MessageCacheReplace", array( $title, $text ) );
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shortcut to update caches.
|
|
|
|
|
*
|
|
|
|
|
* @param $cache Array: cached messages with a version.
|
|
|
|
|
* @param $memc Bool: Wether to update or not memcache.
|
|
|
|
|
* @param $code String: Language code.
|
|
|
|
|
* @return False on somekind of error.
|
|
|
|
|
*/
|
|
|
|
|
protected function saveToCaches( $cache, $memc = true, $code = false ) {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
* 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
|
|
|
global $wgUseLocalMessageCache, $wgLocalMessageCacheSerialized;
|
2008-07-05 15:39:10 +00:00
|
|
|
|
|
|
|
|
$cacheKey = wfMemcKey( 'messages', $code );
|
|
|
|
|
|
|
|
|
|
if ( $memc ) {
|
* Converted BagOStuff.php from the style of memcached-client.php to the standard MediaWiki style, including camel case, using protected visibility instead of initial underscore, abstract functions instead of stubs, stylize.php.
* In SqlBagOStuff, ignore errors due to a read-only database, per my comments on CR r42796. Same for LocalisationCache.
* Merged SqlBagOStuff and MediaWikiBagOStuff, that proved to be an awkward and unnecessary generalisation. Use the standard quoting wrapper functions instead of $db->query().
* Implemented atomic incr() and decr() functions for SqlBagOStuff.
* Made incr() and decr() generally work roughly the same as it does in memcached, respecting negative steps instead of ignoring such operations. This allows decr() to be implemented in terms of incr().
* Per bug 11533, in MessageCache.php, don't retry 20 times on a cache failure, that's really memcached-specific and won't be useful for other cache types. It's not really very useful for memcached either.
* Moved MySQL-specific implementations of wasDeadlock() and wasErrorReissuable() to DatabaseMysql.
* Briefly tested page views with $wgReadOnly=read_only=1, fixed an error from Article::viewUpdates(). A CentralAuth fix will be in a subsequent commit.
2009-08-15 03:45:19 +00:00
|
|
|
$success = $this->mMemc->set( $cacheKey, $cache, $this->mExpiry );
|
|
|
|
|
} else {
|
|
|
|
|
$success = true;
|
2008-06-03 20:41:57 +00:00
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
|
|
|
|
|
# Save to local cache
|
* 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
|
|
|
if ( $wgUseLocalMessageCache ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$serialized = serialize( $cache );
|
|
|
|
|
$hash = md5( $serialized );
|
|
|
|
|
$this->mMemc->set( wfMemcKey( 'messages', $code, 'hash' ), $hash, $this->mExpiry );
|
|
|
|
|
if ($wgLocalMessageCacheSerialized) {
|
|
|
|
|
$this->saveToLocal( $serialized, $hash, $code );
|
|
|
|
|
} else {
|
|
|
|
|
$this->saveToScript( $cache, $hash, $code );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2008-07-05 15:39:10 +00:00
|
|
|
return $success;
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Represents a write lock on the messages key
|
2010-04-09 21:27:23 +00:00
|
|
|
*
|
|
|
|
|
* @return Boolean: success
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2008-07-05 15:39:10 +00:00
|
|
|
function lock($key) {
|
2003-12-14 14:32:19 +00:00
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
$lockKey = $key . ':lock';
|
2004-05-09 05:12:55 +00:00
|
|
|
for ($i=0; $i < MSG_WAIT_TIMEOUT && !$this->mMemc->add( $lockKey, 1, MSG_LOCK_TIMEOUT ); $i++ ) {
|
2003-12-14 14:32:19 +00:00
|
|
|
sleep(1);
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
return $i >= MSG_WAIT_TIMEOUT;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
function unlock($key) {
|
2003-12-14 14:32:19 +00:00
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
$lockKey = $key . ':lock';
|
2004-05-09 05:12:55 +00:00
|
|
|
$this->mMemc->delete( $lockKey );
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get a message from either the content language or the user language.
|
|
|
|
|
*
|
2010-04-09 21:27:23 +00:00
|
|
|
* @param $key String: the message cache key
|
|
|
|
|
* @param $useDB Boolean: get the message from the DB, false to use only
|
|
|
|
|
* the localisation
|
|
|
|
|
* @param $langcode String: code of the language to get the message for, if
|
|
|
|
|
* it is a valid code create a language for that language,
|
|
|
|
|
* if it is a string but not a valid code then make a basic
|
|
|
|
|
* language object, if it is a false boolean then use the
|
|
|
|
|
* current users language (as a fallback for the old
|
|
|
|
|
* parameter functionality), or if it is a true boolean
|
|
|
|
|
* then use the wikis content language (also as a
|
|
|
|
|
* fallback).
|
|
|
|
|
* @param $isFullKey Boolean: specifies whether $key is a two part key
|
|
|
|
|
* "msg/lang".
|
2007-01-05 18:08:29 +00:00
|
|
|
*/
|
2008-04-27 14:50:55 +00:00
|
|
|
function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) {
|
2008-07-26 20:41:52 +00:00
|
|
|
global $wgContLanguageCode, $wgContLang;
|
2008-04-24 11:59:32 +00:00
|
|
|
|
2009-07-10 11:54:32 +00:00
|
|
|
if ( strval( $key ) === '' ) {
|
|
|
|
|
# Shortcut: the empty key is always missing
|
2010-03-25 20:21:31 +00:00
|
|
|
return false;
|
2009-07-03 06:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-26 20:41:52 +00:00
|
|
|
$lang = wfGetLangObj( $langcode );
|
2006-07-26 08:26:51 +00:00
|
|
|
$langcode = $lang->getCode();
|
2008-04-24 11:59:32 +00:00
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
$message = false;
|
2007-01-05 18:08:29 +00:00
|
|
|
|
Reverted breakage of non-ASCII message keys, Domas says that's not allowed. Optimised Language::lcfirst and Language::ucfirst() instead.
Timings in microseconds for ASCII no-change, ASCII change, non-ASCII no-change, non-ASCII change:
lcfirst: 1.8, 3.6, 21.2, 22.1
ucfirst: 1.5, 2.3, 21.1, 21.7
2009-08-28 17:58:54 +00:00
|
|
|
# Normalise title-case input (with some inlining)
|
* 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
|
|
|
$lckey = str_replace( ' ', '_', $key );
|
Reverted breakage of non-ASCII message keys, Domas says that's not allowed. Optimised Language::lcfirst and Language::ucfirst() instead.
Timings in microseconds for ASCII no-change, ASCII change, non-ASCII no-change, non-ASCII change:
lcfirst: 1.8, 3.6, 21.2, 22.1
ucfirst: 1.5, 2.3, 21.1, 21.7
2009-08-28 17:58:54 +00:00
|
|
|
if ( ord( $key ) < 128 ) {
|
|
|
|
|
$lckey[0] = strtolower( $lckey[0] );
|
|
|
|
|
$uckey = ucfirst( $lckey );
|
|
|
|
|
} else {
|
|
|
|
|
$lckey = $wgContLang->lcfirst( $lckey );
|
|
|
|
|
$uckey = $wgContLang->ucfirst( $lckey );
|
|
|
|
|
}
|
2007-01-07 14:22:32 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Try the MediaWiki namespace
|
2004-11-21 13:56:04 +00:00
|
|
|
if( !$this->mDisable && $useDB ) {
|
* 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
|
|
|
$title = $uckey;
|
2009-05-16 20:12:29 +00:00
|
|
|
if(!$isFullKey && ( $langcode != $wgContLanguageCode ) ) {
|
2004-11-21 13:56:04 +00:00
|
|
|
$title .= '/' . $langcode;
|
|
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
$message = $this->getMsgFromNamespace( $title, $langcode );
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2004-09-24 00:09:42 +00:00
|
|
|
# Try the array in the language object
|
2008-07-05 15:39:10 +00:00
|
|
|
if ( $message === false ) {
|
2007-01-07 15:43:23 +00:00
|
|
|
$message = $lang->getMessage( $lckey );
|
2005-10-22 20:52:30 +00:00
|
|
|
if ( is_null( $message ) ) {
|
|
|
|
|
$message = false;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2006-08-07 12:21:06 +00:00
|
|
|
# Try the array of another language
|
* 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
|
|
|
if( $message === false ) {
|
|
|
|
|
$parts = explode( '/', $lckey );
|
|
|
|
|
# We may get calls for things that are http-urls from sidebar
|
|
|
|
|
# Let's not load nonexistent languages for those
|
|
|
|
|
# They usually have more than one slash.
|
|
|
|
|
if ( count( $parts ) == 2 && $parts[1] !== '' ) {
|
|
|
|
|
$message = Language::getMessageFor( $parts[0], $parts[1] );
|
|
|
|
|
if ( is_null( $message ) ) {
|
|
|
|
|
$message = false;
|
2006-08-10 09:10:06 +00:00
|
|
|
}
|
2006-08-07 12:21:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-13 11:50:54 +00:00
|
|
|
# Is this a custom message? Try the default language in the db...
|
2006-05-31 08:05:38 +00:00
|
|
|
if( ($message === false || $message === '-' ) &&
|
2005-03-13 11:50:54 +00:00
|
|
|
!$this->mDisable && $useDB &&
|
2007-01-05 18:08:29 +00:00
|
|
|
!$isFullKey && ($langcode != $wgContLanguageCode) ) {
|
* 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
|
|
|
$message = $this->getMsgFromNamespace( $uckey, $wgContLanguageCode );
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
2005-07-07 03:08:58 +00:00
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
# Final fallback
|
2005-09-11 14:50:47 +00:00
|
|
|
if( $message === false ) {
|
2010-03-25 20:21:31 +00:00
|
|
|
return false;
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2009-06-04 07:26:46 +00:00
|
|
|
|
|
|
|
|
# Fix whitespace
|
2010-02-05 04:25:30 +00:00
|
|
|
$message = strtr( $message,
|
2009-06-04 07:26:46 +00:00
|
|
|
array(
|
|
|
|
|
# Fix for trailing whitespace, removed by textarea
|
|
|
|
|
' ' => ' ',
|
|
|
|
|
# Fix for NBSP, converted to space by firefox
|
|
|
|
|
' ' => "\xc2\xa0",
|
|
|
|
|
) );
|
|
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
return $message;
|
|
|
|
|
}
|
2005-07-07 03:08:58 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Get a message from the MediaWiki namespace, with caching. The key must
|
2007-01-05 18:08:29 +00:00
|
|
|
* first be converted to two-part lang/msg form if necessary.
|
|
|
|
|
*
|
2008-07-05 15:39:10 +00:00
|
|
|
* @param $title String: Message cache key with initial uppercase letter.
|
|
|
|
|
* @param $code String: code denoting the language to try.
|
2007-01-05 18:08:29 +00:00
|
|
|
*/
|
2008-07-05 15:39:10 +00:00
|
|
|
function getMsgFromNamespace( $title, $code ) {
|
2008-06-30 03:02:06 +00:00
|
|
|
$type = false;
|
2008-07-05 15:39:10 +00:00
|
|
|
$message = false;
|
2005-07-07 03:08:58 +00:00
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
if ( $this->mUseCache ) {
|
|
|
|
|
$this->load( $code );
|
|
|
|
|
if (isset( $this->mCache[$code][$title] ) ) {
|
|
|
|
|
$entry = $this->mCache[$code][$title];
|
|
|
|
|
$type = substr( $entry, 0, 1 );
|
|
|
|
|
if ( $type == ' ' ) {
|
|
|
|
|
return substr( $entry, 1 );
|
|
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Call message hooks, in case they are defined
|
|
|
|
|
wfRunHooks('MessagesPreLoad', array( $title, &$message ) );
|
|
|
|
|
if ( $message !== false ) {
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If there is no cache entry and no placeholder, it doesn't exist
|
2008-07-05 15:39:10 +00:00
|
|
|
if ( $type !== '!' ) {
|
2007-01-05 18:08:29 +00:00
|
|
|
return false;
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
$titleKey = wfMemcKey( 'messages', 'individual', $title );
|
2007-01-05 18:08:29 +00:00
|
|
|
|
|
|
|
|
# Try the individual message cache
|
2005-09-11 14:50:47 +00:00
|
|
|
if ( $this->mUseCache ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$entry = $this->mMemc->get( $titleKey );
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( $entry ) {
|
|
|
|
|
$type = substr( $entry, 0, 1 );
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
if ( $type === ' ' ) {
|
|
|
|
|
# Ok!
|
2007-04-27 16:39:21 +00:00
|
|
|
$message = substr( $entry, 1 );
|
2008-07-05 15:39:10 +00:00
|
|
|
$this->mCache[$code][$title] = $entry;
|
2007-01-05 18:08:29 +00:00
|
|
|
return $message;
|
2008-07-05 15:39:10 +00:00
|
|
|
} elseif ( $entry === '!NONEXISTENT' ) {
|
2007-01-05 18:08:29 +00:00
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
# Corrupt/obsolete entry, delete it
|
2008-07-05 15:39:10 +00:00
|
|
|
$this->mMemc->delete( $titleKey );
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Try loading it from the DB
|
2005-09-11 14:50:47 +00:00
|
|
|
$revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $title ) );
|
|
|
|
|
if( $revision ) {
|
|
|
|
|
$message = $revision->getText();
|
|
|
|
|
if ($this->mUseCache) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$this->mCache[$code][$title] = ' ' . $message;
|
2010-02-11 14:17:22 +00:00
|
|
|
$this->mMemc->set( $titleKey, ' ' . $message, $this->mExpiry );
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
2005-09-11 14:50:47 +00:00
|
|
|
} else {
|
|
|
|
|
# Negative caching
|
2005-09-11 17:33:25 +00:00
|
|
|
# Use some special text instead of false, because false gets converted to '' somewhere
|
2008-07-05 15:39:10 +00:00
|
|
|
$this->mMemc->set( $titleKey, '!NONEXISTENT', $this->mExpiry );
|
|
|
|
|
$this->mCache[$code][$title] = false;
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
2004-03-01 05:51:55 +00:00
|
|
|
|
2008-11-13 01:02:17 +00:00
|
|
|
function transform( $message, $interface = false, $language = null ) {
|
* 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
|
|
|
// Avoid creating parser if nothing to transform
|
2008-07-05 15:39:10 +00:00
|
|
|
if( strpos( $message, '{{' ) === false ) {
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-26 14:37:15 +00:00
|
|
|
global $wgParser, $wgParserConf;
|
2006-07-03 11:17:27 +00:00
|
|
|
if ( !$this->mParser && isset( $wgParser ) ) {
|
2006-07-04 09:13:10 +00:00
|
|
|
# Do some initialisation so that we don't have to do it twice
|
|
|
|
|
$wgParser->firstCallInit();
|
|
|
|
|
# Clone it and store it
|
2008-08-26 14:37:15 +00:00
|
|
|
$class = $wgParserConf['class'];
|
|
|
|
|
if ( $class == 'Parser_DiffTest' ) {
|
|
|
|
|
# Uncloneable
|
|
|
|
|
$this->mParser = new $class( $wgParserConf );
|
|
|
|
|
} else {
|
|
|
|
|
$this->mParser = clone $wgParser;
|
|
|
|
|
}
|
2008-07-05 15:39:10 +00:00
|
|
|
#wfDebug( __METHOD__ . ": following contents triggered transform: $message\n" );
|
2006-07-03 11:17:27 +00:00
|
|
|
}
|
2008-01-19 09:03:45 +00:00
|
|
|
if ( $this->mParser ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$popts = $this->getParserOptions();
|
|
|
|
|
$popts->setInterfaceMessage( $interface );
|
2008-11-13 01:02:17 +00:00
|
|
|
$popts->setTargetLanguage( $language );
|
2008-07-05 15:39:10 +00:00
|
|
|
$message = $this->mParser->transformMsg( $message, $popts );
|
2004-04-05 10:38:40 +00:00
|
|
|
}
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2004-03-01 05:51:55 +00:00
|
|
|
function disable() { $this->mDisable = true; }
|
|
|
|
|
function enable() { $this->mDisable = false; }
|
2010-02-05 04:25:30 +00:00
|
|
|
|
2008-01-19 09:03:45 +00:00
|
|
|
/** @deprecated */
|
2008-04-02 11:49:55 +00:00
|
|
|
function disableTransform(){
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
function enableTransform() {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
function setTransform( $x ) {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
function getTransform() {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-03-01 05:51:55 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Clear all stored messages. Mainly used after a mass rebuild.
|
|
|
|
|
*/
|
2004-08-11 02:31:47 +00:00
|
|
|
function clear() {
|
|
|
|
|
if( $this->mUseCache ) {
|
2008-07-05 15:39:10 +00:00
|
|
|
$langs = Language::getLanguageNames( false );
|
|
|
|
|
foreach ( array_keys($langs) as $code ) {
|
|
|
|
|
# Global cache
|
|
|
|
|
$this->mMemc->delete( wfMemcKey( 'messages', $code ) );
|
|
|
|
|
# Invalidate all local caches
|
|
|
|
|
$this->mMemc->delete( wfMemcKey( 'messages', $code, 'hash' ) );
|
|
|
|
|
}
|
2004-08-11 02:31:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-08-24 16:58:44 +00:00
|
|
|
|
2009-07-03 06:19:39 +00:00
|
|
|
/**
|
|
|
|
|
* Add a message to the cache
|
|
|
|
|
* @deprecated Use $wgExtensionMessagesFiles
|
|
|
|
|
*
|
2010-04-09 21:27:23 +00:00
|
|
|
* @param $key Mixed
|
|
|
|
|
* @param $value Mixed
|
|
|
|
|
* @param $lang String: the messages language, English by default
|
2009-07-03 06:19:39 +00:00
|
|
|
*/
|
|
|
|
|
function addMessage( $key, $value, $lang = 'en' ) {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
$lc = Language::getLocalisationCache();
|
|
|
|
|
$lc->addLegacyMessages( array( $lang => array( $key => $value ) ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add an associative array of message to the cache
|
|
|
|
|
* @deprecated Use $wgExtensionMessagesFiles
|
|
|
|
|
*
|
2010-04-09 21:27:23 +00:00
|
|
|
* @param $messages Array: an associative array of key => values to be added
|
|
|
|
|
* @param $lang String: the messages language, English by default
|
2009-07-03 06:19:39 +00:00
|
|
|
*/
|
|
|
|
|
function addMessages( $messages, $lang = 'en' ) {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
$lc = Language::getLocalisationCache();
|
|
|
|
|
$lc->addLegacyMessages( array( $lang => $messages ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a 2-D array of messages by lang. Useful for extensions.
|
|
|
|
|
* @deprecated Use $wgExtensionMessagesFiles
|
|
|
|
|
*
|
2010-04-09 21:27:23 +00:00
|
|
|
* @param $messages Array: the array to be added
|
2009-07-03 06:19:39 +00:00
|
|
|
*/
|
|
|
|
|
function addMessagesByLang( $messages ) {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
$lc = Language::getLocalisationCache();
|
|
|
|
|
$lc->addLegacyMessages( $messages );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a hook for addMessagesByLang()
|
|
|
|
|
*/
|
|
|
|
|
function setExtensionMessagesHook( $callback ) {
|
|
|
|
|
$this->mAddMessagesHook = $callback;
|
|
|
|
|
}
|
|
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +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
|
|
|
* @deprecated
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +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
|
|
|
function loadAllMessages( $lang = false ) {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
}
|
2008-04-24 11:59:32 +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
|
|
|
* @deprecated
|
2008-04-24 11:59:32 +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
|
|
|
function loadMessagesFile( $filename, $langcode = false ) {
|
2008-04-24 11:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-05 15:39:10 +00:00
|
|
|
public function figureMessage( $key ) {
|
|
|
|
|
global $wgContLanguageCode;
|
2008-10-07 18:10:08 +00:00
|
|
|
$pieces = explode( '/', $key );
|
|
|
|
|
if( count( $pieces ) < 2 )
|
|
|
|
|
return array( $key, $wgContLanguageCode );
|
2008-07-05 15:39:10 +00:00
|
|
|
|
2008-10-07 18:10:08 +00:00
|
|
|
$lang = array_pop( $pieces );
|
|
|
|
|
$validCodes = Language::getLanguageNames();
|
|
|
|
|
if( !array_key_exists( $lang, $validCodes ) )
|
|
|
|
|
return array( $key, $wgContLanguageCode );
|
2008-07-05 15:39:10 +00:00
|
|
|
|
2008-10-07 18:10:08 +00:00
|
|
|
$message = implode( '/', $pieces );
|
|
|
|
|
return array( $message, $lang );
|
2008-07-05 15:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|