MediaWiki
REL1_22
|
Message cache Performs various MediaWiki namespace-related functions. More...
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. |
Message cache Performs various MediaWiki namespace-related functions.
Definition at line 52 of file MessageCache.php.
MessageCache::__construct | ( | $ | memCached, |
$ | useDB, | ||
$ | expiry | ||
) |
ObjectCache | $memCached | A cache instance. If none, fall back to CACHE_NONE. |
bool | $useDB | |
int | $expiry | Lifetime for cache. |
Definition at line 127 of file MessageCache.php.
Clear all stored messages.
Mainly used after a mass rebuild.
Definition at line 1057 of file MessageCache.php.
static MessageCache::destroyInstance | ( | ) | [static] |
Destroy the singleton instance.
Definition at line 118 of file MessageCache.php.
Referenced by NewParserTest\setupGlobals(), and NewParserTest\tearDown().
Definition at line 1046 of file MessageCache.php.
Definition at line 1050 of file MessageCache.php.
MessageCache::figureMessage | ( | $ | key | ) |
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.
string | $key | the message key |
bool | $useDB | If true, look for the message in the DB, false to use only the compiled l10n cache. |
bool | string | object | $langcode | Code of the language to get the message for.
|
bool | $isFullKey | specifies whether $key is a two part key "msg/lang". |
MWException | when given an invalid key |
Definition at line 691 of file MessageCache.php.
MessageCache::getAllMessageKeys | ( | $ | code | ) |
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.
string | $code | Language code |
Definition at line 1096 of file MessageCache.php.
MessageCache::getLocalCache | ( | $ | hash, |
$ | code | ||
) |
Try to load the cache from a local file.
string | $hash | the hash of contents, to check validity. |
Mixed | $code | Optional language code, see documenation of load(). |
Definition at line 157 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.
Language | $lang | Requested language |
string | $lckey | Lowercase key for the message |
string | $uckey | Uppercase key for the message |
bool | $useDB | Whether to use the database |
Definition at line 778 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.
string | $title | Message cache key with initial uppercase letter. |
string | $code | Code denoting the language to try. |
Definition at line 867 of file MessageCache.php.
Definition at line 989 of file MessageCache.php.
ParserOptions is lazy initialised.
Definition at line 142 of file MessageCache.php.
MessageCache::isCacheExpired | ( | $ | cache | ) | [protected] |
Is the given cache array expired due to time passing or a version change?
$cache |
Definition at line 574 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.
bool | String | $code | Language to which load messages |
MWException |
Definition at line 231 of file MessageCache.php.
MessageCache::loadFromDB | ( | $ | code | ) |
Loads cacheable messages from the database.
Messages bigger than $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded on-demand from the database later.
string | $code | Language code. |
Definition at line 426 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.
string | $key |
Definition at line 629 of file MessageCache.php.
MessageCache::parse | ( | $ | text, |
$ | title = null , |
||
$ | linestart = true , |
||
$ | interface = false , |
||
$ | language = null |
||
) |
string | $text | |
Title | $title | |
bool | $linestart | Whether or not this is at the start of a line |
bool | $interface | Whether this is an interface message |
string | $language | Language code |
Definition at line 1014 of file MessageCache.php.
MessageCache::replace | ( | $ | title, |
$ | text | ||
) |
Updates cache as necessary when message page is changed.
string | $title | Name of the page changed. |
mixed | $text | New contents of the page. |
Definition at line 511 of file MessageCache.php.
MessageCache::saveToCaches | ( | $ | cache, |
$ | dest, | ||
$ | code = false |
||
) | [protected] |
Shortcut to update caches.
array | $cache | Cached messages with a version. |
string | $dest | Either "local-only" to save to local caches only or "all" to save to all caches. |
string | bool | $code | Language code (default: false) |
Definition at line 596 of file MessageCache.php.
MessageCache::saveToLocal | ( | $ | serialized, |
$ | hash, | ||
$ | code | ||
) |
Save the cache to a local file.
Definition at line 189 of file MessageCache.php.
static MessageCache::singleton | ( | ) | [static] |
Get the signleton instance of this class.
Definition at line 101 of file MessageCache.php.
Referenced by Skin\addToSidebarPlain(), ApiQueryAllMessages\execute(), Title\getDefaultMessageText(), Status\getHTML(), ContentHandler\getPageLanguage(), RawAction\getRawText(), Title\hasSourceText(), MediaWikiLangTestCase\setUp(), MessageCacheTest\setUp(), MessageCacheTest\testFullKeyBehaviour(), MessageCacheTest\testMessageFallbacks(), wfEmptyMsg(), wfMsgExt(), wfMsgGetKey(), and wfMsgWikiHtml().
MessageCache::transform | ( | $ | message, |
$ | interface = false , |
||
$ | language = null , |
||
$ | title = null |
||
) |
Definition at line 961 of file MessageCache.php.
MessageCache::unlock | ( | $ | key | ) |
Definition at line 652 of file MessageCache.php.
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.
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.