MediaWiki
REL1_19
|
Class for caching the contents of localisation files, Messages*.php and *.i18n.php. More...
Public Member Functions | |
__construct ($conf) | |
Constructor. | |
disableBackend () | |
Disable the storage backend. | |
getItem ($code, $key) | |
Get a cache item. | |
getSubitem ($code, $key, $subkey) | |
Get a subitem, for instance a single message for a given language. | |
getSubitemList ($code, $key) | |
Get the list of subitem keys for a given item. | |
initShallowFallback ($primaryCode, $fallbackCode) | |
Create a fallback from one language to another, without creating a complete persistent cache. | |
isExpired ($code) | |
Returns true if the cache identified by $code is missing or expired. | |
isMergeableKey ($key) | |
Returns true if the given key is mergeable, that is, if it is an associative array which can be merged through a fallback sequence. | |
recache ($code) | |
Load localisation data for a given language for both core and extensions and save it to the persistent cache store and the process cache. | |
unload ($code) | |
Unload the data for a given language from the object cache. | |
unloadAll () | |
Unload all data. | |
Public Attributes | |
$conf | |
Configuration associative array. | |
$data = array() | |
The cache data. | |
$forceRecache = false | |
True to treat all files as expired until they are regenerated by this object. | |
$initialisedLangs = array() | |
An array where presence of a key indicates that that language has been initialised. | |
$loadedItems = array() | |
A 2-d associative array, code/key, where presence indicates that the item is loaded. | |
$loadedSubitems = array() | |
A 3-d associative array, code/key/subkey, where presence indicates that the subitem is loaded. | |
$manualRecache = false | |
True if recaching should only be done on an explicit call to recache(). | |
$mergeableKeys = null | |
$recachedLangs = array() | |
An array where the keys are codes that have been recached by this instance. | |
$shallowFallbacks = array() | |
An array mapping non-existent pseudo-languages to fallback languages. | |
$store | |
Static Public Attributes | |
static | $allKeys |
All item keys. | |
static | $magicWordKeys = array( 'magicWords' ) |
Keys for items that are formatted like $magicWords. | |
static | $mergeableAliasListKeys = array( 'specialPageAliases' ) |
Keys for items which contain an array of arrays of equivalent aliases for each subitem. | |
static | $mergeableListKeys = array( 'extraUserToggles' ) |
Keys for items which are a numbered array. | |
static | $mergeableMapKeys |
Keys for items which consist of associative arrays, which may be merged by a fallback sequence. | |
static | $optionalMergeKeys = array( 'bookstoreList' ) |
Keys for items which contain an associative array, and may be merged if the primary value contains the special array key "inherit". | |
static | $preloadedKeys = array( 'dateFormats', 'namespaceNames' ) |
Keys which are loaded automatically by initLanguage() | |
static | $splitKeys = array( 'messages' ) |
Keys for items where the subitems are stored in the backend separately. | |
Protected Member Functions | |
buildPreload ($data) | |
Build the preload item from the given pre-cache data. | |
initLanguage ($code) | |
Initialise a language in this object. | |
loadItem ($code, $key) | |
Load an item into the cache. | |
loadSubitem ($code, $key, $subkey) | |
Load a subitem into the cache. | |
mergeExtensionItem ($codeSequence, $key, &$value, $fallbackValue) | |
Given an array mapping language code to localisation value, such as is found in extension *.i18n.php files, iterate through a fallback sequence to merge the given data with an existing primary value. | |
mergeItem ($key, &$value, $fallbackValue) | |
Merge two localisation values, a primary and a fallback, overwriting the primary value in place. | |
mergeMagicWords (&$value, $fallbackValue) | |
readPHPFile ($_fileName, $_fileType) | |
Read a PHP file containing localisation data. |
Class for caching the contents of localisation files, Messages*.php and *.i18n.php.
An instance of this class is available using Language::getLocalisationCache().
The values retrieved from here are merged, containing items from extension files, core messages files and the language fallback sequence (e.g. zh-cn -> zh-hans -> en ). Some common errors are corrected, for example namespace names with spaces instead of underscores, but heavyweight processing, such as grammatical transformation, is done by the caller.
Definition at line 17 of file LocalisationCache.php.
LocalisationCache::__construct | ( | $ | conf | ) |
Constructor.
For constructor parameters, see the documentation in DefaultSettings.php for $wgLocalisationCacheConf.
$conf | Array |
Definition at line 146 of file LocalisationCache.php.
References $conf, $wgCacheDirectory, and wfDebug().
LocalisationCache::buildPreload | ( | $ | data | ) | [protected] |
Build the preload item from the given pre-cache data.
The preload item will be loaded automatically, improving performance for the commonly-requested items it contains.
$data |
Definition at line 722 of file LocalisationCache.php.
References $data.
Referenced by recache().
Disable the storage backend.
Definition at line 770 of file LocalisationCache.php.
LocalisationCache::getItem | ( | $ | code, |
$ | key | ||
) |
Get a cache item.
Warning: this may be slow for split items (messages), since it will need to fetch all of the subitems from the cache individually.
$code | |
$key |
Reimplemented in LocalisationCache_BulkLoad.
Definition at line 215 of file LocalisationCache.php.
References loadItem(), wfProfileIn(), and wfProfileOut().
Referenced by getSubitemList(), and initLanguage().
LocalisationCache::getSubitem | ( | $ | code, |
$ | key, | ||
$ | subkey | ||
) |
Get a subitem, for instance a single message for a given language.
$code | |
$key | |
$subkey |
Reimplemented in LocalisationCache_BulkLoad.
Definition at line 236 of file LocalisationCache.php.
References loadSubitem(), wfProfileIn(), and wfProfileOut().
Referenced by getSubitemList(), and loadItem().
LocalisationCache::getSubitemList | ( | $ | code, |
$ | key | ||
) |
Get the list of subitem keys for a given item.
This is faster than array_keys($lc->getItem(...)) for the items listed in self::$splitKeys.
Will return null if the item is not found, or false if the item is not an array.
$code | |
$key |
Definition at line 263 of file LocalisationCache.php.
References getItem(), and getSubitem().
LocalisationCache::initLanguage | ( | $ | code | ) | [protected] |
Initialise a language in this object.
Rebuild the cache if necessary.
$code |
Definition at line 381 of file LocalisationCache.php.
References getItem(), Language\getMessagesFileName(), initShallowFallback(), isExpired(), Language\isValidBuiltInCode(), and recache().
Referenced by loadItem(), and loadSubitem().
LocalisationCache::initShallowFallback | ( | $ | primaryCode, |
$ | fallbackCode | ||
) |
Create a fallback from one language to another, without creating a complete persistent cache.
$primaryCode | |
$fallbackCode |
Definition at line 439 of file LocalisationCache.php.
Referenced by initLanguage().
LocalisationCache::isExpired | ( | $ | code | ) |
Returns true if the cache identified by $code is missing or expired.
Definition at line 347 of file LocalisationCache.php.
References $keys, CacheDependency\isExpired(), and wfDebug().
Referenced by initLanguage().
LocalisationCache::isMergeableKey | ( | $ | key | ) |
Returns true if the given key is mergeable, that is, if it is an associative array which can be merged through a fallback sequence.
$key |
Definition at line 193 of file LocalisationCache.php.
Referenced by recache().
LocalisationCache::loadItem | ( | $ | code, |
$ | key | ||
) | [protected] |
Load an item into the cache.
$code | |
$key |
Definition at line 281 of file LocalisationCache.php.
References getSubitem(), and initLanguage().
Referenced by getItem(), and loadSubitem().
LocalisationCache::loadSubitem | ( | $ | code, |
$ | key, | ||
$ | subkey | ||
) | [protected] |
Load a subitem into the cache.
$code | |
$key | |
$subkey |
Definition at line 318 of file LocalisationCache.php.
References initLanguage(), and loadItem().
Referenced by getSubitem().
LocalisationCache::mergeExtensionItem | ( | $ | codeSequence, |
$ | key, | ||
&$ | value, | ||
$ | fallbackValue | ||
) | [protected] |
Given an array mapping language code to localisation value, such as is found in extension *.i18n.php files, iterate through a fallback sequence to merge the given data with an existing primary value.
Returns true if any data from the extension array was used, false otherwise.
$codeSequence | |
$key | |
$value | |
$fallbackValue |
Definition at line 533 of file LocalisationCache.php.
References mergeItem().
Referenced by recache().
LocalisationCache::mergeItem | ( | $ | key, |
&$ | value, | ||
$ | fallbackValue | ||
) | [protected] |
Merge two localisation values, a primary and a fallback, overwriting the primary value in place.
$key | |
$value | |
$fallbackValue |
Definition at line 476 of file LocalisationCache.php.
References mergeMagicWords().
Referenced by mergeExtensionItem(), and recache().
LocalisationCache::mergeMagicWords | ( | &$ | value, |
$ | fallbackValue | ||
) | [protected] |
$value | |
$fallbackValue |
Definition at line 506 of file LocalisationCache.php.
Referenced by mergeItem().
LocalisationCache::readPHPFile | ( | $ | _fileName, |
$ | _fileType | ||
) | [protected] |
Read a PHP file containing localisation data.
$_fileName | |
$_fileType |
Reimplemented in LocalisationCache_BulkLoad.
Definition at line 452 of file LocalisationCache.php.
References $data.
Referenced by recache().
LocalisationCache::recache | ( | $ | code | ) |
Load localisation data for a given language for both core and extensions and save it to the persistent cache store and the process cache.
$code |
Reimplemented in LocalisationCache_BulkLoad.
Definition at line 550 of file LocalisationCache.php.
References $data, $page, $wgExtensionMessagesFiles, buildPreload(), MessageBlobStore\clear(), Language\getMessagesFileName(), isMergeableKey(), mergeExtensionItem(), mergeItem(), readPHPFile(), wfDebug(), wfProfileIn(), wfProfileOut(), and wfRunHooks().
Referenced by initLanguage().
LocalisationCache::unload | ( | $ | code | ) |
Unload the data for a given language from the object cache.
Reduces memory usage.
$code |
Reimplemented in LocalisationCache_BulkLoad.
Definition at line 745 of file LocalisationCache.php.
Referenced by unloadAll().
Unload all data.
Definition at line 761 of file LocalisationCache.php.
References unload().
LocalisationCache::$allKeys [static] |
array( 'fallback', 'namespaceNames', 'bookstoreList', 'magicWords', 'messages', 'rtl', 'capitalizeAllNouns', 'digitTransformTable', 'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension', 'linkTrail', 'namespaceAliases', 'dateFormats', 'datePreferences', 'datePreferenceMigrationMap', 'defaultDateFormat', 'extraUserToggles', 'specialPageAliases', 'imageFiles', 'preloadedMessages', 'namespaceGenderAliases', 'digitGroupingPattern' )
All item keys.
Definition at line 85 of file LocalisationCache.php.
LocalisationCache::$conf |
Configuration associative array.
Definition at line 19 of file LocalisationCache.php.
Referenced by __construct().
LocalisationCache::$data = array() |
The cache data.
3-d array, where the first key is the language code, the second key is the item key e.g. 'messages', and the third key is an item specific subkey index. Some items are not arrays and so for those items, there are no subkeys.
Definition at line 39 of file LocalisationCache.php.
Referenced by buildPreload(), readPHPFile(), LocalisationCache_BulkLoad\readPHPFile(), and recache().
LocalisationCache::$forceRecache = false |
True to treat all files as expired until they are regenerated by this object.
Definition at line 31 of file LocalisationCache.php.
LocalisationCache::$initialisedLangs = array() |
An array where presence of a key indicates that that language has been initialised.
Initialisation includes checking for cache expiry and doing any necessary updates.
Definition at line 68 of file LocalisationCache.php.
LocalisationCache::$loadedItems = array() |
A 2-d associative array, code/key, where presence indicates that the item is loaded.
Value arbitrary.
For split items, if set, this indicates that all of the subitems have been loaded.
Definition at line 55 of file LocalisationCache.php.
LocalisationCache::$loadedSubitems = array() |
A 3-d associative array, code/key/subkey, where presence indicates that the subitem is loaded.
Only used for the split items, i.e. messages.
Definition at line 61 of file LocalisationCache.php.
LocalisationCache::$magicWordKeys = array( 'magicWords' ) [static] |
Keys for items that are formatted like $magicWords.
Definition at line 125 of file LocalisationCache.php.
LocalisationCache::$manualRecache = false |
True if recaching should only be done on an explicit call to recache().
Setting this reduces the overhead of cache freshness checking, which requires doing a stat() for every extension i18n file.
Definition at line 26 of file LocalisationCache.php.
LocalisationCache::$mergeableAliasListKeys = array( 'specialPageAliases' ) [static] |
Keys for items which contain an array of arrays of equivalent aliases for each subitem.
The aliases may be merged by a fallback sequence.
Definition at line 113 of file LocalisationCache.php.
LocalisationCache::$mergeableKeys = null |
Definition at line 137 of file LocalisationCache.php.
LocalisationCache::$mergeableListKeys = array( 'extraUserToggles' ) [static] |
Keys for items which are a numbered array.
Definition at line 107 of file LocalisationCache.php.
LocalisationCache::$mergeableMapKeys [static] |
array( 'messages', 'namespaceNames', 'dateFormats', 'imageFiles', 'preloadedMessages', )
Keys for items which consist of associative arrays, which may be merged by a fallback sequence.
Definition at line 100 of file LocalisationCache.php.
LocalisationCache::$optionalMergeKeys = array( 'bookstoreList' ) [static] |
Keys for items which contain an associative array, and may be merged if the primary value contains the special array key "inherit".
That array key is removed after the first merge.
Definition at line 120 of file LocalisationCache.php.
LocalisationCache::$preloadedKeys = array( 'dateFormats', 'namespaceNames' ) [static] |
Keys which are loaded automatically by initLanguage()
Definition at line 135 of file LocalisationCache.php.
LocalisationCache::$recachedLangs = array() |
An array where the keys are codes that have been recached by this instance.
Definition at line 80 of file LocalisationCache.php.
LocalisationCache::$shallowFallbacks = array() |
An array mapping non-existent pseudo-languages to fallback languages.
This is filled by initShallowFallback() when data is requested from a language that lacks a Messages*.php file.
Definition at line 75 of file LocalisationCache.php.
LocalisationCache::$splitKeys = array( 'messages' ) [static] |
Keys for items where the subitems are stored in the backend separately.
Definition at line 130 of file LocalisationCache.php.
LocalisationCache::$store |
Definition at line 46 of file LocalisationCache.php.