MediaWiki
1.28.3
|
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... | |
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... | |
loadFromDB ($code, $mode=null) | |
Loads cacheable messages from the database. More... | |
parse ($text, $title=null, $linestart=true, $interface=false, $language=null) | |
replace ($title, $text) | |
Updates cache as necessary when message page is changed. More... | |
transform ($message, $interface=false, $language=null, $title=null) | |
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 | |
$mParser | |
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... | |
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 | |
$mCache | |
Process local cache of loaded messages that are defined in MediaWiki namespace. More... | |
$mDisable | |
Should mean that database cannot be used, but check. More... | |
$mExpiry | |
Lifetime for cache, used by object caching. More... | |
$mInParser = false | |
$mLoadedLanguages = [] | |
Variable for tracking which variables are already loaded. More... | |
BagOStuff | $mMemc |
$mParserOptions | |
Message cache has its own parser which it uses to transform messages. More... | |
WANObjectCache | $wanCache |
Private Member Functions | |
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... | |
Static Private Attributes | |
static | $instance |
Singleton instance. More... | |
Message cache Performs various MediaWiki namespace-related functions.
Definition at line 37 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 147 of file MessageCache.php.
References $wgUseLocalMessageCache, CACHE_NONE, ObjectCache\getMainWANInstance(), global, and wfGetCache().
MessageCache::clear | ( | ) |
Clear all stored messages.
Mainly used after a mass rebuild.
Definition at line 1162 of file MessageCache.php.
References $code, as, Language\fetchLanguageNames(), and wfMemcKey().
|
static |
Destroy the singleton instance.
Definition at line 120 of file MessageCache.php.
Referenced by ParserTestRunner\staticSetup(), and MessageTest\testRawHtmlInMsg().
MessageCache::disable | ( | ) |
Definition at line 1135 of file MessageCache.php.
MessageCache::enable | ( | ) |
Definition at line 1139 of file MessageCache.php.
MessageCache::figureMessage | ( | $key | ) |
string | $key |
Definition at line 1176 of file MessageCache.php.
References $lang, $wgLanguageCode, Language\fetchLanguageName(), and global.
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 742 of file MessageCache.php.
References $lang, by, 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 1202 of file MessageCache.php.
References $cache, $code, $wgContLang, global, and load().
|
protected |
Try to load the cache from APC.
string | $code | Optional language code, see documenation of load(). |
Definition at line 203 of file MessageCache.php.
References $code, and wfMemcKey().
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 851 of file MessageCache.php.
References $code, $lang, $wgContLang, as, Language\getFallbacksFor(), getMessagePageName(), getMsgFromNamespace(), and global.
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 825 of file MessageCache.php.
References $lang, $wgContLang, getMessageForLang(), and global.
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 909 of file MessageCache.php.
References $wgLanguageCode, and global.
Referenced by getMessageForLang().
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 931 of file MessageCache.php.
References $code, $content, $dbr, $title, DB_REPLICA, Database\getCacheSetOptions(), load(), Title\makeTitle(), Revision\newKnownCurrent(), NS_MEDIAWIKI, Hooks\run(), wfDebugLog(), wfGetDB(), and wfMemcKey().
Referenced by getMessageForLang().
MessageCache::getParser | ( | ) |
Definition at line 1073 of file MessageCache.php.
References $mParser, $wgParser, and global.
Referenced by parse(), and transform().
MessageCache::getParserOptions | ( | ) |
ParserOptions is lazy initialised.
Definition at line 172 of file MessageCache.php.
References $mParserOptions, $wgUser, global, ParserOptions\newFromAnon(), and ParserOptions\setEditSection().
Referenced by parse(), and transform().
|
protected |
string | $key | A language message cache key that stores blobs |
integer | $timeout | Wait timeout in seconds |
Definition at line 704 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 653 of file MessageCache.php.
References $code, $value, WANObjectCache\HOLDOFF_TTL, and wfMemcKey().
Referenced by load().
|
protected |
Is the given cache array expired due to time passing or a version change?
array | $cache |
Definition at line 610 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 1155 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 |
integer | $mode | Use MessageCache::FOR_UPDATE to skip process cache [optional] |
MWException |
Definition at line 241 of file MessageCache.php.
References $cache, $code, $success, array(), cache, data, getLocalCache(), getReentrantScopedLock(), getValidationHash(), in, info, isCacheExpired(), list, loadFromDBWithLock(), messages, of, or, saveToCaches(), too, wfDebug(), wfDebugLog(), and wfMemcKey().
Referenced by getAllMessageKeys(), getMsgFromNamespace(), loadFromDB(), and replace().
MessageCache::loadFromDB | ( | $code, | |
$mode = null |
|||
) |
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 |
integer | $mode | Use MessageCache::FOR_UPDATE to skip process cache |
Definition at line 446 of file MessageCache.php.
References $cache, $code, $dbr, $res, $value, $wgAdaptiveMessageCache, $wgLanguageCode, $wgMaxMsgCacheEntrySize, as, DB_MASTER, DB_REPLICA, Revision\getRevisionText(), global, load(), MSG_CACHE_VERSION, NS_MEDIAWIKI, serialize(), TS_MW, wfDebugLog(), wfGetDB(), and wfTimestamp().
Referenced by loadFromDBWithLock().
|
protected |
string | $code | |
array | $where | List of wfDebug() comments |
integer | $mode | Use MessageCache::FOR_UPDATE to use DB_MASTER |
Definition at line 382 of file MessageCache.php.
References $cache, $code, $status, $wgUseLocalMessageCache, getReentrantScopedLock(), global, loadFromDB(), saveToCaches(), and wfMemcKey().
Referenced by load().
|
static |
Normalize message key input.
string | $key | Input message key to be normalized |
Definition at line 130 of file MessageCache.php.
References $wgContLang, and global.
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 1099 of file MessageCache.php.
References $parser, $res, $title, $wgTitle, Language\factory(), getParser(), getParserOptions(), global, Title\makeTitle(), NS_SPECIAL, wfDebugLog(), and wfGetAllCallers().
MessageCache::replace | ( | $title, | |
$text | |||
) |
Updates cache as necessary when message page is changed.
string | bool | $title | Name of the page changed (false if deleted) |
mixed | $text | New contents of the page. |
Definition at line 534 of file MessageCache.php.
References $code, $title, $wgContLang, $wgLanguageCode, $wgMaxMsgCacheEntrySize, as, Language\fetchLanguageNames(), figureMessage(), RequestContext\getMain(), getReentrantScopedLock(), global, list, load(), Hooks\run(), saveToCaches(), and wfMemcKey().
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 633 of file MessageCache.php.
References $code, $success, saveToLocalCache(), setValidationHash(), and wfMemcKey().
Referenced by load(), loadFromDBWithLock(), and replace().
|
protected |
Save the cache to APC.
string | $code | |
array | $cache | The cache array |
Definition at line 215 of file MessageCache.php.
References $cache, $code, and wfMemcKey().
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
string | $code | |
array | $cache | Cached messages with a version |
Definition at line 688 of file MessageCache.php.
References $code, IExpiringStore\TTL_INDEFINITE, and wfMemcKey().
Referenced by saveToCaches().
|
static |
Get the signleton instance of this class.
Definition at line 102 of file MessageCache.php.
References $wgMsgCacheExpiry, $wgUseDatabaseMessages, global, and wfGetMessageCacheStorage().
Referenced by 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(), MediaWikiLangTestCase\setUp(), MessageCacheTest\setUp(), ParserTestRunner\setupDatabase(), MessageCacheTest\testFullKeyBehaviour(), MessageCacheTest\testMessageFallbacks(), and Message\transformText().
MessageCache::transform | ( | $message, | |
$interface = false , |
|||
$language = null , |
|||
$title = null |
|||
) |
Definition at line 1044 of file MessageCache.php.
References $parser, $title, getParser(), and getParserOptions().
|
staticprivate |
Singleton instance.
Definition at line 94 of file MessageCache.php.
|
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 53 of file MessageCache.php.
|
protected |
Should mean that database cannot be used, but check.
Definition at line 59 of file MessageCache.php.
Referenced by isDisabled().
|
protected |
Lifetime for cache, used by object caching.
Set on construction, see __construct().
Definition at line 65 of file MessageCache.php.
|
protected |
Definition at line 82 of file MessageCache.php.
|
protected |
Variable for tracking which variables are already loaded.
Definition at line 77 of file MessageCache.php.
|
protected |
Definition at line 85 of file MessageCache.php.
MessageCache::$mParser |
Definition at line 71 of file MessageCache.php.
Referenced by getParser().
|
protected |
Message cache has its own parser which it uses to transform messages.
Definition at line 71 of file MessageCache.php.
Referenced by getParserOptions().
|
protected |
Definition at line 87 of file MessageCache.php.
const MessageCache::FOR_UPDATE = 1 |
Definition at line 38 of file MessageCache.php.
const MessageCache::LOCK_TTL = 30 |
How long memcached locks last.
Definition at line 43 of file MessageCache.php.
const MessageCache::WAIT_SEC = 15 |
How long to wait for memcached locks.
Definition at line 41 of file MessageCache.php.