MediaWiki  1.23.6
MessageCache Class Reference

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...
 

Detailed Description

Message cache Performs various MediaWiki namespace-related functions.

Definition at line 52 of file MessageCache.php.

Constructor & Destructor Documentation

◆ __construct()

MessageCache::__construct (   $memCached,
  $useDB,
  $expiry 
)
Parameters
BagOStuff$memCachedA cache instance. If none, fall back to CACHE_NONE.
bool$useDB
int$expiryLifetime for cache.
See also
$mExpiry.

Definition at line 128 of file MessageCache.php.

References CACHE_NONE, and wfGetCache().

Member Function Documentation

◆ clear()

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().

◆ destroyInstance()

static MessageCache::destroyInstance ( )
static

Destroy the singleton instance.

Since
1.18

Definition at line 119 of file MessageCache.php.

◆ disable()

MessageCache::disable ( )

Definition at line 1075 of file MessageCache.php.

◆ enable()

MessageCache::enable ( )

Definition at line 1079 of file MessageCache.php.

◆ figureMessage()

MessageCache::figureMessage (   $key)
Parameters
$key
Returns
array

Definition at line 1101 of file MessageCache.php.

References array(), Language\fetchLanguageName(), and global.

Referenced by replace().

◆ get()

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):

  1. If a language-specific override, i.e., [[MW:msg/lang]], is available, use that. Note: for the content language, there is no /lang subpage.
  2. Fetch from the static CDB cache.
  3. If available, check the database for fallback language overrides.

This process provides a number of guarantees. When changing this code, make sure all of these guarantees are preserved.

  • If the requested language is not the content language, then the CDB cache for that specific language will take precedence over the root database page ([[MW:msg]]).
  • Fallbacks will be just that: fallbacks. A fallback language will never be reached if the message is available anywhere in the language for which it is a fallback.
Parameters
string$keythe message key
bool$useDBIf true, look for the message in the DB, false to use only the compiled l10n cache.
bool | string | object$langcodeCode of the language to get the message for.
  • If string and a valid code, will create a standard language object
  • If string but not a valid code, will create a basic language object
  • If boolean and false, create object from the current users language
  • If boolean and true, create object from the wikis content language
  • If language object, use it as given
bool$isFullKeyspecifies whether $key is a two part key "msg/lang".
Exceptions
MWExceptionwhen given an invalid key
Returns
string|bool False if the message doesn't exist, otherwise the message (which can be empty)

Definition at line 703 of file MessageCache.php.

References $section, $wgContLang, array(), Language\getMessageFor(), getMessageFromFallbackChain(), global, wfGetLangObj(), and wfRunHooks().

◆ getAllMessageKeys()

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.

Parameters
string$codeLanguage code
Returns
array of message keys (strings)

Definition at line 1126 of file MessageCache.php.

References $cache, $wgContLang, array(), global, and load().

◆ getLocalCache()

MessageCache::getLocalCache (   $hash,
  $code 
)

Try to load the cache from a local file.

Parameters
string$hashthe hash of contents, to check validity.
Mixed$codeOptional language code, see documenation of load().
Returns
array The cache array

Definition at line 159 of file MessageCache.php.

References $file, $hash, $serialized, global, wfRestoreWarnings(), wfSuppressWarnings(), and wfWikiID().

Referenced by load().

◆ getMessageFromFallbackChain()

MessageCache::getMessageFromFallbackChain (   $lang,
  $lckey,
  $uckey,
  $useDB 
)
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.

Parameters
Language$langRequested language
string$lckeyLowercase key for the message
string$uckeyUppercase key for the message
bool$useDBWhether to use the database
See also
MessageCache::get
Returns
string|bool The message, or false if not found

Definition at line 801 of file MessageCache.php.

References $wgContLang, as, Language\getFallbacksIncludingSiteLanguage(), getMsgFromNamespace(), global, and list.

Referenced by get().

◆ getMsgFromNamespace()

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.

Parameters
string$titleMessage cache key with initial uppercase letter.
string$codeCode denoting the language to try.
Returns
string|bool The message, or false if it does not exist or on error

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().

◆ getParser()

MessageCache::getParser ( )
Returns
Parser

