MediaWiki  1.23.2
LocalisationCache Class Reference

Class for caching the contents of localisation files, Messages*.php and *.i18n.php. More...

Inheritance diagram for LocalisationCache:
Collaboration diagram for LocalisationCache:

Public Member Functions

 __construct ( $conf)
 Constructor. 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...
 
 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 Attributes

static $allKeys
 All item keys. More...
 
static $magicWordKeys = array( 'magicWords' )
 Keys for items that are formatted like $magicWords. More...
 
static $mergeableAliasListKeys = array( 'specialPageAliases' )
 Keys for items which contain an array of arrays of equivalent aliases for each subitem. More...
 
static $mergeableListKeys = array( 'extraUserToggles' )
 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 = array( '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 = array( 'dateFormats', 'namespaceNames' )
 Keys which are loaded automatically by initLanguage() More...
 
static $splitKeys = array( '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...
 
 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. 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 = array()
 The cache data. More...
 

Private Attributes

 $conf
 Configuration associative array. More...
 
 $forceRecache = false
 True to treat all files as expired until they are regenerated by this object. More...
 
 $initialisedLangs = array()
 An array where presence of a key indicates that that language has been initialised. More...
 
 $loadedItems = array()
 A 2-d associative array, code/key, where presence indicates that the item is loaded. More...
 
 $loadedSubitems = array()
 A 3-d associative array, code/key/subkey, where presence indicates that the subitem is loaded. More...
 
 $manualRecache = false
 True if recaching should only be done on an explicit call to recache(). More...
 
 $mergeableKeys = null
 
 $pluralRules = null
 Associative array of cached plural rules. More...
 
 $pluralRuleTypes = null
 Associative array of cached plural rule types. More...
 
 $recachedLangs = array()
 An array where the keys are codes that have been recached by this instance. More...
 
 $shallowFallbacks = array()
 An array mapping non-existent pseudo-languages to fallback languages. More...
 
LCStore $store
 The persistent store object. More...
 

Detailed Description

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 37 of file LocalisationCache.php.

Constructor & Destructor Documentation

◆ __construct()

LocalisationCache::__construct (   $conf)

Constructor.

For constructor parameters, see the documentation in DefaultSettings.php for $wgLocalisationCacheConf.

Parameters
$confArray
Exceptions
MWException

Definition at line 186 of file LocalisationCache.php.

References $conf, array(), as, global, and wfDebugLog().

Member Function Documentation

◆ buildPreload()

LocalisationCache::buildPreload (   $data)
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.

Parameters
$data
Returns
array

Definition at line 989 of file LocalisationCache.php.

References $data, array(), and as.

Referenced by recache().

◆ disableBackend()

LocalisationCache::disableBackend ( )

Disable the storage backend.

Definition at line 1038 of file LocalisationCache.php.

◆ getCompiledPluralRules()

LocalisationCache::getCompiledPluralRules (   $code)

Get the compiled plural rules for a given language from the XML files.

Since
1.20

Definition at line 581 of file LocalisationCache.php.

References $e, array(), CLDRPluralRuleEvaluator\compile(), getPluralRules(), and wfDebugLog().

Referenced by readSourceFilesAndRegisterDeps().

◆ 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 of the subitems from the cache individually.

Parameters
$code
$key
Returns
mixed

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 256 of file LocalisationCache.php.

References data, loadItem(), wfProfileIn(), and wfProfileOut().

Referenced by getSubitemList(), and initLanguage().

◆ getPluralRules()

LocalisationCache::getPluralRules (   $code)

Get the plural rules for a given language from the XML files.

Cached.

Since
1.20

Definition at line 602 of file LocalisationCache.php.

References loadPluralFiles().

Referenced by getCompiledPluralRules(), and readSourceFilesAndRegisterDeps().

◆ getPluralRuleTypes()

LocalisationCache::getPluralRuleTypes (   $code)

Get the plural rule types for a given language from the XML files.

Cached.

Since
1.22

Definition at line 618 of file LocalisationCache.php.

References loadPluralFiles().

Referenced by readSourceFilesAndRegisterDeps().

◆ getSubitem()

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

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

Parameters
$code
$key
$subkey
Returns
null

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 277 of file LocalisationCache.php.

References data, loadSubitem(), wfProfileIn(), and wfProfileOut().

Referenced by getSubitemList(), and loadItem().

◆ 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::$splitKeys.

Will return null if the item is not found, or false if the item is not an array.

Parameters
$code
$key
Returns
bool|null|string

Definition at line 305 of file LocalisationCache.php.

References getItem(), and getSubitem().

◆ initLanguage()

LocalisationCache::initLanguage (   $code)
protected

Initialise a language in this object.

Rebuild the cache if necessary.

Parameters
$code
Exceptions
MWException

Definition at line 434 of file LocalisationCache.php.

References as, data, getItem(), initShallowFallback(), isExpired(), Language\isSupportedLanguage(), Language\isValidBuiltInCode(), and recache().

Referenced by loadItem(), and loadSubitem().

◆ initShallowFallback()

LocalisationCache::initShallowFallback (   $primaryCode,
  $fallbackCode 
)

Create a fallback from one language to another, without creating a complete persistent cache.

Parameters
$primaryCode
$fallbackCode

Definition at line 495 of file LocalisationCache.php.

References data.

Referenced by initLanguage().

◆ isExpired()

LocalisationCache::isExpired (   $code)

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

Parameters
string$code
Returns
bool

Definition at line 396 of file LocalisationCache.php.

References $keys, as, CacheDependency\isExpired(), and wfDebug().

Referenced by initLanguage().

◆ isMergeableKey()

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.

Parameters
$key
Returns
bool

Definition at line 233 of file LocalisationCache.php.

Referenced by recache().

◆ loadItem()

LocalisationCache::loadItem (   $code,
  $key 
)
protected

Load an item into the cache.

Parameters
$code
$key

Definition at line 323 of file LocalisationCache.php.

References as, data, getSubitem(), and initLanguage().

Referenced by getItem(), and loadSubitem().

◆ loadPluralFile()

LocalisationCache::loadPluralFile (   $fileName)
protected

Load a plural XML file with the given filename, compile the relevant rules, and save the compiled rules in a process-local cache.

Definition at line 648 of file LocalisationCache.php.

References array(), and as.

Referenced by loadPluralFiles().

◆ loadPluralFiles()

LocalisationCache::loadPluralFiles ( )
protected

Load the plural XML files.

Definition at line 632 of file LocalisationCache.php.

References $IP, global, and loadPluralFile().

Referenced by getPluralRules(), and getPluralRuleTypes().

◆ loadSubitem()

LocalisationCache::loadSubitem (   $code,
  $key,
  $subkey 
)
protected

Load a subitem into the cache.

Parameters
$code
$key
$subkey

Definition at line 360 of file LocalisationCache.php.

References $value, data, initLanguage(), and loadItem().

Referenced by getSubitem().

◆ mergeExtensionItem()

LocalisationCache::mergeExtensionItem (   $codeSequence,
  $key,
$value,
  $fallbackValue 
)
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.

Parameters
$codeSequence
$key
$value
$fallbackValue
Returns
bool

Definition at line 771 of file LocalisationCache.php.

References $value, as, and mergeItem().

Referenced by recache().

◆ mergeItem()

LocalisationCache::mergeItem (   $key,
$value,
  $fallbackValue 
)
protected

Merge two localisation values, a primary and a fallback, overwriting the primary value in place.

Parameters
$key
$value
$fallbackValue

Definition at line 714 of file LocalisationCache.php.

References $value, and mergeMagicWords().

Referenced by mergeExtensionItem(), and recache().

◆ mergeMagicWords()

LocalisationCache::mergeMagicWords ( $value,
  $fallbackValue 
)
protected
Parameters
$value
$fallbackValue

Definition at line 744 of file LocalisationCache.php.

References $value, array(), and as.

Referenced by mergeItem().

◆ readJSONFile()

LocalisationCache::readJSONFile (   $fileName)

Read a JSON file containing localisation messages.

Parameters
string$fileNameName of file to read
Exceptions
MWExceptionif there is a syntax error in the JSON file
Returns
array with a 'messages' key, or empty array if the file doesn't exist

Definition at line 541 of file LocalisationCache.php.

References $data, array(), as, FormatJson\decode(), wfProfileIn(), and wfProfileOut().

Referenced by recache().

◆ readPHPFile()

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

Read a PHP file containing localisation data.

Parameters
$_fileName
$_fileType
Exceptions
MWException
Returns
array

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 509 of file LocalisationCache.php.

References $data, wfProfileIn(), wfProfileOut(), wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by readSourceFilesAndRegisterDeps(), and recache().

◆ readSourceFilesAndRegisterDeps()

LocalisationCache::readSourceFilesAndRegisterDeps (   $code,
$deps 
)
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.

Definition at line 678 of file LocalisationCache.php.

References $data, $IP, array(), getCompiledPluralRules(), Language\getMessagesFileName(), getPluralRules(), getPluralRuleTypes(), global, readPHPFile(), wfProfileIn(), and wfProfileOut().

Referenced by recache().

◆ 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
$code
Exceptions
MWException

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 789 of file LocalisationCache.php.

References $data, $dir, $dirs, $value, $wgExtensionMessagesFiles, array(), as, buildPreload(), MessageBlobStore\clear(), data, false, global, isMergeableKey(), mergeExtensionItem(), mergeItem(), readJSONFile(), readPHPFile(), readSourceFilesAndRegisterDeps(), wfDebug(), wfProfileIn(), wfProfileOut(), and wfRunHooks().

Referenced by initLanguage().

◆ unload()

LocalisationCache::unload (   $code)

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

Reduces memory usage.

Parameters
$code

Reimplemented in LocalisationCacheBulkLoad.

Definition at line 1012 of file LocalisationCache.php.

References as, and data.

Referenced by unloadAll().

◆ unloadAll()

LocalisationCache::unloadAll ( )

Unload all data.

Definition at line 1029 of file LocalisationCache.php.

References as, and unload().

Member Data Documentation

◆ $allKeys

LocalisationCache::$allKeys
static
Initial value:
'fallback', 'namespaceNames', 'bookstoreList',
'magicWords', 'messages', 'rtl', 'capitalizeAllNouns', 'digitTransformTable',
'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
'linkTrail', 'linkPrefixCharset', 'namespaceAliases',
'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
'imageFiles', 'preloadedMessages', 'namespaceGenderAliases',
'digitGroupingPattern', 'pluralRules', 'pluralRuleTypes', 'compiledPluralRules',
)

All item keys.

Definition at line 104 of file LocalisationCache.php.

◆ $conf

LocalisationCache::$conf
private

Configuration associative array.

Definition at line 39 of file LocalisationCache.php.

Referenced by __construct().

◆ $data

LocalisationCache::$data = array()
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 59 of file LocalisationCache.php.

Referenced by buildPreload(), readJSONFile(), readPHPFile(), LocalisationCacheBulkLoad\readPHPFile(), readSourceFilesAndRegisterDeps(), and recache().

◆ $forceRecache

LocalisationCache::$forceRecache = false
private

True to treat all files as expired until they are regenerated by this object.

Definition at line 51 of file LocalisationCache.php.

◆ $initialisedLangs

LocalisationCache::$initialisedLangs = array()
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 87 of file LocalisationCache.php.

◆ $loadedItems

LocalisationCache::$loadedItems = array()
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 74 of file LocalisationCache.php.

◆ $loadedSubitems

LocalisationCache::$loadedSubitems = array()
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 80 of file LocalisationCache.php.

◆ $magicWordKeys

LocalisationCache::$magicWordKeys = array( 'magicWords' )
static

Keys for items that are formatted like $magicWords.

Definition at line 144 of file LocalisationCache.php.

◆ $manualRecache

LocalisationCache::$manualRecache = false
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 46 of file LocalisationCache.php.

◆ $mergeableAliasListKeys

LocalisationCache::$mergeableAliasListKeys = array( 'specialPageAliases' )
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 132 of file LocalisationCache.php.

◆ $mergeableKeys

LocalisationCache::$mergeableKeys = null
private

Definition at line 176 of file LocalisationCache.php.

◆ $mergeableListKeys

LocalisationCache::$mergeableListKeys = array( 'extraUserToggles' )
static

Keys for items which are a numbered array.

Definition at line 126 of file LocalisationCache.php.

◆ $mergeableMapKeys

LocalisationCache::$mergeableMapKeys
static
Initial value:
= array( 'messages', 'namespaceNames',
'dateFormats', 'imageFiles', 'preloadedMessages'
)

Keys for items which consist of associative arrays, which may be merged by a fallback sequence.

Definition at line 119 of file LocalisationCache.php.

◆ $optionalMergeKeys

LocalisationCache::$optionalMergeKeys = array( 'bookstoreList' )
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 139 of file LocalisationCache.php.

◆ $pluralRules

LocalisationCache::$pluralRules = null
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 160 of file LocalisationCache.php.

◆ $pluralRuleTypes

LocalisationCache::$pluralRuleTypes = null
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 174 of file LocalisationCache.php.

◆ $preloadedKeys

LocalisationCache::$preloadedKeys = array( 'dateFormats', 'namespaceNames' )
static

Keys which are loaded automatically by initLanguage()

Definition at line 154 of file LocalisationCache.php.

◆ $recachedLangs

LocalisationCache::$recachedLangs = array()
private

An array where the keys are codes that have been recached by this instance.

Definition at line 99 of file LocalisationCache.php.

◆ $shallowFallbacks

LocalisationCache::$shallowFallbacks = array()
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 94 of file LocalisationCache.php.

◆ $splitKeys

LocalisationCache::$splitKeys = array( 'messages' )
static

Keys for items where the subitems are stored in the backend separately.

Definition at line 149 of file LocalisationCache.php.

◆ $store

LCStore LocalisationCache::$store
private

The persistent store object.

An instance of LCStore.

Definition at line 65 of file LocalisationCache.php.


The documentation for this class was generated from the following file:
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.