MediaWiki  REL1_24
MessageCache Class Reference

Message cache Performs various MediaWiki namespace-related functions. More...

Collaboration diagram for MessageCache:

List of all members.

Public Member Functions

 __construct ($memCached, $useDB, $expiry)
 clear ()
 Clear all stored messages.
 disable ()
 enable ()
 figureMessage ($key)
 get ($key, $useDB=true, $langcode=true, $isFullKey=false)
 Get a message from either the content language or the user language.
 getAllMessageKeys ($code)
 Get all message keys stored in the message cache for a given language.
 getLocalCache ($hash, $code)
 Try to load the cache from a local file.
 getMsgFromNamespace ($title, $code)
 Get a message from the MediaWiki namespace, with caching.
 getParser ()
 getParserOptions ()
 ParserOptions is lazy initialised.
 load ($code=false)
 Loads messages from caches or from database in this order: (1) local message cache (if $wgUseLocalMessageCache is enabled) (2) memcached (3) from the database.
 loadFromDB ($code)
 Loads cacheable messages from the database.
 lock ($key)
 Represents a write lock on the messages key.
 parse ($text, $title=null, $linestart=true, $interface=false, $language=null)
 replace ($title, $text)
 Updates cache as necessary when message page is changed.
 saveToLocal ($serialized, $hash, $code)
 Save the cache to a local file.
 transform ($message, $interface=false, $language=null, $title=null)
 unlock ($key)

Static Public Member Functions

static destroyInstance ()
 Destroy the singleton instance.
static singleton ()
 Get the signleton instance of this class.

Public Attributes

 $mParser

Protected Member Functions

 getMessageFromFallbackChain ($lang, $lckey, $uckey, $useDB)
 Given a language, try and fetch a message from that language, then the fallbacks of that language, then the site language, then the fallbacks for the site language.
 isCacheExpired ($cache)
 Is the given cache array expired due to time passing or a version change?
 saveToCaches ($cache, $dest, $code=false)
 Shortcut to update caches.

Protected Attributes

 $mCache
 Process local cache of loaded messages that are defined in MediaWiki namespace.
bool $mDisable
 Should mean that database cannot be used, but check $mDisable.
 $mExpiry
 Lifetime for cache, used by object caching.
bool $mInParser = false
 $mInParser
array $mLoadedLanguages = array()
 Variable for tracking which variables are already loaded $mLoadedLanguages.
 $mParserOptions
 Message cache has it's own parser which it uses to transform messages.

Static Private Attributes

static $instance
 Singleton instance.

Detailed Description

Message cache Performs various MediaWiki namespace-related functions.

Definition at line 52 of file MessageCache.php.


Constructor & Destructor Documentation

MessageCache::__construct ( memCached,
useDB,
expiry 
)
Parameters:
BagOStuff$memCachedA cache instance. If none, fall back to CACHE_NONE.
bool$useDB
int$expiryLifetime for cache.
See also:
$mExpiry.

Definition at line 128 of file MessageCache.php.


Member Function Documentation

Clear all stored messages.

Mainly used after a mass rebuild.

Definition at line 1088 of file MessageCache.php.

static MessageCache::destroyInstance ( ) [static]

Destroy the singleton instance.

Since:
1.18

Definition at line 119 of file MessageCache.php.

Referenced by NewParserTest\tearDown().

Definition at line 1077 of file MessageCache.php.

Definition at line 1081 of file MessageCache.php.

Parameters:
string$key
Returns:
array

Definition at line 1103 of file MessageCache.php.

static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place change it to the message you want to define MessageCache::get ( key,
useDB = true,
langcode = true,
isFullKey = false 
)

Get a message from either the content language or the user language.

First, assemble a list of languages to attempt getting the message from. This chain begins with the requested language and its fallbacks and then continues with the content language and its fallbacks. For each language in the chain, the following process will occur (in this order): 1. If a language-specific override, i.e., [[MW:msg/lang]], is available, use that. Note: for the content language, there is no /lang subpage. 2. Fetch from the static CDB cache. 3. If available, check the database for fallback language overrides.

This process provides a number of guarantees. When changing this code, make sure all of these guarantees are preserved. * If the requested language is *not* the content language, then the CDB cache for that specific language will take precedence over the root database page ([[MW:msg]]). * Fallbacks will be just that: fallbacks. A fallback language will never be reached if the message is available *anywhere* in the language for which it is a fallback.

Parameters:
string$keyThe message key
bool$useDBIf true, look for the message in the DB, false to use only the compiled l10n cache.
bool | string | object$langcodeCode of the language to get the message for.
  • If string and a valid code, will create a standard language object
  • If string but not a valid code, will create a basic language object
  • If boolean and false, create object from the current users language
  • If boolean and true, create object from the wikis content language
  • If language object, use it as given
bool$isFullKeySpecifies whether $key is a two part key "msg/lang".
Exceptions:
MWExceptionWhen given an invalid key
Returns:
string|bool False if the message doesn't exist, otherwise the message (which can be empty)

Definition at line 705 of file MessageCache.php.

Get all message keys stored in the message cache for a given language.

If $code is the content language code, this will return all message keys for which MediaWiki:msgkey exists. If $code is another language code, this will ONLY return message keys for which MediaWiki:msgkey/$code exists.

Parameters:
string$codeLanguage code
Returns:
array Array of message keys (strings)

Definition at line 1128 of file MessageCache.php.

MessageCache::getLocalCache ( hash,
code 
)

Try to load the cache from a local file.

Parameters:
string$hashThe hash of contents, to check validity.
string$codeOptional language code, see documenation of load().
Returns:
array The cache array

Definition at line 159 of file MessageCache.php.

MessageCache::getMessageFromFallbackChain ( lang,
lckey,
uckey,
useDB 
) [protected]

Given a language, try and fetch a message from that language, then the fallbacks of that language, then the site language, then the fallbacks for the site language.

Parameters:
Language$langRequested language
string$lckeyLowercase key for the message
string$uckeyUppercase key for the message
bool$useDBWhether to use the database
See also:
MessageCache::get
Returns:
string|bool The message, or false if not found

Definition at line 803 of file MessageCache.php.

MessageCache::getMsgFromNamespace ( title,
code 
)

Get a message from the MediaWiki namespace, with caching.

The key must first be converted to two-part lang/msg form if necessary.

Unlike self::get(), this function doesn't resolve fallback chains, and some callers require this behavior. LanguageConverter::parseCachedTable() and self::get() are some examples in core.

Parameters:
string$titleMessage cache key with initial uppercase letter.
string$codeCode denoting the language to try.
Returns:
string|bool The message, or false if it does not exist or on error

Definition at line 893 of file MessageCache.php.

Returns:
Parser

Definition at line 1018 of file MessageCache.php.

ParserOptions is lazy initialised.

Returns:
ParserOptions

Definition at line 143 of file MessageCache.php.

MessageCache::isCacheExpired ( cache) [protected]

Is the given cache array expired due to time passing or a version change?

Parameters:
array$cache
Returns:
bool

Definition at line 586 of file MessageCache.php.

MessageCache::load ( code = false)

Loads messages from caches or from database in this order: (1) local message cache (if $wgUseLocalMessageCache is enabled) (2) memcached (3) from the database.

When succesfully loading from (2) or (3), all higher level caches are updated for the newest version.

Nothing is loaded if member variable mDisable is true, either manually set by calling code or if message loading fails (is this possible?).

Returns true if cache is already populated or it was succesfully populated, or false if populating empty cache fails. Also returns true if MessageCache is disabled.

Parameters:
bool | string$codeLanguage to which load messages
Exceptions:
MWException
Returns:
bool

Definition at line 239 of file MessageCache.php.

Loads cacheable messages from the database.

Messages bigger than $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded on-demand from the database later.

Parameters:
string$codeLanguage code.
Returns:
array Loaded messages for storing in caches.

Definition at line 436 of file MessageCache.php.

MessageCache::lock ( key)

Represents a write lock on the messages key.

Will retry MessageCache::MSG_WAIT_TIMEOUT times, each operations having a timeout of MessageCache::MSG_LOCK_TIMEOUT.

Parameters:
string$key
Returns:
bool Success

Definition at line 643 of file MessageCache.php.

MessageCache::parse ( text,
title = null,
linestart = true,
interface = false,
language = null 
)
Parameters:
string$text
Title$title
bool$linestartWhether or not this is at the start of a line
bool$interfaceWhether this is an interface message
string$languageLanguage code
Returns:
ParserOutput|string

Definition at line 1044 of file MessageCache.php.

MessageCache::replace ( title,
text 
)

Updates cache as necessary when message page is changed.

Parameters:
string$titleName of the page changed.
mixed$textNew contents of the page.

Definition at line 522 of file MessageCache.php.

MessageCache::saveToCaches ( cache,
dest,
code = false 
) [protected]

Shortcut to update caches.

Parameters:
array$cacheCached messages with a version.
string$destEither "local-only" to save to local caches only or "all" to save to all caches.
string | bool$codeLanguage code (default: false)
Returns:
bool

Definition at line 609 of file MessageCache.php.

MessageCache::saveToLocal ( serialized,
hash,
code 
)

Save the cache to a local file.

Parameters:
string$serialized
string$hash
string$code

Definition at line 196 of file MessageCache.php.

MessageCache::transform ( message,
interface = false,
language = null,
title = null 
)
Parameters:
string$message
bool$interface
string$languageLanguage code
Title$title
Returns:
string

Definition at line 989 of file MessageCache.php.

Definition at line 666 of file MessageCache.php.


Member Data Documentation

MessageCache MessageCache::$instance [static, private]

Singleton instance.

Definition at line 89 of file MessageCache.php.

MessageCache::$mCache [protected]

Process local cache of loaded messages that are defined in MediaWiki namespace.

First array level is a language code, second level is message key and the values are either message content prefixed with space, or !NONEXISTENT for negative caching.

Definition at line 60 of file MessageCache.php.

bool MessageCache::$mDisable [protected]

Should mean that database cannot be used, but check $mDisable.

Definition at line 65 of file MessageCache.php.

MessageCache::$mExpiry [protected]

Lifetime for cache, used by object caching.

Set on construction, see __construct().

Definition at line 71 of file MessageCache.php.

bool MessageCache::$mInParser = false [protected]

$mInParser

Definition at line 93 of file MessageCache.php.

array MessageCache::$mLoadedLanguages = array() [protected]

Variable for tracking which variables are already loaded $mLoadedLanguages.

Definition at line 82 of file MessageCache.php.

MessageCache::$mParser

Definition at line 77 of file MessageCache.php.

MessageCache::$mParserOptions [protected]

Message cache has it's own parser which it uses to transform messages.

Definition at line 77 of file MessageCache.php.


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