Definition at line 1016 of file MessageCache.php.

References $mParser, $wgParser, and global.

Referenced by parse(), and transform().

◆ getParserOptions()

MessageCache::getParserOptions ( )

ParserOptions is lazy initialised.

Returns
ParserOptions

Definition at line 143 of file MessageCache.php.

References $mParserOptions, and ParserOptions\setEditSection().

Referenced by parse(), and transform().

◆ isCacheExpired()

MessageCache::isCacheExpired (   $cache)
protected

Is the given cache array expired due to time passing or a version change?

Parameters
$cache
Returns
bool

Definition at line 583 of file MessageCache.php.

References $cache, MSG_CACHE_VERSION, and wfTimestampNow().

Referenced by load().

◆ 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.

Parameters
bool | String$codeLanguage to which load messages
Exceptions
MWException
Returns
bool

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().

◆ loadFromDB()

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.

Parameters
string$codeLanguage code.
Returns
array Loaded messages for storing in caches.

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().

◆ lock()

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.

Parameters
string$key
Returns
Boolean: success

Definition at line 640 of file MessageCache.php.

References MSG_LOCK_TIMEOUT, MSG_WAIT_TIMEOUT, and wfMemcKey().

Referenced by load(), and replace().

◆ parse()

MessageCache::parse (   $text,
  $title = null,
  $linestart = true,
  $interface = false,
  $language = null 
)
Parameters
string$text
Title$title
bool$linestartWhether or not this is at the start of a line
bool$interfaceWhether this is an interface message
string$languageLanguage code
Returns
ParserOutput|string

Definition at line 1042 of file MessageCache.php.

References $parser, $res, $title, $wgTitle, getParser(), getParserOptions(), global, Title\newFromText(), wfProfileIn(), and wfProfileOut().

◆ replace()

MessageCache::replace (   $title,
  $text 
)

Updates cache as necessary when message page is changed.

Parameters
string$titleName of the page changed.
mixed$textNew 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().

◆ saveToCaches()

MessageCache::saveToCaches (   $cache,
  $dest,
  $code = false 
)
protected

Shortcut to update caches.

Parameters
array$cacheCached messages with a version.
string$destEither "local-only" to save to local caches only or "all" to save to all caches.
string | bool$codeLanguage code (default: false)
Returns
bool

Definition at line 606 of file MessageCache.php.

References $cache, $hash, $serialized, $success, global, saveToLocal(), wfMemcKey(), wfProfileIn(), and wfProfileOut().

Referenced by load(), and replace().

◆ saveToLocal()

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().

◆ singleton()

◆ transform()

MessageCache::transform (   $message,
  $interface = false,
  $language = null,
  $title = null 
)
Parameters
string$message
bool$interface
string$languageLanguage code
Title$title
Returns
string

Definition at line 987 of file MessageCache.php.

References $parser, $title, getParser(), and getParserOptions().

◆ unlock()

MessageCache::unlock (   $key)

Definition at line 663 of file MessageCache.php.

Referenced by load(), and replace().

Member Data Documentation

◆ $instance

MessageCache MessageCache::$instance
staticprivate

Singleton instance.

Definition at line 89 of file MessageCache.php.

Referenced by singleton().

◆ $mCache

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 60 of file MessageCache.php.

◆ $mDisable

bool MessageCache::$mDisable
protected

Should mean that database cannot be used, but check $mDisable.

Definition at line 65 of file MessageCache.php.

◆ $mExpiry

MessageCache::$mExpiry
protected

Lifetime for cache, used by object caching.

Set on construction, see __construct().

Definition at line 71 of file MessageCache.php.

◆ $mInParser

bool MessageCache::$mInParser = false
protected

$mInParser

Definition at line 93 of file MessageCache.php.

◆ $mLoadedLanguages

array MessageCache::$mLoadedLanguages = array()
protected

Variable for tracking which variables are already loaded $mLoadedLanguages.

Definition at line 82 of file MessageCache.php.

◆ $mParser

MessageCache::$mParser

Definition at line 77 of file MessageCache.php.

Referenced by getParser().

◆ $mParserOptions

MessageCache::$mParserOptions
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().


The documentation for this class was generated from the following files: