MediaWiki REL1_30
|
Message cache Performs various MediaWiki namespace-related functions. More...
Public Member Functions | |
__construct (WANObjectCache $wanCache, BagOStuff $clusterCache, BagOStuff $srvCache, $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. | |
getMsgFromNamespace ( $title, $code) | |
Get a message from the MediaWiki namespace, with caching. | |
getParser () | |
getParserOptions () | |
ParserOptions is lazy initialised. | |
isDisabled () | |
Whether DB/cache usage is disabled for determining messages. | |
parse ( $text, $title=null, $linestart=true, $interface=false, $language=null) | |
replace ( $title, $text) | |
Updates cache as necessary when message page is changed. | |
transform ( $message, $interface=false, $language=null, $title=null) | |
updateMessageOverride (Title $title, Content $content=null) | |
Purge message caches when a MediaWiki: page is created, updated, or deleted. | |
Static Public Member Functions | |
static | destroyInstance () |
Destroy the singleton instance. | |
static | normalizeKey ( $key) |
Normalize message key input. | |
static | singleton () |
Get the signleton instance of this class. | |
Public Attributes | |
const | FOR_UPDATE = 1 |
const | LOCK_TTL = 30 |
How long memcached locks last. | |
const | WAIT_SEC = 15 |
How long to wait for memcached locks. | |
Protected Member Functions | |
getLocalCache ( $code) | |
Try to load the cache from APC. | |
getMessageFromFallbackChain ( $lang, $lckey, $useDB) | |
Given a language, try and fetch messages from that language. | |
getReentrantScopedLock ( $key, $timeout=self::WAIT_SEC) | |
getValidationHash ( $code) | |
Get the md5 used to validate the local APC cache. | |
isCacheExpired ( $cache) | |
Is the given cache array expired due to time passing or a version change? | |
load ( $code, $mode=null) | |
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, $mode=null) | |
Loads cacheable messages from the database. | |
loadFromDBWithLock ( $code, array &$where, $mode=null) | |
saveToCaches (array $cache, $dest, $code=false) | |
Shortcut to update caches. | |
saveToLocalCache ( $code, $cache) | |
Save the cache to APC. | |
setValidationHash ( $code, array $cache) | |
Set the md5 used to validate the local disk cache. | |
Protected Attributes | |
BagOStuff | $clusterCache |
$mCache | |
Process local cache of loaded messages that are defined in MediaWiki namespace. | |
bool[] | $mCacheVolatile = [] |
Map of (language code => boolean) | |
$mDisable | |
Should mean that database cannot be used, but check. | |
$mExpiry | |
Lifetime for cache, used by object caching. | |
$mInParser = false | |
$mLoadedLanguages = [] | |
Variable for tracking which variables are already loaded. | |
Parser | $mParser |
ParserOptions | $mParserOptions |
Message cache has its own parser which it uses to transform messages. | |
BagOStuff | $srvCache |
WANObjectCache | $wanCache |
Private Member Functions | |
bigMessageCacheKey ( $hash, $title) | |
getMessageForLang ( $lang, $lckey, $useDB, &$alreadyTried) | |
Given a language, try and fetch messages from that language and its fallbacks. | |
getMessagePageName ( $langcode, $uckey) | |
Get the message page name for a given language. | |
getMessageTextFromContent (Content $content=null) | |
Static Private Attributes | |
static | $instance |
Singleton instance. | |
Message cache Performs various MediaWiki namespace-related functions.
Definition at line 39 of file MessageCache.php.
MessageCache::__construct | ( | WANObjectCache | $wanCache, |
BagOStuff | $clusterCache, | ||
BagOStuff | $srvCache, | ||
$useDB, | |||
$expiry ) |
WANObjectCache | $wanCache | WAN cache instance |
BagOStuff | $clusterCache | Cluster cache instance |
BagOStuff | $srvCache | Server cache instance |
bool | $useDB | Whether to look for message overrides (e.g. MediaWiki: pages) |
int | $expiry | Lifetime for cache. |
Definition at line 165 of file MessageCache.php.
References $clusterCache, $srvCache, and $wanCache.
|
private |
string | $hash | Hash for this version of the entire key/value overrides map |
string | $title | Message cache key with initial uppercase letter |
Definition at line 1328 of file MessageCache.php.
Referenced by getMsgFromNamespace(), and replace().
MessageCache::clear | ( | ) |
Clear all stored messages.
Mainly used after a mass rebuild.
Definition at line 1213 of file MessageCache.php.
References $code.
|
static |
Destroy the singleton instance.
Definition at line 135 of file MessageCache.php.
Referenced by ParserTestRunner\staticSetup(), and MessageTest\testRawHtmlInMsg().
MessageCache::disable | ( | ) |
Definition at line 1186 of file MessageCache.php.
MessageCache::enable | ( | ) |
Definition at line 1190 of file MessageCache.php.
MessageCache::figureMessage | ( | $key | ) |
string | $key |
Definition at line 1227 of file MessageCache.php.
References $lang, and $wgLanguageCode.
Referenced by replace().
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 799 of file MessageCache.php.
References $lang, getMessageFromFallbackChain(), normalizeKey(), string, and wfGetLangObj().
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 1253 of file MessageCache.php.
References $cache, $code, $wgContLang, and load.
|
protected |
Try to load the cache from APC.
string | $code | Optional language code, see documenation of load(). |
Definition at line 222 of file MessageCache.php.
References $code.
Referenced by load().
|
private |
Given a language, try and fetch messages from that language and its fallbacks.
Language | StubObject | $lang | Preferred language |
string | $lckey | Lowercase key for the message (as for localisation cache) |
bool | $useDB | Whether to include messages from the wiki database |
bool[] | $alreadyTried | Contains true for each language that has been tried already |
Definition at line 908 of file MessageCache.php.
References $code, $lang, $wgContLang, getMessagePageName(), and getMsgFromNamespace().
Referenced by getMessageFromFallbackChain().
|
protected |
Given a language, try and fetch messages from that language.
Will also consider fallbacks of that language, the site language, and fallbacks for the site language.
Language | StubObject | $lang | Preferred language |
string | $lckey | Lowercase key for the message (as for localisation cache) |
bool | $useDB | Whether to include messages from the wiki database |
Definition at line 882 of file MessageCache.php.
References $lang, $wgContLang, and getMessageForLang().
Referenced by get().
|
private |
Get the message page name for a given language.
string | $langcode | |
string | $uckey | Uppercase key for the message |
Definition at line 967 of file MessageCache.php.
References $wgLanguageCode.
Referenced by getMessageForLang().
|
private |
Definition at line 1299 of file MessageCache.php.
Referenced by getMsgFromNamespace(), replace(), and updateMessageOverride().
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 990 of file MessageCache.php.
References $code, $dbr, $title, bigMessageCacheKey(), DB_REPLICA, getMessageTextFromContent(), load, Revision\newKnownCurrent(), and wfGetDB().
Referenced by getMessageForLang().
MessageCache::getParser | ( | ) |
Definition at line 1122 of file MessageCache.php.
References $mParser, $wgParser, and $wgParserConf.
Referenced by parse(), and transform().
MessageCache::getParserOptions | ( | ) |
ParserOptions is lazy initialised.
Definition at line 185 of file MessageCache.php.
References $mParserOptions, $wgUser, and ParserOptions\setEditSection().
Referenced by parse(), and transform().
|
protected |
string | $key | A language message cache key that stores blobs |
int | $timeout | Wait timeout in seconds |
Definition at line 761 of file MessageCache.php.
Referenced by load(), loadFromDBWithLock(), and replace().
|
protected |
Get the md5 used to validate the local APC cache.
string | $code |
Definition at line 707 of file MessageCache.php.
Referenced by load().
|
protected |
Is the given cache array expired due to time passing or a version change?
array | $cache |
Definition at line 664 of file MessageCache.php.
References $cache, MSG_CACHE_VERSION, and wfTimestampNow().
Referenced by load().
MessageCache::isDisabled | ( | ) |
Whether DB/cache usage is disabled for determining messages.
If so, this typically indicates either:
Definition at line 1206 of file MessageCache.php.
References $mDisable.
|
protected |
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.
string | $code | Language to which load messages |
int | $mode | Use MessageCache::FOR_UPDATE to skip process cache [optional] |
MWException |
Definition at line 260 of file MessageCache.php.
References $cache, $code, $success, cache, data, getLocalCache(), getReentrantScopedLock(), getValidationHash(), isCacheExpired(), list, loadFromDBWithLock(), saveToCaches(), wfDebug(), and wfDebugLog().
|
protected |
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 |
int | $mode | Use MessageCache::FOR_UPDATE to skip process cache |
Definition at line 464 of file MessageCache.php.
References $cache, $code, $dbr, $res, $value, $wgAdaptiveMessageCache, $wgLanguageCode, $wgMaxMsgCacheEntrySize, DB_MASTER, DB_REPLICA, Revision\getRevisionText(), load, MSG_CACHE_VERSION, NS_MEDIAWIKI, serialize(), wfDebugLog(), wfGetDB(), and wfTimestamp().
Referenced by loadFromDBWithLock(), and replace().
|
protected |
string | $code | |
array | &$where | List of wfDebug() comments |
int | $mode | Use MessageCache::FOR_UPDATE to use DB_MASTER |
Definition at line 402 of file MessageCache.php.
References $cache, $code, getReentrantScopedLock(), loadFromDB(), and saveToCaches().
Referenced by load().
|
static |
Normalize message key input.
string | $key | Input message key to be normalized |
Definition at line 145 of file MessageCache.php.
References $wgContLang.
Referenced by ApiQueryAllMessages\execute(), get(), and MessageCacheTest\testNormalizeKey().
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 |
Language | string | $language | Language code |
Definition at line 1149 of file MessageCache.php.
References $parser, $res, $wgTitle, getParser(), getParserOptions(), NS_SPECIAL, wfDebugLog(), and wfGetAllCallers().
MessageCache::replace | ( | $title, | |
$text ) |
Updates cache as necessary when message page is changed.
string | $title | Message cache key with initial uppercase letter |
string | bool | $text | New contents of the page (false if deleted) |
Definition at line 572 of file MessageCache.php.
References $cache, $code, $title, $wgContLang, $wgLanguageCode, $wgMaxMsgCacheEntrySize, bigMessageCacheKey(), WikiPage\factory(), figureMessage(), RequestContext\getMain(), getMessageTextFromContent(), getReentrantScopedLock(), list, loadFromDB(), and saveToCaches().
|
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 687 of file MessageCache.php.
References $cache, $code, $success, saveToLocalCache(), and setValidationHash().
Referenced by load(), loadFromDBWithLock(), and replace().
|
protected |
Save the cache to APC.
string | $code | |
array | $cache | The cache array |
Definition at line 234 of file MessageCache.php.
Referenced by saveToCaches().
|
protected |
Set the md5 used to validate the local disk cache.
If $cache has a 'LATEST' UNIX timestamp key, then the hash will not be treated as "volatile" by getValidationHash() for the next few seconds. This is triggered when $cache is generated using FOR_UPDATE mode.
string | $code | |
array | $cache | Cached messages with a version |
Definition at line 745 of file MessageCache.php.
Referenced by saveToCaches().
|
static |
Get the signleton instance of this class.
Definition at line 113 of file MessageCache.php.
References $instance, $wgMsgCacheExpiry, $wgUseDatabaseMessages, $wgUseLocalMessageCache, and wfGetMessageCacheStorage().
Referenced by ParserTestRunner\addArticle(), Skin\addToSidebarPlain(), Skin\buildSidebar(), EmailNotification\composeCommonMailtext(), WikiPage\doEditUpdates(), WikiPage\doPurge(), ApiQueryAllMessages\execute(), Message\fetchMessage(), Title\getDefaultMessageText(), Status\getHTML(), ContentHandler\getPageLanguage(), RawAction\getRawText(), Title\hasSourceText(), SideBarTest\initMessagesHref(), WikiPage\onArticleDelete(), LanguageConverter\parseCachedTable(), Message\parseText(), MediaWiki\preOutputCommit(), MWExceptionRenderer\reportOutageHTML(), SpecialRecentChanges\setTopText(), MessageCacheTest\setUp(), MediaWikiLangTestCase\setUp(), ParserTestRunner\setupDatabase(), MessageCacheTest\testFullKeyBehaviour(), MessageCacheTest\testMessageFallbacks(), MessageCacheTest\testReplaceMsg(), and Message\transformText().
MessageCache::transform | ( | $message, | |
$interface = false, | |||
$language = null, | |||
$title = null ) |
Definition at line 1093 of file MessageCache.php.
References $parser, getParser(), and getParserOptions().
Purge message caches when a MediaWiki: page is created, updated, or deleted.
Title | $title | Message page title |
Content | null | $content | New content for edit/create, null on deletion |
Definition at line 1280 of file MessageCache.php.
References $wgContLang, Title\getDBkey(), getMessageTextFromContent(), and replace.
|
protected |
Definition at line 96 of file MessageCache.php.
Referenced by __construct().
|
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 55 of file MessageCache.php.
|
protected |
Map of (language code => boolean)
Definition at line 60 of file MessageCache.php.
|
protected |
Should mean that database cannot be used, but check.
Definition at line 66 of file MessageCache.php.
Referenced by isDisabled().
|
protected |
Lifetime for cache, used by object caching.
Set on construction, see __construct().
Definition at line 72 of file MessageCache.php.
|
protected |
Definition at line 91 of file MessageCache.php.
|
protected |
Variable for tracking which variables are already loaded.
Definition at line 86 of file MessageCache.php.
|
protected |
Definition at line 80 of file MessageCache.php.
Referenced by getParser().
|
protected |
Message cache has its own parser which it uses to transform messages.
Definition at line 78 of file MessageCache.php.
Referenced by getParserOptions().
|
protected |
Definition at line 98 of file MessageCache.php.
Referenced by __construct().
|
protected |
Definition at line 94 of file MessageCache.php.
Referenced by __construct().
const MessageCache::FOR_UPDATE = 1 |
Definition at line 40 of file MessageCache.php.
const MessageCache::LOCK_TTL = 30 |
How long memcached locks last.
Definition at line 45 of file MessageCache.php.
const MessageCache::WAIT_SEC = 15 |
How long to wait for memcached locks.
Definition at line 43 of file MessageCache.php.