MediaWiki master
|
Caching for the contents of localisation files. More...
Inherited by LocalisationCacheBulkLoad.
Public Member Functions | |
__construct (ServiceOptions $options, LCStore $store, LoggerInterface $logger, array $clearStoreCallbacks, LanguageNameUtils $langNameUtils, HookContainer $hookContainer) | |
For constructor parameters, \MediaWiki\MainConfigSchema::LocalisationCacheConf. | |
disableBackend () | |
Disable the storage backend. | |
getItem ( $code, $key) | |
Get a cache item. | |
getMessagesDirs () | |
Gets the combined list of messages dirs from core and extensions. | |
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. | |
getSubitemWithSource ( $code, $key, $subkey) | |
Get a subitem with its source language. | |
isExpired ( $code) | |
Returns true if the cache identified by $code is missing or expired. | |
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. | |
Static Public Member Functions | |
static | getStoreFromConf (array $conf, $fallbackCacheDir) |
Return a suitable LCStore as specified by the given configuration. | |
Public Attributes | |
const | ALL_ALIAS_KEYS = [ 'specialPageAliases' ] |
Keys for items which can be localized. | |
const | ALL_KEYS |
All item keys. | |
const | CONSTRUCTOR_OPTIONS |
const | VERSION = 5 |
Protected Member Functions | |
readPHPFile ( $_fileName, $_fileType) | |
Read a PHP file containing localisation data. | |
Protected Attributes | |
array< string, array > | $data = [] |
The cache data. | |
array< string, array< string, array< string, string > > > | $sourceLanguage = [] |
The source language of cached data items. | |
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 48 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 332 of file LocalisationCache.php.
References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), and MediaWiki\Config\ServiceOptions\get().
LocalisationCache::disableBackend | ( | ) |
Disable the storage backend.
Definition at line 1364 of file LocalisationCache.php.
Referenced by MediaWiki\MediaWikiServices\disableStorage().
LocalisationCache::getItem | ( | $code, | |
$key ) |
Get a cache item.
Warning: this may be slow for split items (messages), since it will need to fetch all the subitems from the cache individually.
string | $code | |
string | $key |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 379 of file LocalisationCache.php.
LocalisationCache::getMessagesDirs | ( | ) |
Gets the combined list of messages dirs from core and extensions.
Definition at line 961 of file LocalisationCache.php.
References $IP.
|
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 282 of file LocalisationCache.php.
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 399 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::SPLIT_KEYS.
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 442 of file LocalisationCache.php.
LocalisationCache::getSubitemWithSource | ( | $code, | |
$key, | |||
$subkey ) |
Get a subitem with its source language.
Only supports messages for now.
string | $code | |
string | $key | |
string | $subkey |
Definition at line 418 of file LocalisationCache.php.
LocalisationCache::isExpired | ( | $code | ) |
Returns true if the cache identified by $code is missing or expired.
string | $code |
Definition at line 559 of file LocalisationCache.php.
References CacheDependency\isExpired().
|
protected |
Read a PHP file containing localisation data.
string | $_fileName | |
string | $_fileType |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 698 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 |
Reimplemented in LocalisationCacheBulkLoad.
Definition at line 1069 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 1336 of file LocalisationCache.php.
LocalisationCache::unloadAll | ( | ) |
Unload all data.
Definition at line 1355 of file LocalisationCache.php.
|
protected |
The cache data.
2/3-d array, where the first key is the language code, the second key is the item key e.g. 'messages', and the optional 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 71 of file LocalisationCache.php.
Referenced by LocalisationCacheBulkLoad\readPHPFile().
|
protected |
The source language of cached data items.
Only supports messages for now.
Definition at line 78 of file LocalisationCache.php.
const LocalisationCache::ALL_ALIAS_KEYS = [ 'specialPageAliases' ] |
Keys for items which can be localized.
Definition at line 194 of file LocalisationCache.php.
const LocalisationCache::ALL_KEYS |
All item keys.
Definition at line 150 of file LocalisationCache.php.
const LocalisationCache::CONSTRUCTOR_OPTIONS |
Definition at line 310 of file LocalisationCache.php.
const LocalisationCache::VERSION = 5 |
Definition at line 49 of file LocalisationCache.php.