MediaWiki
1.32.5
|
Cache of messages that are defined by MediaWiki namespace pages or by hooks. More...
Public Member Functions | |
__construct (WANObjectCache $wanCache, BagOStuff $clusterCache, BagOStuff $serverCache, $useDB, $expiry, Language $contLang=null) | |
clear () | |
Clear all stored messages in global and local cache. More... | |
disable () | |
enable () | |
figureMessage ( $key) | |
get ( $key, $useDB=true, $langcode=true) | |
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... | |
getCheckKey ( $code) | |
getMsgFromNamespace ( $title, $code) | |
Get a message from the MediaWiki namespace, with caching. More... | |
getParser () | |
getParserOptions () | |
ParserOptions is lazy initialised. More... | |
isDisabled () | |
Whether DB/cache usage is disabled for determining messages. More... | |
parse ( $text, $title=null, $linestart=true, $interface=false, $language=null) | |
refreshAndReplaceInternal ( $code, array $replacements) | |
replace ( $title, $text) | |
Updates cache as necessary when message page is changed. More... | |
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. More... | |
Static Public Member Functions | |
static | destroyInstance () |
Destroy the singleton instance. More... | |
static | normalizeKey ( $key) |
Normalize message key input. More... | |
static | singleton () |
Get the signleton instance of this class. More... | |
Public Attributes | |
const | FOR_UPDATE = 1 |
const | LOCK_TTL = 30 |
How long memcached locks last. More... | |
const | WAIT_SEC = 15 |
How long to wait for memcached locks. More... | |
Protected Member Functions | |
getLocalCache ( $code) | |
Try to load the cache from APC. More... | |
getMessageFromFallbackChain ( $lang, $lckey, $useDB) | |
Given a language, try and fetch messages from that language. More... | |
getReentrantScopedLock ( $key, $timeout=self::WAIT_SEC) | |
getValidationHash ( $code) | |
Get the md5 used to validate the local APC cache. More... | |
isCacheExpired ( $cache) | |
Is the given cache array expired due to time passing or a version change? More... | |
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. More... | |
loadFromDB ( $code, $mode=null) | |
Loads cacheable messages from the database. More... | |
loadFromDBWithLock ( $code, array &$where, $mode=null) | |
saveToCaches (array $cache, $dest, $code=false) | |
Shortcut to update caches. More... | |
saveToLocalCache ( $code, $cache) | |
Save the cache to APC. More... | |
setValidationHash ( $code, array $cache) | |
Set the md5 used to validate the local disk cache. More... | |
Protected Attributes | |
MapCacheLRU | $cache |
Process cache of loaded messages that are defined in MediaWiki namespace. More... | |
bool[] | $cacheVolatile = [] |
Map of (language code => boolean) More... | |
BagOStuff | $clusterCache |
Language | $contLang |
$mDisable | |
Should mean that database cannot be used, but check. More... | |
$mExpiry | |
Lifetime for cache, used by object caching. More... | |
$mInParser = false | |
Parser | $mParser |
ParserOptions | $mParserOptions |
Message cache has its own parser which it uses to transform messages. More... | |
array | $overridable |
Map of (lowercase message key => index) for all software defined messages. More... | |
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. More... | |
getMessagePageName ( $langcode, $uckey) | |
Get the message page name for a given language. More... | |
getMessageTextFromContent (Content $content=null) | |
isMainCacheable ( $name, array $overridable) | |
loadCachedMessagePageEntry ( $dbKey, $code, $hash) | |
Private Attributes | |
array | $loadedLanguages = [] |
Track which languages have been loaded by load(). More... | |
Static Private Attributes | |
static | $instance |
Singleton instance. More... | |
Cache of messages that are defined by MediaWiki namespace pages or by hooks.
Performs various MediaWiki namespace-related functions
Definition at line 40 of file MessageCache.php.
MessageCache::__construct | ( | WANObjectCache | $wanCache, |
BagOStuff | $clusterCache, | ||
BagOStuff | $serverCache, | ||
$useDB, | |||
$expiry, | |||
Language | $contLang = null |
||
) |
WANObjectCache | $wanCache | |
BagOStuff | $clusterCache | |
BagOStuff | $serverCache | |
bool | $useDB | Whether to look for message overrides (e.g. MediaWiki: pages) |
int | $expiry | Lifetime for cache. |
Definition at line 173 of file MessageCache.php.
References $clusterCache, $contLang, $wanCache, and cache.
|
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 1405 of file MessageCache.php.
References $title.
Referenced by loadCachedMessagePageEntry(), and refreshAndReplaceInternal().
MessageCache::clear | ( | ) |
Clear all stored messages in global and local cache.
Mainly used after a mass rebuild
Definition at line 1287 of file MessageCache.php.
References $code, as, cache, Language\fetchLanguageNames(), and getCheckKey().
|
static |
Destroy the singleton instance.
Definition at line 144 of file MessageCache.php.
Referenced by MessageCacheTest\setUp(), and MessageCacheTest\testReplaceCache().
MessageCache::disable | ( | ) |
Definition at line 1258 of file MessageCache.php.
MessageCache::enable | ( | ) |
Definition at line 1262 of file MessageCache.php.
MessageCache::figureMessage | ( | $key | ) |
string | $key |
Definition at line 1300 of file MessageCache.php.
References $lang, $wgLanguageCode, captcha-old\count, and Language\fetchLanguageName().
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.
|
MWException | When given an invalid key |
Definition at line 858 of file MessageCache.php.
References by, captcha-old\count, Language\getMessageFor(), getMessageFromFallbackChain(), normalizeKey(), Hooks\run(), 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 1326 of file MessageCache.php.
MessageCache::getCheckKey | ( | $code | ) |
string | $code | Language code |
Definition at line 1368 of file MessageCache.php.
References $code.
Referenced by clear(), getValidationHash(), and refreshAndReplaceInternal().
|
protected |
Try to load the cache from APC.
string | $code | Optional language code, see documentation of load(). |
Definition at line 226 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 957 of file MessageCache.php.
References $code, $lang, as, Language\getFallbacksFor(), 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 933 of file MessageCache.php.
References $lang, 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 1013 of file MessageCache.php.
References $wgLanguageCode.
Referenced by getMessageForLang().
|
private |
Definition at line 1376 of file MessageCache.php.
References $content.
Referenced by loadCachedMessagePageEntry(), refreshAndReplaceInternal(), 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 1036 of file MessageCache.php.
References $code, $name, $title, cache, isMainCacheable(), load(), loadCachedMessagePageEntry(), and Hooks\run().
Referenced by getMessageForLang().
MessageCache::getParser | ( | ) |
Definition at line 1194 of file MessageCache.php.
References $mParser, $wgParser, $wgParserConf, and class.
Referenced by parse(), and transform().
MessageCache::getParserOptions | ( | ) |
ParserOptions is lazy initialised.
Definition at line 197 of file MessageCache.php.
References $mParserOptions, ParserOptions\newFromAnon(), and ParserOptions\setAllowUnsafeRawHtml().
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 821 of file MessageCache.php.
Referenced by load(), loadFromDBWithLock(), and refreshAndReplaceInternal().
|
protected |
Get the md5 used to validate the local APC cache.
string | $code |
Definition at line 767 of file MessageCache.php.
References $code, $value, getCheckKey(), and IExpiringStore\TTL_MINUTE.
Referenced by load().
|
protected |
Is the given cache array expired due to time passing or a version change?
array | $cache |
Definition at line 724 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 1278 of file MessageCache.php.
References $mDisable.
|
private |
string | $name | Message name with lowercase first letter |
array | $overridable | Map of (key => unused) for software-defined messages |
Definition at line 588 of file MessageCache.php.
References $name, and $overridable.
Referenced by getMsgFromNamespace(), and loadFromDB().
|
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 successfully 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 successfully populated, or false if populating empty cache fails. Also returns true if MessageCache is disabled.
string | $code | Language to which load messages |
int | null | $mode | Use MessageCache::FOR_UPDATE to skip process cache [optional] |
InvalidArgumentException |
Definition at line 264 of file MessageCache.php.
References $cache, $code, $success, a, array(), cache, data, MapCacheLRU\get(), getLocalCache(), Language\getMessageKeysFor(), getReentrantScopedLock(), getValidationHash(), isCacheExpired(), list, loadFromDBWithLock(), none(), of, or, saveToCaches(), too, wfDebug(), and wfDebugLog().
Referenced by getAllMessageKeys(), getMsgFromNamespace(), loadFromDB(), and refreshAndReplaceInternal().
|
private |
string | $dbKey | |
string | $code | |
string | $hash |
Definition at line 1111 of file MessageCache.php.
References $code, $content, $dbr, $fname, $title, bigMessageCacheKey(), DB_REPLICA, getMessageTextFromContent(), Title\makeTitle(), Revision\newKnownCurrent(), NS_MEDIAWIKI, IExpiringStore\TTL_MINUTE, use, and wfGetDB().
Referenced by getMsgFromNamespace().
|
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 | null | $mode | Use MessageCache::FOR_UPDATE to skip process cache |
Definition at line 474 of file MessageCache.php.
References $cache, $code, $dbr, $name, $overridable, $res, $value, $wgAdaptiveMessageCache, $wgLanguageCode, $wgMaxMsgCacheEntrySize, as, cache, captcha-old\count, DB_MASTER, DB_REPLICA, Language\getMessageKeysFor(), Revision\getRevisionText(), isMainCacheable(), load(), MSG_CACHE_VERSION, NS_MEDIAWIKI, serialize(), wfDebugLog(), wfGetDB(), and wfTimestamp().
Referenced by loadFromDBWithLock(), and refreshAndReplaceInternal().
|
protected |
string | $code | |
array | &$where | List of wfDebug() comments |
int | null | $mode | Use MessageCache::FOR_UPDATE to use DB_MASTER |
Definition at line 412 of file MessageCache.php.
References $cache, $code, cache, getReentrantScopedLock(), loadFromDB(), and saveToCaches().
Referenced by load().
|
static |
Normalize message key input.
string | $key | Input message key to be normalized |
Definition at line 154 of file MessageCache.php.
Referenced by ApiQueryAllMessages\execute(), get(), and MessageCacheTest\testNormalizeKey().
MessageCache::parse | ( | $text, | |
$title = null , |
|||
$linestart = true , |
|||
$interface = false , |
|||
$language = null |
|||
) |
string | $text | |
Title | null | $title | |
bool | $linestart | Whether or not this is at the start of a line |
bool | $interface | Whether this is an interface message |
Language | string | null | $language | Language code |
Definition at line 1221 of file MessageCache.php.
References $parser, $res, $title, $wgTitle, Language\factory(), getParser(), getParserOptions(), Title\makeTitle(), NS_SPECIAL, wfDebugLog(), and wfGetAllCallers().
MessageCache::refreshAndReplaceInternal | ( | $code, | |
array | $replacements | ||
) |
string | $code | |
array[] | $replacements | List of (title, message key) pairs |
MWException |
Definition at line 634 of file MessageCache.php.
References $cache, $code, $title, $wgMaxMsgCacheEntrySize, as, bigMessageCacheKey(), cache, WikiPage\factory(), getCheckKey(), RequestContext\getMain(), getMessageTextFromContent(), getReentrantScopedLock(), list, load(), loadFromDB(), Title\makeTitle(), NS_MEDIAWIKI, Hooks\run(), saveToCaches(), and serialize().
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 600 of file MessageCache.php.
References $code, $title, $wgLanguageCode, DeferredUpdates\addUpdate(), cache, figureMessage(), list, and DeferredUpdates\PRESEND.
Referenced by updateMessageOverride().
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 747 of file MessageCache.php.
References $cache, $code, $success, saveToLocalCache(), and setValidationHash().
Referenced by load(), loadFromDBWithLock(), and refreshAndReplaceInternal().
|
protected |
Save the cache to APC.
string | $code | |
array | $cache | The cache array |
Definition at line 238 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 805 of file MessageCache.php.
References $cache, $code, and IExpiringStore\TTL_INDEFINITE.
Referenced by saveToCaches().
|
static |
Get the signleton instance of this class.
Definition at line 120 of file MessageCache.php.
References $instance, $services, $wgMsgCacheExpiry, $wgUseDatabaseMessages, $wgUseLocalMessageCache, and wfGetMessageCacheStorage().
Referenced by Skin\addToSidebarPlain(), Skin\buildSidebar(), EmailNotification\composeCommonMailtext(), WikiPage\doPurge(), MessageCacheUpdate\doUpdate(), ApiQueryAllMessages\execute(), Title\getDefaultMessageText(), Status\getHTML(), ContentHandler\getPageLanguage(), Title\hasSourceText(), SideBarTest\initMessagesHref(), WikiPage\newDerivedDataUpdater(), WikiPage\onArticleDelete(), MediaWiki\preOutputCommit(), MWExceptionRenderer\reportOutageHTML(), SpecialRecentChanges\setTopText(), MediaWikiLangTestCase\setUp(), MessageCacheTest\setUp(), SpamBlacklistTest\setUp(), SpamBlacklistTest\tearDown(), ApiQuerySiteinfoTest\testInterwikiMap(), MessageCacheTest\testMessageFallbacks(), MessageCacheTest\testNoDBAccess(), MessageCacheTest\testReplaceCache(), and MessageCacheTest\testReplaceMsg().
MessageCache::transform | ( | $message, | |
$interface = false , |
|||
$language = null , |
|||
$title = null |
|||
) |
Definition at line 1165 of file MessageCache.php.
References $parser, $title, 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 1351 of file MessageCache.php.
References $content, $title, Title\getDBkey(), getMessageTextFromContent(), and replace().
|
protected |
Process cache of loaded messages that are defined in MediaWiki namespace.
Map of (language code => key => " <MESSAGE>" or "!TOO BIG")
Definition at line 53 of file MessageCache.php.
Referenced by getAllMessageKeys(), isCacheExpired(), load(), loadFromDB(), loadFromDBWithLock(), refreshAndReplaceInternal(), saveToCaches(), saveToLocalCache(), and setValidationHash().
|
protected |
Map of (language code => boolean)
Definition at line 65 of file MessageCache.php.
|
protected |
Definition at line 95 of file MessageCache.php.
Referenced by __construct().
|
protected |
Definition at line 99 of file MessageCache.php.
Referenced by __construct().
|
staticprivate |
|
private |
Track which languages have been loaded by load().
Definition at line 105 of file MessageCache.php.
|
protected |
Should mean that database cannot be used, but check.
Definition at line 71 of file MessageCache.php.
Referenced by isDisabled().
|
protected |
Lifetime for cache, used by object caching.
Set on construction, see __construct().
Definition at line 77 of file MessageCache.php.
|
protected |
Definition at line 90 of file MessageCache.php.
|
protected |
Definition at line 85 of file MessageCache.php.
Referenced by getParser().
|
protected |
Message cache has its own parser which it uses to transform messages.
Definition at line 83 of file MessageCache.php.
Referenced by getParserOptions().
|
protected |
Map of (lowercase message key => index) for all software defined messages.
Definition at line 60 of file MessageCache.php.
Referenced by isMainCacheable(), and loadFromDB().
|
protected |
Definition at line 97 of file MessageCache.php.
|
protected |
Definition at line 93 of file MessageCache.php.
Referenced by __construct().
const MessageCache::FOR_UPDATE = 1 |
Definition at line 41 of file MessageCache.php.
const MessageCache::LOCK_TTL = 30 |
How long memcached locks last.
Definition at line 46 of file MessageCache.php.
const MessageCache::WAIT_SEC = 15 |
How long to wait for memcached locks.
Definition at line 44 of file MessageCache.php.