MediaWiki
REL1_19
|
Message cache Performs various MediaWiki namespace-related functions. More...
Public Member Functions | |
__construct ($memCached, $useDB, $expiry) | |
clear () | |
Clear all stored messages. | |
disable () | |
enable () | |
escapeForScript ($string) | |
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. | |
getMostUsedMessages () | |
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. | |
loadFromLocal ($hash, $code) | |
Try to load the cache from a local file. | |
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. | |
saveToScript ($array, $hash, $code) | |
setCache ($cache, $code) | |
Set the cache to $cache, if it is valid. | |
transform ($message, $interface=false, $language=null, $title=null) | |
unlock ($key) | |
Static Public Member Functions | |
static | destroyInstance () |
Destroy the singleton instance. | |
static | logMessages () |
static | singleton () |
Get the signleton instance of this class. | |
Public Attributes | |
$mParser | |
Protected Member Functions | |
saveToCaches ($cache, $memc=true, $code=false) | |
Shortcut to update caches. | |
Protected Attributes | |
$mCache | |
Process local cache of loaded messages that are defined in MediaWiki namespace. | |
$mDisable | |
$mExpiry | |
Lifetime for cache, used by object caching. | |
$mInParser = false | |
$mLoadedLanguages = array() | |
Variable for tracking which variables are already loaded. | |
$mParserOptions | |
Message cache has it's own parser which it uses to transform messages. | |
$mRequestedMessages = array() | |
Used for automatic detection of most used messages. | |
Static Protected Attributes | |
static | $mAdaptiveDataAge = 604800 |
How long the message request counts are stored. | |
static | $mAdaptiveInclusionThreshold = 0.05 |
Filter the tail of less used messages that are requested more seldom than this factor times the number of request of most requested message. | |
Static Private Attributes | |
static | $instance |
Message cache Performs various MediaWiki namespace-related functions.
Definition at line 20 of file MessageCache.php.
MessageCache::__construct | ( | $ | memCached, |
$ | useDB, | ||
$ | expiry | ||
) |
Definition at line 100 of file MessageCache.php.
References wfGetCache().
Clear all stored messages.
Mainly used after a mass rebuild.
Definition at line 870 of file MessageCache.php.
References Language\getLanguageNames(), and wfMemcKey().
static MessageCache::destroyInstance | ( | ) | [static] |
Definition at line 859 of file MessageCache.php.
Definition at line 863 of file MessageCache.php.
MessageCache::escapeForScript | ( | $ | string | ) |
Definition at line 226 of file MessageCache.php.
Referenced by saveToScript().
MessageCache::figureMessage | ( | $ | key | ) |
$key |
Definition at line 885 of file MessageCache.php.
References $wgLanguageCode, and Language\getLanguageNames().
Referenced by replace().
MessageCache::get | ( | $ | key, |
$ | useDB = true , |
||
$ | langcode = true , |
||
$ | isFullKey = false |
||
) |
Get a message from either the content language or the user language.
$key | String: the message cache key |
$useDB | Boolean: get the message from the DB, false to use only the localisation |
$langcode | String: code of the language to get the message for, if it is a valid code create a language for that language, if it is a string but not a valid code then make a basic language object, if it is a false boolean then use the current users language (as a fallback for the old parameter functionality), or if it is a true boolean then use the wikis content language (also as a fallback). |
$isFullKey | Boolean: specifies whether $key is a two part key "msg/lang". |
Definition at line 593 of file MessageCache.php.
References $title, $wgContLang, $wgLanguageCode, Language\getMessageFor(), getMsgFromNamespace(), 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.
$code | string |
Definition at line 986 of file MessageCache.php.
References $wgContLang, and load().
Definition at line 945 of file MessageCache.php.
References $count, $messages, wfGetCache(), wfMemcKey(), wfProfileIn(), and wfProfileOut().
Referenced by loadFromDB().
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.
$title | String: Message cache key with initial uppercase letter. |
$code | String: code denoting the language to try. |
Definition at line 701 of file MessageCache.php.
References $title, $wgAdaptiveMessageCache, load(), Title\makeTitle(), Revision\newFromTitle(), wfDebugLog(), wfMemcKey(), and wfRunHooks().
Referenced by get().
Definition at line 804 of file MessageCache.php.
References $wgParser, and $wgParserConf.
Referenced by parse(), and transform().
ParserOptions is lazy initialised.
Definition at line 115 of file MessageCache.php.
Referenced by parse(), and transform().
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.
$code | String: language to which load messages |
Definition at line 264 of file MessageCache.php.
References $success, $wgUseLocalMessageCache, loadFromDB(), loadFromLocal(), lock(), saveToCaches(), setCache(), unlock(), wfDebug(), wfMemcKey(), wfProfileIn(), and wfProfileOut().
Referenced by getAllMessageKeys(), getMsgFromNamespace(), 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.
$code | String: language code. |
Definition at line 375 of file MessageCache.php.
References $dbr, $res, $wgAdaptiveMessageCache, $wgLanguageCode, $wgMaxMsgCacheEntrySize, getMostUsedMessages(), Revision\getRevisionText(), wfDebugLog(), wfGetDB(), wfProfileIn(), and wfProfileOut().
Referenced by load().
MessageCache::loadFromLocal | ( | $ | hash, |
$ | code | ||
) |
Try to load the cache from a local file.
Actual format of the file depends on the $wgLocalMessageCacheSerialized setting.
$hash | String: the hash of contents, to check validity. |
$code | Mixed: Optional language code, see documenation of load(). |
Definition at line 131 of file MessageCache.php.
References $file, $serialized, $wgCacheDirectory, $wgLocalMessageCacheSerialized, setCache(), wfRestoreWarnings(), wfSuppressWarnings(), and wfWikiID().
Referenced by load().
MessageCache::lock | ( | $ | key | ) |
Represents a write lock on the messages key.
$key | string |
Definition at line 560 of file MessageCache.php.
Referenced by load(), and replace().
static MessageCache::logMessages | ( | ) | [static] |
Definition at line 902 of file MessageCache.php.
References $mAdaptiveDataAge, $wgAdaptiveMessageCache, wfGetCache(), wfProfileIn(), wfProfileOut(), wfTimestamp(), and wfTimestampNow().
Referenced by MediaWiki\restInPeace().
MessageCache::parse | ( | $ | text, |
$ | title = null , |
||
$ | linestart = true , |
||
$ | interface = false , |
||
$ | language = null |
||
) |
$text | string |
$title | Title |
$linestart | bool |
$interface | bool |
$language |
Definition at line 829 of file MessageCache.php.
References $language, $res, $title, $wgTitle, getParser(), getParserOptions(), Title\newFromText(), wfProfileIn(), and wfProfileOut().
MessageCache::replace | ( | $ | title, |
$ | text | ||
) |
Updates cache as necessary when message page is changed.
$title | String: name of the page changed. |
$text | Mixed: new contents of the page. |
Definition at line 460 of file MessageCache.php.
References $title, $wgContLang, $wgMaxMsgCacheEntrySize, $wgMemc, figureMessage(), Language\getLanguageNames(), load(), lock(), saveToCaches(), unlock(), MessageBlobStore\updateMessage(), wfMemcKey(), wfProfileIn(), wfProfileOut(), and wfRunHooks().
MessageCache::saveToCaches | ( | $ | cache, |
$ | memc = true , |
||
$ | code = false |
||
) | [protected] |
Shortcut to update caches.
$cache | Array: cached messages with a version. |
$memc | Bool: Wether to update or not memcache. |
$code | String: Language code. |
Definition at line 525 of file MessageCache.php.
References $serialized, $success, $wgLocalMessageCacheSerialized, $wgUseLocalMessageCache, saveToLocal(), saveToScript(), wfMemcKey(), wfProfileIn(), and wfProfileOut().
Referenced by load(), and replace().
MessageCache::saveToLocal | ( | $ | serialized, |
$ | hash, | ||
$ | code | ||
) |
Save the cache to a local file.
Definition at line 175 of file MessageCache.php.
References $file, $serialized, $wgCacheDirectory, wfDebug(), wfMkdirParents(), wfRestoreWarnings(), wfSuppressWarnings(), and wfWikiID().
Referenced by saveToCaches().
MessageCache::saveToScript | ( | $ | array, |
$ | hash, | ||
$ | code | ||
) |
Definition at line 197 of file MessageCache.php.
References $file, $wgCacheDirectory, escapeForScript(), wfDebug(), wfMkdirParents(), wfRestoreWarnings(), wfSuppressWarnings(), and wfWikiID().
Referenced by saveToCaches().
MessageCache::setCache | ( | $ | cache, |
$ | code | ||
) |
Set the cache to $cache, if it is valid.
Otherwise set the cache to false.
Definition at line 237 of file MessageCache.php.
Referenced by load(), and loadFromLocal().
static MessageCache::singleton | ( | ) | [static] |
Get the signleton instance of this class.
Definition at line 83 of file MessageCache.php.
References $instance, $wgMsgCacheExpiry, $wgUseDatabaseMessages, and wfGetMessageCacheStorage().
Referenced by NewParserTest\addDBData(), Skin\addToSidebarPlain(), EmailNotification\composeCommonMailtext(), WikiPage\doEditUpdates(), WikiPage\doPurge(), ApiQueryAllmessages\execute(), Message\fetchMessage(), Title\getDefaultMessageText(), DBConnectionError\getHTML(), Title\getPageLanguage(), Title\hasSourceText(), SideBarTest\initMessagesHref(), WikiPage\onArticleDelete(), LanguageConverter\parseCachedTable(), Message\parseText(), MediaWikiLangTestCase\setUp(), ParserTest\setupDatabase(), NewParserTest\setupGlobals(), Message\transformText(), wfEmptyMsg(), wfMsgExt(), wfMsgGetKey(), and wfMsgWikiHtml().
MessageCache::transform | ( | $ | message, |
$ | interface = false , |
||
$ | language = null , |
||
$ | title = null |
||
) |
$message | string |
$interface | bool |
$language | |
$title | Title |
Definition at line 776 of file MessageCache.php.
References $language, $title, getParser(), and getParserOptions().
MessageCache::unlock | ( | $ | key | ) |
Definition at line 569 of file MessageCache.php.
Referenced by load(), and replace().
MessageCache::$instance [static, private] |
Definition at line 70 of file MessageCache.php.
Referenced by singleton().
MessageCache::$mAdaptiveDataAge = 604800 [static, protected] |
How long the message request counts are stored.
Longer period gives better sample, but also takes longer to adapt changes. The counts are aggregrated per day, regardless of the value of this variable.
Definition at line 55 of file MessageCache.php.
Referenced by logMessages().
MessageCache::$mAdaptiveInclusionThreshold = 0.05 [static, protected] |
Filter the tail of less used messages that are requested more seldom than this factor times the number of request of most requested message.
These messages are not loaded in the default set, but are still cached individually on demand with the normal cache expiry time.
Definition at line 63 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 28 of file MessageCache.php.
MessageCache::$mDisable [protected] |
Definition at line 31 of file MessageCache.php.
MessageCache::$mExpiry [protected] |
Lifetime for cache, used by object caching.
Definition at line 34 of file MessageCache.php.
MessageCache::$mInParser = false [protected] |
Definition at line 75 of file MessageCache.php.
MessageCache::$mLoadedLanguages = array() [protected] |
Variable for tracking which variables are already loaded.
Definition at line 43 of file MessageCache.php.
MessageCache::$mParser |
Definition at line 40 of file MessageCache.php.
MessageCache::$mParserOptions [protected] |
Message cache has it's own parser which it uses to transform messages.
Definition at line 40 of file MessageCache.php.
MessageCache::$mRequestedMessages = array() [protected] |
Used for automatic detection of most used messages.
Definition at line 48 of file MessageCache.php.