MediaWiki REL1_33
|
Class for caching the contents of localisation files, Messages*.php and *.i18n.php. More...
Public Member Functions | |
__construct ( $conf) | |
For constructor parameters, see the documentation in DefaultSettings.php for $wgLocalisationCacheConf. | |
disableBackend () | |
Disable the storage backend. | |
getCompiledPluralRules ( $code) | |
Get the compiled plural rules for a given language from the XML files. | |
getItem ( $code, $key) | |
Get a cache item. | |
getMessagesDirs () | |
Gets the combined list of messages dirs from core and extensions. | |
getPluralRules ( $code) | |
Get the plural rules for a given language from the XML files. | |
getPluralRuleTypes ( $code) | |
Get the plural rule types for a given language from the XML files. | |
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. | |
readJSONFile ( $fileName) | |
Read a JSON file containing localisation messages. | |
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 | |
const | VERSION = 4 |
Static Public Attributes | |
static | $allKeys |
All item keys. | |
static | $magicWordKeys = [ 'magicWords' ] |
Keys for items that are formatted like $magicWords. | |
static | $mergeableAliasListKeys = [ 'specialPageAliases' ] |
Keys for items which contain an array of arrays of equivalent aliases for each subitem. | |
static | $mergeableListKeys = [ '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 = [ '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 = [ 'dateFormats', 'namespaceNames' ] |
Keys which are loaded automatically by initLanguage() | |
static | $splitKeys = [ '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. | |
loadPluralFile ( $fileName) | |
Load a plural XML file with the given filename, compile the relevant rules, and save the compiled rules in a process-local cache. | |
loadPluralFiles () | |
Load the plural XML files. | |
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. | |
readSourceFilesAndRegisterDeps ( $code, &$deps) | |
Read the data from the source files for a given language, and register the relevant dependencies in the $deps array. | |
Protected Attributes | |
$data = [] | |
The cache data. | |
Private Attributes | |
$conf | |
Configuration associative array. | |
$forceRecache = false | |
True to treat all files as expired until they are regenerated by this object. | |
$initialisedLangs = [] | |
An array where presence of a key indicates that that language has been initialised. | |
$loadedItems = [] | |
A 2-d associative array, code/key, where presence indicates that the item is loaded. | |
$loadedSubitems = [] | |
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 | |
$pluralRules = null | |
Associative array of cached plural rules. | |
$pluralRuleTypes = null | |
Associative array of cached plural rule types. | |
$recachedLangs = [] | |
An array where the keys are codes that have been recached by this instance. | |
$shallowFallbacks = [] | |
An array mapping non-existent pseudo-languages to fallback languages. | |
LCStore | $store |
The persistent store object. | |
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 39 of file LocalisationCache.php.
LocalisationCache::__construct | ( | $conf | ) |
For constructor parameters, see the documentation in DefaultSettings.php for $wgLocalisationCacheConf.
array | $conf |
MWException |
Definition at line 191 of file LocalisationCache.php.
References $conf, $wgCacheDirectory, and(), and wfDebugLog().
|
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.
array | $data |
Definition at line 1051 of file LocalisationCache.php.
Referenced by recache().
LocalisationCache::disableBackend | ( | ) |
Disable the storage backend.
Definition at line 1096 of file LocalisationCache.php.
LocalisationCache::getCompiledPluralRules | ( | $code | ) |
Get the compiled plural rules for a given language from the XML files.
string | $code |
Definition at line 586 of file LocalisationCache.php.
References $code, $e, and(), getPluralRules(), and wfDebugLog().
Referenced by readSourceFilesAndRegisterDeps().
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.
string | $code | |
string | $key |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 271 of file LocalisationCache.php.
References $code, and(), and loadItem().
Referenced by getSubitemList(), initLanguage(), and LocalisationCacheTest\testRecacheFallbacksWithHooks().
LocalisationCache::getMessagesDirs | ( | ) |
Gets the combined list of messages dirs from core and extensions.
Definition at line 799 of file LocalisationCache.php.
Referenced by recache().
LocalisationCache::getPluralRules | ( | $code | ) |
Get the plural rules for a given language from the XML files.
Cached.
string | $code |
Definition at line 609 of file LocalisationCache.php.
References $code, and loadPluralFiles().
Referenced by getCompiledPluralRules(), and readSourceFilesAndRegisterDeps().
LocalisationCache::getPluralRuleTypes | ( | $code | ) |
Get the plural rule types for a given language from the XML files.
Cached.
string | $code |
Definition at line 623 of file LocalisationCache.php.
References $code, and loadPluralFiles().
Referenced by readSourceFilesAndRegisterDeps().
LocalisationCache::getSubitem | ( | $code, | |
$key, | |||
$subkey ) |
Get a subitem, for instance a single message for a given language.
string | $code | |
string | $key | |
string | $subkey |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 290 of file LocalisationCache.php.
References $code, and(), and loadSubitem().
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.
string | $code | |
string | $key |
Definition at line 312 of file LocalisationCache.php.
References $code, and(), getItem(), and getSubitem().
|
protected |
Initialise a language in this object.
Rebuild the cache if necessary.
string | $code |
MWException |
Definition at line 441 of file LocalisationCache.php.
References $code, and(), getItem(), initShallowFallback(), isExpired(), 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.
string | $primaryCode | |
string | $fallbackCode |
Definition at line 502 of file LocalisationCache.php.
References and().
Referenced by initLanguage().
LocalisationCache::isExpired | ( | $code | ) |
Returns true if the cache identified by $code is missing or expired.
string | $code |
Definition at line 403 of file LocalisationCache.php.
References $code, $keys, and(), 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.
string | $key |
Definition at line 248 of file LocalisationCache.php.
References and().
Referenced by recache().
|
protected |
Load an item into the cache.
string | $code | |
string | $key |
Definition at line 330 of file LocalisationCache.php.
References $code, and(), getSubitem(), initLanguage(), and loadItem().
Referenced by getItem(), loadItem(), and loadSubitem().
|
protected |
Load a plural XML file with the given filename, compile the relevant rules, and save the compiled rules in a process-local cache.
string | $fileName |
MWException |
Definition at line 652 of file LocalisationCache.php.
Referenced by loadPluralFiles().
|
protected |
Load the plural XML files.
Definition at line 633 of file LocalisationCache.php.
References $IP, and(), and loadPluralFile().
Referenced by getPluralRules(), and getPluralRuleTypes().
|
protected |
Load a subitem into the cache.
string | $code | |
string | $key | |
string | $subkey |
Definition at line 367 of file LocalisationCache.php.
References $code, $value, and(), initLanguage(), loadItem(), and loadSubitem().
Referenced by getSubitem(), and loadSubitem().
|
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.
array | $codeSequence | |
string | $key | |
mixed | &$value | |
mixed | $fallbackValue |
Definition at line 780 of file LocalisationCache.php.
References $code, $value, and(), and mergeItem().
|
protected |
Merge two localisation values, a primary and a fallback, overwriting the primary value in place.
string | $key | |
mixed | &$value | |
mixed | $fallbackValue |
Definition at line 723 of file LocalisationCache.php.
References $value, and(), and mergeMagicWords().
Referenced by mergeExtensionItem(), and recache().
|
protected |
mixed | &$value | |
mixed | $fallbackValue |
Definition at line 753 of file LocalisationCache.php.
Referenced by mergeItem().
LocalisationCache::readJSONFile | ( | $fileName | ) |
Read a JSON file containing localisation messages.
string | $fileName | Name of file to read |
MWException | If there is a syntax error in the JSON file |
Definition at line 554 of file LocalisationCache.php.
Referenced by recache().
|
protected |
Read a PHP file containing localisation data.
string | $_fileName | |
string | $_fileType |
MWException |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 516 of file LocalisationCache.php.
Referenced by readSourceFilesAndRegisterDeps(), and recache().
|
protected |
Read the data from the source files for a given language, and register the relevant dependencies in the $deps array.
If the localisation exists, the data array is returned, otherwise false is returned.
string | $code | |
array | &$deps |
Definition at line 691 of file LocalisationCache.php.
References $code, $data, $IP, and(), getCompiledPluralRules(), getPluralRules(), getPluralRuleTypes(), and readPHPFile().
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.
string | $code |
MWException |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 818 of file LocalisationCache.php.
References $code, $data, $value, $wgExtensionMessagesFiles, and(), array(), buildPreload(), getMessagesDirs(), isMergeableKey(), mergeItem(), readJSONFile(), readPHPFile(), readSourceFilesAndRegisterDeps(), and wfDebug().
Referenced by initLanguage(), and LocalisationCacheTest\testRecacheFallbacksWithHooks().
LocalisationCache::unload | ( | $code | ) |
Unload the data for a given language from the object cache.
Reduces memory usage.
string | $code |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 1070 of file LocalisationCache.php.
References $code, and(), and unload().
Referenced by unload(), and unloadAll().
LocalisationCache::unloadAll | ( | ) |
Unload all data.
Definition at line 1087 of file LocalisationCache.php.
|
static |
All item keys.
Definition at line 109 of file LocalisationCache.php.
|
private |
Configuration associative array.
Definition at line 43 of file LocalisationCache.php.
Referenced by __construct().
|
protected |
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 63 of file LocalisationCache.php.
Referenced by buildPreload(), readJSONFile(), readPHPFile(), LocalisationCacheBulkLoad\readPHPFile(), readSourceFilesAndRegisterDeps(), and recache().
|
private |
True to treat all files as expired until they are regenerated by this object.
Definition at line 55 of file LocalisationCache.php.
|
private |
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 92 of file LocalisationCache.php.
|
private |
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 79 of file LocalisationCache.php.
|
private |
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 85 of file LocalisationCache.php.
|
static |
Keys for items that are formatted like $magicWords.
Definition at line 150 of file LocalisationCache.php.
|
private |
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 50 of file LocalisationCache.php.
|
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 138 of file LocalisationCache.php.
|
private |
Definition at line 182 of file LocalisationCache.php.
|
static |
Keys for items which are a numbered array.
Definition at line 132 of file LocalisationCache.php.
|
static |
Keys for items which consist of associative arrays, which may be merged by a fallback sequence.
Definition at line 125 of file LocalisationCache.php.
|
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 145 of file LocalisationCache.php.
|
private |
Associative array of cached plural rules.
The key is the language code, the value is an array of plural rules for that language.
Definition at line 166 of file LocalisationCache.php.
|
private |
Associative array of cached plural rule types.
The key is the language code, the value is an array of plural rule types for that language. For example, $pluralRuleTypes['ar'] = ['zero', 'one', 'two', 'few', 'many']. The index for each rule type matches the index for the rule in $pluralRules, thus allowing correlation between the two. The reason we don't just use the type names as the keys in $pluralRules is because Language::convertPlural applies the rules based on numeric order (or explicit numeric parameter), not based on the name of the rule type. For example, {{plural:count|wordform1|wordform2|wordform3}}, rather than {{plural:count|one=wordform1|two=wordform2|many=wordform3}}.
Definition at line 180 of file LocalisationCache.php.
|
static |
Keys which are loaded automatically by initLanguage()
Definition at line 160 of file LocalisationCache.php.
|
private |
An array where the keys are codes that have been recached by this instance.
Definition at line 104 of file LocalisationCache.php.
|
private |
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 99 of file LocalisationCache.php.
|
static |
Keys for items where the subitems are stored in the backend separately.
Definition at line 155 of file LocalisationCache.php.
|
private |
The persistent store object.
An instance of LCStore.
Definition at line 70 of file LocalisationCache.php.
const LocalisationCache::VERSION = 4 |
Definition at line 40 of file LocalisationCache.php.