MediaWiki master
LocalisationCache Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __construct()

LocalisationCache::__construct ( ServiceOptions $options,
LCStore $store,
LoggerInterface $logger,
array $clearStoreCallbacks,
LanguageNameUtils $langNameUtils,
HookContainer $hookContainer )

For constructor parameters, \MediaWiki\MainConfigSchema::LocalisationCacheConf.

Access: internal
Do not construct directly, use MediaWikiServices instead.
Parameters
ServiceOptions$options
LCStore$storeWhat backend to use for storage
LoggerInterface$logger
callable[]$clearStoreCallbacksTo 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 329 of file LocalisationCache.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), and MediaWiki\Config\ServiceOptions\get().

Member Function Documentation

◆ disableBackend()

LocalisationCache::disableBackend ( )

Disable the storage backend.

Definition at line 1360 of file LocalisationCache.php.

Referenced by MediaWiki\MediaWikiServices\disableStorage().

◆ getItem()

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.

Parameters
string$code
string$key
Returns
mixed

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 376 of file LocalisationCache.php.

◆ getMessagesDirs()

LocalisationCache::getMessagesDirs ( )

Gets the combined list of messages dirs from core and extensions.

Since
1.25
Returns
array

Definition at line 960 of file LocalisationCache.php.

References $IP.

◆ getStoreFromConf()

static LocalisationCache::getStoreFromConf ( array $conf,
$fallbackCacheDir )
static

Return a suitable LCStore as specified by the given configuration.

Since
1.34
Parameters
array$confIn the format of $wgLocalisationCacheConf
string | false | null$fallbackCacheDirIn case 'storeDirectory' isn't specified
Returns
LCStore

Definition at line 279 of file LocalisationCache.php.

◆ getSubitem()

LocalisationCache::getSubitem ( $code,
$key,
$subkey )

Get a subitem, for instance a single message for a given language.

Parameters
string$code
string$key
string$subkey
Returns
mixed|null

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 396 of file LocalisationCache.php.

◆ getSubitemList()

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.

Parameters
string$code
string$key
Returns
bool|null|string|string[]

Definition at line 439 of file LocalisationCache.php.

◆ getSubitemWithSource()

LocalisationCache::getSubitemWithSource ( $code,
$key,
$subkey )

Get a subitem with its source language.

Only supports messages for now.

Since
1.41
Parameters
string$code
string$key
string$subkey
Returns
string[]|null Return [ subitem, sourceLanguage ] if the subitem is defined.

Definition at line 415 of file LocalisationCache.php.

◆ isExpired()

LocalisationCache::isExpired ( $code)

Returns true if the cache identified by $code is missing or expired.

Parameters
string$code
Returns
bool

Definition at line 556 of file LocalisationCache.php.

References CacheDependency\isExpired().

◆ readPHPFile()

LocalisationCache::readPHPFile ( $_fileName,
$_fileType )
protected

Read a PHP file containing localisation data.

Parameters
string$_fileName
string$_fileType
Returns
array

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 695 of file LocalisationCache.php.

◆ 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.

Parameters
string$code

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 1065 of file LocalisationCache.php.

◆ unload()

LocalisationCache::unload ( $code)

Unload the data for a given language from the object cache.

Reduces memory usage.

Parameters
string$code

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 1332 of file LocalisationCache.php.

◆ unloadAll()

LocalisationCache::unloadAll ( )

Unload all data.

Definition at line 1351 of file LocalisationCache.php.

Member Data Documentation

◆ $data

array<string,array> LocalisationCache::$data = []
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 69 of file LocalisationCache.php.

Referenced by LocalisationCacheBulkLoad\readPHPFile().

◆ $sourceLanguage

array<string,array<string,array<string,string> > > LocalisationCache::$sourceLanguage = []
protected

The source language of cached data items.

Only supports messages for now.

Definition at line 76 of file LocalisationCache.php.

◆ ALL_ALIAS_KEYS

const LocalisationCache::ALL_ALIAS_KEYS = [ 'specialPageAliases' ]

Keys for items which can be localized.

Definition at line 191 of file LocalisationCache.php.

◆ ALL_KEYS

const LocalisationCache::ALL_KEYS
Initial value:
= [
'fallback', 'namespaceNames', 'bookstoreList',
'magicWords', 'messages', 'rtl',
'digitTransformTable', 'separatorTransformTable',
'minimumGroupingDigits', 'fallback8bitEncoding',
'linkPrefixExtension', 'linkTrail', 'linkPrefixCharset',
'namespaceAliases', 'dateFormats', 'datePreferences',
'datePreferenceMigrationMap', 'defaultDateFormat',
'specialPageAliases', 'imageFiles', 'preloadedMessages',
'namespaceGenderAliases', 'digitGroupingPattern', 'pluralRules',
'pluralRuleTypes', 'compiledPluralRules',
]

All item keys.

Definition at line 148 of file LocalisationCache.php.

◆ CONSTRUCTOR_OPTIONS

const LocalisationCache::CONSTRUCTOR_OPTIONS
Initial value:
= [
'forceRecache',
'manualRecache',
MainConfigNames::ExtensionMessagesFiles,
MainConfigNames::MessagesDirs,
MainConfigNames::TranslationAliasesDirs,
]
Access: internal
For use by ServiceWiring

Definition at line 307 of file LocalisationCache.php.

◆ VERSION

const LocalisationCache::VERSION = 5

Definition at line 47 of file LocalisationCache.php.


The documentation for this class was generated from the following file: