MediaWiki
1.23.0
|
Message cache Performs various MediaWiki namespace-related functions. More...
Public Member Functions | |
__construct ( $memCached, $useDB, $expiry) | |
clear () | |
Clear all stored messages. More... | |
disable () | |
enable () | |
figureMessage ( $key) | |
get ( $key, $useDB=true, $langcode=true, $isFullKey=false) | |
Get a message from either the content language or the user language. More... | |
getAllMessageKeys ( $code) | |
Get all message keys stored in the message cache for a given language. More... | |
getLocalCache ( $hash, $code) | |
Try to load the cache from a local file. More... | |
getMsgFromNamespace ( $title, $code) | |
Get a message from the MediaWiki namespace, with caching. More... | |
getParser () | |
getParserOptions () | |
ParserOptions is lazy initialised. More... | |
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. More... | |
loadFromDB ( $code) | |
Loads cacheable messages from the database. More... | |
lock ( $key) | |
Represents a write lock on the messages key. More... | |
parse ( $text, $title=null, $linestart=true, $interface=false, $language=null) | |
replace ( $title, $text) | |
Updates cache as necessary when message page is changed. More... | |
saveToLocal ( $serialized, $hash, $code) | |
Save the cache to a local file. More... | |
transform ( $message, $interface=false, $language=null, $title=null) | |
unlock ( $key) | |
Static Public Member Functions | |
static | destroyInstance () |
Destroy the singleton instance. More... | |
static | singleton () |
Get the signleton instance of this class. More... | |
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. More... | |
isCacheExpired ( $cache) | |
Is the given cache array expired due to time passing or a version change? More... | |
saveToCaches ( $cache, $dest, $code=false) | |
Shortcut to update caches. More... | |
Protected Attributes | |
$mCache | |
Process local cache of loaded messages that are defined in MediaWiki namespace. More... | |
bool | $mDisable |
Should mean that database cannot be used, but check $mDisable. More... | |
$mExpiry | |
Lifetime for cache, used by object caching. More... | |
bool | $mInParser = false |
$mInParser More... | |
array | $mLoadedLanguages = array() |
Variable for tracking which variables are already loaded $mLoadedLanguages. More... | |
$mParserOptions | |
Message cache has it's own parser which it uses to transform messages. More... | |
Static Private Attributes | |
static | $instance |
Singleton instance. More... | |
Message cache Performs various MediaWiki namespace-related functions.
Definition at line 52 of file MessageCache.php.
MessageCache::__construct | ( | $memCached, | |
$useDB, | |||
$expiry | |||
) |
BagOStuff | $memCached | A cache instance. If none, fall back to CACHE_NONE. |
bool | $useDB | |
int | $expiry | Lifetime for cache. |
Definition at line 128 of file MessageCache.php.
References CACHE_NONE, and wfGetCache().
MessageCache::clear | ( | ) |
Clear all stored messages.
Mainly used after a mass rebuild.
Definition at line 1086 of file MessageCache.php.
References array(), as, Language\fetchLanguageNames(), and wfMemcKey().
|
static |
MessageCache::disable | ( | ) |
Definition at line 1075 of file MessageCache.php.
MessageCache::enable | ( | ) |
Definition at line 1079 of file MessageCache.php.
MessageCache::figureMessage | ( | $key | ) |
$key |
Definition at line 1101 of file MessageCache.php.
References array(), Language\fetchLanguageName(), and global.
Referenced by replace().
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):
This process provides a number of guarantees. When changing this code, make sure all of these guarantees are preserved.
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 703 of file MessageCache.php.
References $section, $wgContLang, array(), Language\getMessageFor(), getMessageFromFallbackChain(), global, wfGetLangObj(), and wfRunHooks().
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 1126 of file MessageCache.php.
References $cache, $wgContLang, array(), global, and load().
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 159 of file MessageCache.php.
References $file, $hash, $serialized, global, wfRestoreWarnings(), wfSuppressWarnings(), and wfWikiID().
Referenced by load().
|
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 801 of file MessageCache.php.
References $wgContLang, as, Language\getFallbacksIncludingSiteLanguage(), getMsgFromNamespace(), global, and list.
Referenced by get().
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 891 of file MessageCache.php.
References $title, array(), load(), Title\makeTitle(), Revision\newFromTitle(), NS_MEDIAWIKI, IDBAccessObject\READ_LATEST, wfDebugLog(), wfMemcKey(), and wfRunHooks().
Referenced by getMessageFromFallbackChain().
MessageCache::getParser | ( | ) |
Definition at line 1016 of file MessageCache.php.
References $mParser, $wgParser, and global.
Referenced by parse(), and transform().
MessageCache::getParserOptions | ( | ) |
ParserOptions is lazy initialised.
Definition at line 143 of file MessageCache.php.
References $mParserOptions, and ParserOptions\setEditSection().
Referenced by parse(), and transform().
|
protected |
Is the given cache array expired due to time passing or a version change?
$cache |
Definition at line 583 of file MessageCache.php.
References $cache, MSG_CACHE_VERSION, and wfTimestampNow().
Referenced by load().
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 236 of file MessageCache.php.
References $cache, $hash, $success, array(), cache, ScopedCallback\consume(), data, getLocalCache(), global, in, isCacheExpired(), loadFromDB(), lock(), messages, MSG_LOAD_TIMEOUT, of, saveToCaches(), too, unlock(), wfDebug(), wfMemcKey(), wfProfileIn(), and wfProfileOut().
Referenced by getAllMessageKeys(), getMsgFromNamespace(), loadFromDB(), and replace().
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 433 of file MessageCache.php.
References $cache, $dbr, $res, $value, array(), as, DB_SLAVE, Revision\getRevisionText(), global, load(), MSG_CACHE_VERSION, NS_MEDIAWIKI, TS_MW, wfDebugLog(), wfGetDB(), wfProfileIn(), wfProfileOut(), and wfTimestamp().
Referenced by load().
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 640 of file MessageCache.php.
References MSG_LOCK_TIMEOUT, MSG_WAIT_TIMEOUT, and wfMemcKey().
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 1042 of file MessageCache.php.
References $parser, $res, $title, $wgTitle, getParser(), getParserOptions(), global, Title\newFromText(), wfProfileIn(), and wfProfileOut().
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 519 of file MessageCache.php.
References $title, $wgContLang, $wgMemc, array(), as, Language\fetchLanguageNames(), figureMessage(), global, list, load(), lock(), saveToCaches(), unlock(), MessageBlobStore\updateMessage(), wfMemcKey(), wfProfileIn(), wfProfileOut(), and wfRunHooks().
|
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 606 of file MessageCache.php.
References $cache, $hash, $serialized, $success, global, saveToLocal(), wfMemcKey(), wfProfileIn(), and wfProfileOut().
MessageCache::saveToLocal | ( | $serialized, | |
$hash, | |||
$code | |||
) |
Save the cache to a local file.
Definition at line 193 of file MessageCache.php.
References $file, $hash, $serialized, global, wfDebug(), wfMkdirParents(), wfRestoreWarnings(), wfSuppressWarnings(), and wfWikiID().
Referenced by saveToCaches().
|
static |
Get the signleton instance of this class.
Definition at line 101 of file MessageCache.php.
References $instance, global, and wfGetMessageCacheStorage().
Referenced by Skin\addToSidebarPlain(), EmailNotification\composeCommonMailtext(), WikiPage\doEditUpdates(), WikiPage\doPurge(), ApiQueryAllMessages\execute(), Title\getDefaultMessageText(), DBConnectionError\getHTML(), Status\getHTML(), ContentHandler\getPageLanguage(), RawAction\getRawText(), Title\hasSourceText(), SideBarTest\initMessagesHref(), WikiPage\onArticleDelete(), MediaWikiLangTestCase\setUp(), MessageCacheTest\setUp(), MessageCacheTest\testFullKeyBehaviour(), and MessageCacheTest\testMessageFallbacks().
MessageCache::transform | ( | $message, | |
$interface = false , |
|||
$language = null , |
|||
$title = null |
|||
) |
Definition at line 987 of file MessageCache.php.
References $parser, $title, getParser(), and getParserOptions().
MessageCache::unlock | ( | $key | ) |
Definition at line 663 of file MessageCache.php.
|
staticprivate |
|
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.
|
protected |
Should mean that database cannot be used, but check $mDisable.
Definition at line 65 of file MessageCache.php.
|
protected |
Lifetime for cache, used by object caching.
Set on construction, see __construct().
Definition at line 71 of file MessageCache.php.
|
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.
Referenced by getParser().
|
protected |
Message cache has it's own parser which it uses to transform messages.
Definition at line 77 of file MessageCache.php.
Referenced by getParserOptions().