MediaWiki
master
|
Caching for the contents of localisation files. More...
Public Member Functions | |
__construct (ServiceOptions $options, LCStore $store, LoggerInterface $logger, array $clearStoreCallbacks, LanguageNameUtils $langNameUtils, HookContainer $hookContainer) | |
For constructor parameters, \MediaWiki\MainConfigSchema::LocalisationCacheConf. More... | |
disableBackend () | |
Disable the storage backend. More... | |
getCompiledPluralRules ( $code) | |
Get the compiled plural rules for a given language from the XML files. More... | |
getItem ( $code, $key) | |
Get a cache item. More... | |
getMessagesDirs () | |
Gets the combined list of messages dirs from core and extensions. More... | |
getPluralRules ( $code) | |
Get the plural rules for a given language from the XML files. More... | |
getPluralRuleTypes ( $code) | |
Get the plural rule types for a given language from the XML files. More... | |
getSubitem ( $code, $key, $subkey) | |
Get a subitem, for instance a single message for a given language. More... | |
getSubitemList ( $code, $key) | |
Get the list of subitem keys for a given item. More... | |
initShallowFallback ( $primaryCode, $fallbackCode) | |
Create a fallback from one language to another, without creating a complete persistent cache. More... | |
isExpired ( $code) | |
Returns true if the cache identified by $code is missing or expired. More... | |
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. More... | |
readJSONFile ( $fileName) | |
Read a JSON file containing localisation messages. More... | |
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. More... | |
unload ( $code) | |
Unload the data for a given language from the object cache. More... | |
unloadAll () | |
Unload all data. More... | |
Static Public Member Functions | |
static | getStoreFromConf (array $conf, $fallbackCacheDir) |
Return a suitable LCStore as specified by the given configuration. More... | |
Public Attributes | |
const | CONSTRUCTOR_OPTIONS |
const | VERSION = 4 |
Static Public Attributes | |
static | $allKeys |
All item keys. More... | |
static | $magicWordKeys = [ 'magicWords' ] |
Keys for items that are formatted like $magicWords. More... | |
static | $mergeableAliasListKeys = [ 'specialPageAliases' ] |
Keys for items which contain an array of arrays of equivalent aliases for each subitem. More... | |
static | $mergeableListKeys = [] |
Keys for items which are a numbered array. More... | |
static | $mergeableMapKeys |
Keys for items which consist of associative arrays, which may be merged by a fallback sequence. More... | |
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". More... | |
static | $preloadedKeys = [ 'dateFormats', 'namespaceNames' ] |
Keys which are loaded automatically by initLanguage() More... | |
static | $splitKeys = [ 'messages' ] |
Keys for items where the subitems are stored in the backend separately. More... | |
Protected Member Functions | |
buildPreload ( $data) | |
Build the preload item from the given pre-cache data. More... | |
initLanguage ( $code) | |
Initialise a language in this object. More... | |
loadItem ( $code, $key) | |
Load an item into the cache. More... | |
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. More... | |
loadPluralFiles () | |
Load the plural XML files. More... | |
loadSubitem ( $code, $key, $subkey) | |
Load a subitem into the cache. More... | |
mergeItem ( $key, &$value, $fallbackValue) | |
Merge two localisation values, a primary and a fallback, overwriting the primary value in place. More... | |
mergeMagicWords (&$value, $fallbackValue) | |
readPHPFile ( $_fileName, $_fileType) | |
Read a PHP file containing localisation data. More... | |
readSourceFilesAndRegisterDeps ( $code, &$deps) | |
Read the data from the source files for a given language, and register the relevant dependencies in the $deps array. More... | |
Protected Attributes | |
$data = [] | |
The cache data. More... | |
Caching for the contents of localisation files.
Including for i18n JSON files under /languages/messages
, Messages*.php
, and *.i18n.php
.
An instance of this class is available using MediaWikiServices.
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 46 of file LocalisationCache.php.
LocalisationCache::__construct | ( | ServiceOptions | $options, |
LCStore | $store, | ||
LoggerInterface | $logger, | ||
array | $clearStoreCallbacks, | ||
LanguageNameUtils | $langNameUtils, | ||
HookContainer | $hookContainer | ||
) |
For constructor parameters, \MediaWiki\MainConfigSchema::LocalisationCacheConf.
ServiceOptions | $options | |
LCStore | $store | What backend to use for storage |
LoggerInterface | $logger | |
callable[] | $clearStoreCallbacks | To be called whenever the cache is cleared. Can be used to clear other caches that depend on this one, such as ResourceLoader's MessageBlobStore. |
LanguageNameUtils | $langNameUtils | |
HookContainer | $hookContainer |
Definition at line 259 of file LocalisationCache.php.
References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), and MediaWiki\Config\ServiceOptions\get().
|
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 1043 of file LocalisationCache.php.
LocalisationCache::disableBackend | ( | ) |
Disable the storage backend.
Definition at line 1088 of file LocalisationCache.php.
Referenced by MediaWiki\MediaWikiServices\disableStorage().
LocalisationCache::getCompiledPluralRules | ( | $code | ) |
Get the compiled plural rules for a given language from the XML files.
string | $code |
Definition at line 616 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.
string | $code | |
string | $key |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 309 of file LocalisationCache.php.
LocalisationCache::getMessagesDirs | ( | ) |
Gets the combined list of messages dirs from core and extensions.
Definition at line 805 of file LocalisationCache.php.
References $IP.
LocalisationCache::getPluralRules | ( | $code | ) |
Get the plural rules for a given language from the XML files.
Cached.
string | $code |
Definition at line 639 of file LocalisationCache.php.
LocalisationCache::getPluralRuleTypes | ( | $code | ) |
Get the plural rule types for a given language from the XML files.
Cached.
string | $code |
Definition at line 653 of file LocalisationCache.php.
|
static |
Return a suitable LCStore as specified by the given configuration.
array | $conf | In the format of $wgLocalisationCacheConf |
string | false | null | $fallbackCacheDir | In case 'storeDirectory' isn't specified |
Definition at line 210 of file LocalisationCache.php.
Referenced by RebuildLocalisationCache\execute().
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 328 of file LocalisationCache.php.
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 350 of file LocalisationCache.php.
|
protected |
Initialise a language in this object.
Rebuild the cache if necessary.
string | $code |
MWException |
Definition at line 479 of file LocalisationCache.php.
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 540 of file LocalisationCache.php.
LocalisationCache::isExpired | ( | $code | ) |
Returns true if the cache identified by $code is missing or expired.
string | $code |
Definition at line 441 of file LocalisationCache.php.
References $keys, and CacheDependency\isExpired().
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 286 of file LocalisationCache.php.
|
protected |
Load an item into the cache.
string | $code | |
string | $key |
Definition at line 368 of file LocalisationCache.php.
|
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 686 of file LocalisationCache.php.
|
protected |
Load the plural XML files.
Definition at line 663 of file LocalisationCache.php.
|
protected |
Load a subitem into the cache.
string | $code | |
string | $key | |
string | $subkey |
Definition at line 405 of file LocalisationCache.php.
|
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 756 of file LocalisationCache.php.
|
protected |
mixed | &$value | |
mixed | $fallbackValue |
Definition at line 784 of file LocalisationCache.php.
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 584 of file LocalisationCache.php.
References FormatJson\decode().
|
protected |
Read a PHP file containing localisation data.
string | $_fileName | |
string | $_fileType |
MWException |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 554 of file LocalisationCache.php.
|
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 725 of file LocalisationCache.php.
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 824 of file LocalisationCache.php.
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 1062 of file LocalisationCache.php.
LocalisationCache::unloadAll | ( | ) |
|
static |
All item keys.
Definition at line 126 of file LocalisationCache.php.
|
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 65 of file LocalisationCache.php.
Referenced by LocalisationCacheBulkLoad\readPHPFile().
|
static |
Keys for items that are formatted like $magicWords.
Definition at line 168 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 156 of file LocalisationCache.php.
|
static |
Keys for items which are a numbered array.
Definition at line 150 of file LocalisationCache.php.
|
static |
Keys for items which consist of associative arrays, which may be merged by a fallback sequence.
Definition at line 143 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 163 of file LocalisationCache.php.
|
static |
Keys which are loaded automatically by initLanguage()
Definition at line 178 of file LocalisationCache.php.
|
static |
Keys for items where the subitems are stored in the backend separately.
Definition at line 173 of file LocalisationCache.php.
const LocalisationCache::CONSTRUCTOR_OPTIONS |
Definition at line 238 of file LocalisationCache.php.
Referenced by RebuildLocalisationCache\execute().
const LocalisationCache::VERSION = 4 |
Definition at line 47 of file LocalisationCache.php.