BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
LocalisationCache Class Reference
Inheritance diagram for LocalisationCache:

Public Member Functions

 __construct ($conf)
 
 isMergeableKey ($key)
 
 getItem ($code, $key)
 
 getSubitem ($code, $key, $subkey)
 
 getSubitemList ($code, $key)
 
 isExpired ($code)
 
 initShallowFallback ($primaryCode, $fallbackCode)
 
 readJSONFile ($fileName)
 
 getCompiledPluralRules ($code)
 
 getPluralRules ($code)
 
 getPluralRuleTypes ($code)
 
 getMessagesDirs ()
 
 recache ($code)
 
 unload ($code)
 
 unloadAll ()
 
 disableBackend ()
 

Public Attributes

const VERSION = 4
 

Static Public Attributes

static $allKeys
 
static $mergeableMapKeys
 
static $mergeableListKeys = [ 'extraUserToggles' ]
 
static $mergeableAliasListKeys = [ 'specialPageAliases' ]
 
static $optionalMergeKeys = [ 'bookstoreList' ]
 
static $magicWordKeys = [ 'magicWords' ]
 
static $splitKeys = [ 'messages' ]
 
static $preloadedKeys = [ 'dateFormats', 'namespaceNames' ]
 

Protected Member Functions

 loadItem ($code, $key)
 
 loadSubitem ($code, $key, $subkey)
 
 initLanguage ($code)
 
 readPHPFile ($_fileName, $_fileType)
 
 loadPluralFiles ()
 
 loadPluralFile ($fileName)
 
 readSourceFilesAndRegisterDeps ($code, &$deps)
 
 mergeItem ($key, &$value, $fallbackValue)
 
 mergeMagicWords (&$value, $fallbackValue)
 
 mergeExtensionItem ($codeSequence, $key, &$value, $fallbackValue)
 
 buildPreload ($data)
 

Protected Attributes

 $data = []
 

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.

Constructor & Destructor Documentation

LocalisationCache::__construct (   $conf)

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

Parameters
array$conf
Exceptions
MWException

Member Function Documentation

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
array$data
Returns
array
LocalisationCache::disableBackend ( )

Disable the storage backend

LocalisationCache::getCompiledPluralRules (   $code)

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

Since
1.20
Parameters
string$code
Returns
array|null
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
string$code
string$key
Returns
mixed
LocalisationCache::getMessagesDirs ( )

Gets the combined list of messages dirs from core and extensions

Since
1.25
Returns
array
LocalisationCache::getPluralRules (   $code)

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

Since
1.20
Parameters
string$code
Returns
array|null
LocalisationCache::getPluralRuleTypes (   $code)

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

Since
1.22
Parameters
string$code
Returns
array|null
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
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
string$code
string$key
Returns
bool|null|string
LocalisationCache::initLanguage (   $code)
protected

Initialise a language in this object. Rebuild the cache if necessary.

Parameters
string$code
Exceptions
MWException
LocalisationCache::initShallowFallback (   $primaryCode,
  $fallbackCode 
)

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

Parameters
string$primaryCode
string$fallbackCode
LocalisationCache::isExpired (   $code)

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

Parameters
string$code
Returns
bool
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
string$key
Returns
bool
LocalisationCache::loadItem (   $code,
  $key 
)
protected

Load an item into the cache.

Parameters
string$code
string$key
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.

Parameters
string$fileName
Exceptions
MWException
LocalisationCache::loadPluralFiles ( )
protected

Load the plural XML files.

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

Load a subitem into the cache

Parameters
string$code
string$key
string$subkey
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
array$codeSequence
string$key
mixed$value
mixed$fallbackValue
Returns
bool
LocalisationCache::mergeItem (   $key,
$value,
  $fallbackValue 
)
protected

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

Parameters
string$key
mixed$value
mixed$fallbackValue
LocalisationCache::mergeMagicWords ( $value,
  $fallbackValue 
)
protected
Parameters
mixed$value
mixed$fallbackValue
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 Array with a 'messages' key, or empty array if the file doesn't exist
LocalisationCache::readPHPFile (   $_fileName,
  $_fileType 
)
protected

Read a PHP file containing localisation data.

Parameters
string$_fileName
string$_fileType
Exceptions
MWException
Returns
array
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.

Parameters
string$code
array$deps
Returns
array
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
Exceptions
MWException
LocalisationCache::unload (   $code)

Unload the data for a given language from the object cache. Reduces memory usage.

Parameters
string$code
LocalisationCache::unloadAll ( )

Unload all data

Member Data Documentation

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

LocalisationCache::$data = []
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.

LocalisationCache::$magicWordKeys = [ 'magicWords' ]
static

Keys for items that are formatted like $magicWords

LocalisationCache::$mergeableAliasListKeys = [ '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.

LocalisationCache::$mergeableListKeys = [ 'extraUserToggles' ]
static

Keys for items which are a numbered array.

LocalisationCache::$mergeableMapKeys
static
Initial value:
= [ 'messages', 'namespaceNames',
'namespaceAliases', 'dateFormats', 'imageFiles', 'preloadedMessages'
]

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

LocalisationCache::$optionalMergeKeys = [ '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.

LocalisationCache::$preloadedKeys = [ 'dateFormats', 'namespaceNames' ]
static

Keys which are loaded automatically by initLanguage()

LocalisationCache::$splitKeys = [ 'messages' ]
static

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


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