MediaWiki master
MessageCache Class Reference

Cache messages that are defined by MediaWiki-namespace pages or by hooks. More...

Inherits LoggerAwareInterface.

Collaboration diagram for MessageCache:

Public Member Functions

 __construct (WANObjectCache $wanCache, BagOStuff $clusterCache, BagOStuff $serverCache, Language $contLang, LanguageConverterFactory $langConverterFactory, LoggerInterface $logger, ServiceOptions $options, LanguageFactory $langFactory, LocalisationCache $localisationCache, LanguageNameUtils $languageNameUtils, LanguageFallback $languageFallback, HookContainer $hookContainer, ParserFactory $parserFactory)
 
 clear ()
 Clear all stored messages in global and local cache.
 
 disable ()
 
 enable ()
 
 figureMessage ( $key)
 
 get ( $key, $useDB=true, $language=null, &$usedKey='')
 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.
 
 getCheckKey ( $code)
 
 getMsgFromNamespace ( $title, $code)
 Get a message from the MediaWiki namespace, with caching.
 
 getParser ()
 
 isDisabled ()
 Whether DB/cache usage is disabled for determining messages.
 
 parse ( $text, PageReference $page=null, $linestart=true, $interface=false, $language=null)
 
 refreshAndReplaceInternal (string $code, array $replacements)
 
 replace ( $title, $text)
 Updates cache as necessary when message page is changed.
 
 setLogger (LoggerInterface $logger)
 
 transform ( $message, $interface=false, $language=null, PageReference $page=null)
 
 updateMessageOverride (LinkTarget $linkTarget, Content $content=null)
 Purge message caches when a MediaWiki: page is created, updated, or deleted.
 

Static Public Member Functions

static normalizeKey ( $key)
 Normalize message key input.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 Options to be included in the ServiceOptions.
 
const MAX_REQUEST_LANGUAGES = 10
 The size of the MapCacheLRU which stores message data.
 

Detailed Description

Cache messages that are defined by MediaWiki-namespace pages or by hooks.

Definition at line 64 of file MessageCache.php.

Constructor & Destructor Documentation

◆ __construct()

MessageCache::__construct ( WANObjectCache $wanCache,
BagOStuff $clusterCache,
BagOStuff $serverCache,
Language $contLang,
LanguageConverterFactory $langConverterFactory,
LoggerInterface $logger,
ServiceOptions $options,
LanguageFactory $langFactory,
LocalisationCache $localisationCache,
LanguageNameUtils $languageNameUtils,
LanguageFallback $languageFallback,
HookContainer $hookContainer,
ParserFactory $parserFactory )
Access: internal
For use by ServiceWiring
Parameters
WANObjectCache$wanCache
BagOStuff$clusterCache
BagOStuff$serverCache
Language$contLangContent language of site
LanguageConverterFactory$langConverterFactory
LoggerInterface$logger
ServiceOptions$options
LanguageFactory$langFactory
LocalisationCache$localisationCache
LanguageNameUtils$languageNameUtils
LanguageFallback$languageFallback
HookContainer$hookContainer
ParserFactory$parserFactory

Definition at line 215 of file MessageCache.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), disable(), MediaWiki\Config\ServiceOptions\get(), Language\getCode(), and MediaWiki\Languages\LanguageConverterFactory\getLanguageConverter().

Member Function Documentation

◆ clear()

MessageCache::clear ( )

Clear all stored messages in global and local cache.

Mainly used after a mass rebuild

Definition at line 1565 of file MessageCache.php.

References getCheckKey().

◆ disable()

MessageCache::disable ( )

Definition at line 1536 of file MessageCache.php.

References disable().

Referenced by __construct(), disable(), enable(), get(), and replace().

◆ enable()

MessageCache::enable ( )

Definition at line 1540 of file MessageCache.php.

References disable().

◆ figureMessage()

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

Definition at line 1577 of file MessageCache.php.

Referenced by replace().

◆ get()

MessageCache::get ( $key,
$useDB = true,
$language = null,
& $usedKey = '' )

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 | Language | null$languageCode 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 false, create object from the current users language
  • If true or null, create object from the wikis content language
  • If language object, use it as given
  • If this parameter omitted the object from the wikis content language is used
  • Other values than a Language object or null are deprecated.
