LocalisationCache Class Reference

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

Inherited by LocalisationCache_BulkLoad.

List of all members.

Public Member Functions

 __construct ($conf)
 Constructor.
 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.
 getItem ($code, $key)
 Get a cache item.
 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.
 isExpired ($code)
 Returns true if the cache identified by $code is missing or expired.
 initShallowFallback ($primaryCode, $fallbackCode)
 Create a fallback from one language to another, without creating a complete persistent cache.
 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.
 addLegacyMessages ($messages)
 Add messages to the cache, from an extension that has not yet been migrated to $wgExtensionMessages or the LocalisationCacheRecache hook.
 disableBackend ()
 Disable the storage backend.

Public Attributes

 $conf
 Configuration associative array.
 $manualRecache = false
 True if recaching should only be done on an explicit call to recache().
 $forceRecache = false
 True to treat all files as expired until they are regenerated by this object.
 $data = array()
 The cache data.
 $store
 The persistent store object.
 $loadedItems = array()
 A 2-d associative array, code/key, where presence indicates that the item is loaded.
 $loadedSubitems = array()
 A 3-d associative array, code/key/subkey, where presence indicates that the subitem is loaded.
 $initialisedLangs = array()
 An array where presence of a key indicates that that language has been initialised.
 $shallowFallbacks = array()
 An array mapping non-existent pseudo-languages to fallback languages.
 $recachedLangs = array()
 An array where the keys are codes that have been recached by this instance.
 $legacyData = array()
 Data added by extensions using the deprecated $wgMessageCache->addMessages() interface.

Static Public Attributes

static $allKeys
 All item keys.
static $mergeableMapKeys
 Keys for items which consist of associative arrays, which may be merged by a fallback sequence.
static $mergeableListKeys = array( 'extraUserToggles' )
 Keys for items which are a numbered array.
static $mergeableAliasListKeys = array( 'specialPageAliases' )
 Keys for items which contain an array of arrays of equivalent aliases for each subitem.
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".
static $splitKeys = array( 'messages' )
 Keys for items where the subitems are stored in the backend separately.
static $preloadedKeys
 Keys which are loaded automatically by initLanguage().

Protected Member Functions

 loadItem ($code, $key)
 Load an item into the cache.
 loadSubitem ($code, $key, $subkey)
 Load a subitem into the cache.
 initLanguage ($code)
 Initialise a language in this object.
 readPHPFile ($_fileName, $_fileType)
 Read a PHP file containing localisation data.
 mergeItem ($key, &$value, $fallbackValue)
 Merge two localisation values, a primary and a fallback, overwriting the primary value in place.
 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.
 buildPreload ($data)
 Build the preload item from the given pre-cache 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.

Definition at line 17 of file LocalisationCache.php.


Constructor & Destructor Documentation

LocalisationCache::__construct ( conf  ) 

Constructor.

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

Definition at line 142 of file LocalisationCache.php.

References $conf, $wgCacheDirectory, and wfDebug().


Member Function Documentation

LocalisationCache::addLegacyMessages ( messages  ) 

Add messages to the cache, from an extension that has not yet been migrated to $wgExtensionMessages or the LocalisationCacheRecache hook.

Called by deprecated function $wgMessageCache->addMessages().

Definition at line 682 of file LocalisationCache.php.

References $messages.

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.

Definition at line 634 of file LocalisationCache.php.

References $data.

Referenced by recache().

LocalisationCache::disableBackend (  ) 

Disable the storage backend.

Definition at line 696 of file LocalisationCache.php.

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.

Reimplemented in LocalisationCache_BulkLoad.

Definition at line 202 of file LocalisationCache.php.

References $code, loadItem(), wfProfileIn(), and wfProfileOut().

Referenced by getSubitemList(), initLanguage(), and recache().

LocalisationCache::getSubitem ( code,
key,
subkey 
)

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

Reimplemented in LocalisationCache_BulkLoad.

Definition at line 217 of file LocalisationCache.php.

References $code, loadSubitem(), wfProfileIn(), and wfProfileOut().

Referenced by getSubitemList(), and loadItem().

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.

Definition at line 244 of file LocalisationCache.php.

References $code, getItem(), and getSubitem().

LocalisationCache::initLanguage ( code  )  [protected]

Initialise a language in this object.

Rebuild the cache if necessary.

Definition at line 343 of file LocalisationCache.php.

References $code, getItem(), Language::getMessagesFileName(), initShallowFallback(), isExpired(), and recache().

Referenced by loadItem(), and loadSubitem().

LocalisationCache::initShallowFallback ( primaryCode,
fallbackCode 
)

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

Definition at line 392 of file LocalisationCache.php.

Referenced by initLanguage().

LocalisationCache::isExpired ( code  ) 

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

Definition at line 315 of file LocalisationCache.php.

References $code, and wfDebug().

Referenced by initLanguage().

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.

Definition at line 184 of file LocalisationCache.php.

Referenced by recache().

LocalisationCache::loadItem ( code,
key 
) [protected]

Load an item into the cache.

Definition at line 260 of file LocalisationCache.php.

References $code, getSubitem(), and initLanguage().

Referenced by getItem(), and loadSubitem().

LocalisationCache::loadSubitem ( code,
key,
subkey 
) [protected]

Load a subitem into the cache.

Definition at line 289 of file LocalisationCache.php.

References $code, initLanguage(), and loadItem().

Referenced by getSubitem().

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.

Definition at line 453 of file LocalisationCache.php.

References $code, and mergeItem().

Referenced by recache().

LocalisationCache::mergeItem ( key,
&$  value,
fallbackValue 
) [protected]

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

Definition at line 422 of file LocalisationCache.php.

Referenced by mergeExtensionItem(), and recache().

LocalisationCache::readPHPFile ( _fileName,
_fileType 
) [protected]

Read a PHP file containing localisation data.

Reimplemented in LocalisationCache_BulkLoad.

Definition at line 402 of file LocalisationCache.php.

References $data.

Referenced by 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.

Reimplemented in LocalisationCache_BulkLoad.

Definition at line 468 of file LocalisationCache.php.

References $code, $data, $page, $wgExtensionAliasesFiles, $wgExtensionMessagesFiles, buildPreload(), getItem(), Language::getMessagesFileName(), isMergeableKey(), mergeExtensionItem(), mergeItem(), readPHPFile(), wfDebug(), wfProfileIn(), wfProfileOut(), and wfRunHooks().

Referenced by initLanguage().

LocalisationCache::unload ( code  ) 

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

Reduces memory usage.

Reimplemented in LocalisationCache_BulkLoad.

Definition at line 654 of file LocalisationCache.php.

References $code.

Referenced by unloadAll().

LocalisationCache::unloadAll (  ) 

Unload all data.

Definition at line 671 of file LocalisationCache.php.

References unload().


Member Data Documentation

LocalisationCache::$allKeys [static]

Initial value:

 array(
                'fallback', 'namespaceNames', 'mathNames', 'bookstoreList',
                'magicWords', 'messages', 'rtl', 'capitalizeAllNouns', 'digitTransformTable',
                'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
                'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
                'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
                'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
                'imageFiles', 'preloadedMessages',
        )
All item keys.

Definition at line 89 of file LocalisationCache.php.

LocalisationCache::$conf

Configuration associative array.

Definition at line 19 of file LocalisationCache.php.

Referenced by __construct().

LocalisationCache::$data = array()

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

Referenced by buildPreload(), LocalisationCache_BulkLoad::readPHPFile(), readPHPFile(), and recache().

LocalisationCache::$forceRecache = false

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

Definition at line 31 of file LocalisationCache.php.

LocalisationCache::$initialisedLangs = array()

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

LocalisationCache::$legacyData = array()

Data added by extensions using the deprecated $wgMessageCache->addMessages() interface.

Definition at line 84 of file LocalisationCache.php.

LocalisationCache::$loadedItems = array()

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

LocalisationCache::$loadedSubitems = array()

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

LocalisationCache::$manualRecache = false

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

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

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

Keys for items which are a numbered array.

Definition at line 111 of file LocalisationCache.php.

LocalisationCache::$mergeableMapKeys [static]

Initial value:

 array( 'messages', 'namespaceNames', 'mathNames',
                'dateFormats', 'defaultUserOptionOverrides', 'magicWords', 'imageFiles',
                'preloadedMessages',
        )
Keys for items which consist of associative arrays, which may be merged by a fallback sequence.

Definition at line 103 of file LocalisationCache.php.

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

LocalisationCache::$preloadedKeys [static]

Initial value:

 array( 'dateFormats', 'namespaceNames',
                'defaultUserOptionOverrides' )
Keys which are loaded automatically by initLanguage().

Definition at line 134 of file LocalisationCache.php.

LocalisationCache::$recachedLangs = array()

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

Definition at line 78 of file LocalisationCache.php.

LocalisationCache::$shallowFallbacks = array()

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

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

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

Definition at line 129 of file LocalisationCache.php.

LocalisationCache::$store

The persistent store object.

An instance of LCStore.

Definition at line 44 of file LocalisationCache.php.


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

Generated on Sat Apr 30 22:57:42 2011 for MediaWiki by  doxygen 1.5.9