|
MediaWiki master
|
Caching for the contents of localisation files. More...
Inherited by MediaWiki\Language\LocalisationCacheBulkLoad.
Public Member Functions | |
| __construct (private readonly ServiceOptions $options, private LCStore $store, private readonly LoggerInterface $logger, array $clearStoreCallbacks, private readonly LanguageNameUtils $langNameUtils, HookContainer $hookContainer,) | |
| For constructor parameters, \MediaWiki\MainConfigSchema::LocalisationCacheConf. | |
| disableBackend () | |
| Disable the storage backend. | |
| getExpiredReason ( $code) | |
| Returns a string describing the reason a call to isExpired ( $code ) returned true. | |
| 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. | |
| setSubitemForTesting (string $code, string $key, string $subkey, mixed $value) | |
| Override a subitem value. | |
| 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 = 7 |
Protected Member Functions | |
| getFallbackCodes (string $code) | |
| Get the set of language codes, including the current language code and any fallbacks to read from in order. | |
| 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 47 of file LocalisationCache.php.
| MediaWiki\Language\LocalisationCache::__construct | ( | private readonly ServiceOptions | $options, |
| private LCStore | $store, | ||
| private readonly LoggerInterface | $logger, | ||
| array | $clearStoreCallbacks, | ||
| private readonly 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 351 of file LocalisationCache.php.
| MediaWiki\Language\LocalisationCache::disableBackend | ( | ) |
Disable the storage backend.
Definition at line 1485 of file LocalisationCache.php.
Referenced by MediaWiki\MediaWikiServices\disableStorage().
| MediaWiki\Language\LocalisationCache::getExpiredReason | ( | $code | ) |
Returns a string describing the reason a call to isExpired ( $code ) returned true.
| string | $code |
Definition at line 667 of file LocalisationCache.php.
|
protected |
Get the set of language codes, including the current language code and any fallbacks to read from in order.
If fallbacks are disabled this is just the current code.
| string | $code |
Definition at line 554 of file LocalisationCache.php.
| MediaWiki\Language\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 MediaWiki\Language\LocalisationCacheBulkLoad.
Definition at line 394 of file LocalisationCache.php.
| MediaWiki\Language\LocalisationCache::getMessagesDirs | ( | ) |
Gets the combined list of messages dirs from core and extensions.
Definition at line 1053 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 290 of file LocalisationCache.php.
| MediaWiki\Language\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 MediaWiki\Language\LocalisationCacheBulkLoad.
Definition at line 414 of file LocalisationCache.php.
| MediaWiki\Language\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 457 of file LocalisationCache.php.
| MediaWiki\Language\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 433 of file LocalisationCache.php.
| MediaWiki\Language\LocalisationCache::isExpired | ( | $code | ) |
Returns true if the cache identified by $code is missing or expired.
| string | $code |
Definition at line 615 of file LocalisationCache.php.
|
protected |
Read a PHP file containing localisation data.
| string | $_fileName | |
| string | $_fileType |
Reimplemented in MediaWiki\Language\LocalisationCacheBulkLoad.
Definition at line 779 of file LocalisationCache.php.
| MediaWiki\Language\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 MediaWiki\Language\LocalisationCacheBulkLoad.
Definition at line 1169 of file LocalisationCache.php.
| MediaWiki\Language\LocalisationCache::setSubitemForTesting | ( | string | $code, |
| string | $key, | ||
| string | $subkey, | ||
| mixed | $value ) |
| MediaWiki\Language\LocalisationCache::unload | ( | $code | ) |
Unload the data for a given language from the object cache.
Reduces memory usage.
| string | $code |
Reimplemented in MediaWiki\Language\LocalisationCacheBulkLoad.
Definition at line 1457 of file LocalisationCache.php.
| MediaWiki\Language\LocalisationCache::unloadAll | ( | ) |
Unload all data.
Definition at line 1476 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 67 of file LocalisationCache.php.
Referenced by MediaWiki\Language\LocalisationCacheBulkLoad\readPHPFile().
|
protected |
The source language of cached data items.
Only supports messages for now.
Definition at line 74 of file LocalisationCache.php.
| const MediaWiki\Language\LocalisationCache::ALL_ALIAS_KEYS = [ 'specialPageAliases' ] |
Keys for items which can be localized.
Definition at line 190 of file LocalisationCache.php.
| const MediaWiki\Language\LocalisationCache::ALL_KEYS |
All item keys.
Definition at line 145 of file LocalisationCache.php.
| const MediaWiki\Language\LocalisationCache::CONSTRUCTOR_OPTIONS |
Definition at line 328 of file LocalisationCache.php.
| const MediaWiki\Language\LocalisationCache::VERSION = 7 |
Definition at line 48 of file LocalisationCache.php.