string&$usedKeythat the message was fetched from (the requested key may be overridden by hooks).
Returns
string|false False if the message doesn't exist, otherwise the message (which can be empty)

Definition at line 1054 of file MessageCache.php.

References disable().

◆ 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
string[]|null Array of message keys

Definition at line 1606 of file MessageCache.php.

◆ getCheckKey()

MessageCache::getCheckKey ( $code)
Parameters
string$codeLanguage code
Returns
string WAN cache key usable as a "check key" against language page edits

Definition at line 1646 of file MessageCache.php.

Referenced by clear(), and refreshAndReplaceInternal().

◆ 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 the initial uppercase letter
string$codeCode denoting the language to try
Returns
string|false The message, or false if it does not exist or on error

Definition at line 1320 of file MessageCache.php.

◆ getParser()

MessageCache::getParser ( )
Returns
Parser

Definition at line 1477 of file MessageCache.php.

Referenced by parse(), and transform().

◆ isDisabled()

MessageCache::isDisabled ( )

Whether DB/cache usage is disabled for determining messages.

If so, this typically indicates either:

  • a) load() failed to find a cached copy nor query the DB
  • b) we are in a special context or error mode that cannot use the DB If the DB is ignored, any derived HTML output or cached objects may be wrong. To avoid long-term cache pollution, TTLs can be adjusted accordingly.
Returns
bool
Since
1.27

Definition at line 1556 of file MessageCache.php.

◆ normalizeKey()

static MessageCache::normalizeKey ( $key)
static

Normalize message key input.

Parameters
string$keyInput message key to be normalized
Returns
string Normalized message key

Definition at line 183 of file MessageCache.php.

◆ parse()

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

Definition at line 1493 of file MessageCache.php.

References $wgTitle, getParser(), NS_SPECIAL, and MediaWiki\Parser\Parser\parse().

◆ refreshAndReplaceInternal()

MessageCache::refreshAndReplaceInternal ( string $code,
array $replacements )
Parameters
string$code
array[]$replacementsList of (title, message key) pairs

Definition at line 825 of file MessageCache.php.

References MapCacheLRU\get(), getCheckKey(), and NS_MEDIAWIKI.

◆ replace()

MessageCache::replace ( $title,
$text )

Updates cache as necessary when message page is changed.

Parameters
string$titleMessage cache key with the initial uppercase letter
string | false$textNew contents of the page (false if deleted)

Definition at line 794 of file MessageCache.php.

References disable(), and figureMessage().

Referenced by updateMessageOverride().

◆ setLogger()

MessageCache::setLogger ( LoggerInterface $logger)

Definition at line 255 of file MessageCache.php.

◆ transform()

MessageCache::transform ( $message,
$interface = false,
$language = null,
PageReference $page = null )
Parameters
string$message
bool$interface
Language | null$language
PageReference | null$page
Returns
string

Definition at line 1454 of file MessageCache.php.

References getParser(), and MediaWiki\Parser\Parser\transformMsg().

◆ updateMessageOverride()

MessageCache::updateMessageOverride ( LinkTarget $linkTarget,
Content $content = null )

Purge message caches when a MediaWiki: page is created, updated, or deleted.

Parameters
LinkTarget$linkTargetMessage page title
Content | null$contentNew content for edit/create, null on deletion
Since
1.29

Definition at line 1631 of file MessageCache.php.

References MediaWiki\Linker\LinkTarget\getDBkey(), and replace().

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MessageCache::CONSTRUCTOR_OPTIONS
Initial value:
= [
MainConfigNames::UseDatabaseMessages,
MainConfigNames::MaxMsgCacheEntrySize,
MainConfigNames::AdaptiveMessageCache,
MainConfigNames::UseXssLanguage,
MainConfigNames::RawHtmlMessages,
]

Options to be included in the ServiceOptions.

Definition at line 68 of file MessageCache.php.

◆ MAX_REQUEST_LANGUAGES

const MessageCache::MAX_REQUEST_LANGUAGES = 10

The size of the MapCacheLRU which stores message data.

The maximum number of languages which can be efficiently loaded in a given request.

Definition at line 80 of file MessageCache.php.


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