protected $clusterCache;
/** @var BagOStuff */
protected $srvCache;
+ /** @var Language */
+ protected $contLang;
/**
* Singleton instance
public static function singleton() {
if ( self::$instance === null ) {
global $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgUseLocalMessageCache;
+ $services = MediaWikiServices::getInstance();
self::$instance = new self(
- MediaWikiServices::getInstance()->getMainWANObjectCache(),
+ $services->getMainWANObjectCache(),
wfGetMessageCacheStorage(),
$wgUseLocalMessageCache
- ? MediaWikiServices::getInstance()->getLocalServerObjectCache()
+ ? $services->getLocalServerObjectCache()
: new EmptyBagOStuff(),
$wgUseDatabaseMessages,
- $wgMsgCacheExpiry
+ $wgMsgCacheExpiry,
+ $services->getContentLanguage()
);
}
* @return string Normalized message key
*/
public static function normalizeKey( $key ) {
- global $wgContLang;
-
$lckey = strtr( $key, ' ', '_' );
if ( ord( $lckey ) < 128 ) {
$lckey[0] = strtolower( $lckey[0] );
} else {
- $lckey = $wgContLang->lcfirst( $lckey );
+ $lckey = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $lckey );
}
return $lckey;
* @param BagOStuff $serverCache
* @param bool $useDB Whether to look for message overrides (e.g. MediaWiki: pages)
* @param int $expiry Lifetime for cache. @see $mExpiry.
+ * @param Language|null $contLang Content language of site
*/
public function __construct(
WANObjectCache $wanCache,
BagOStuff $clusterCache,
BagOStuff $serverCache,
$useDB,
- $expiry
+ $expiry,
+ Language $contLang = null
) {
$this->wanCache = $wanCache;
$this->clusterCache = $clusterCache;
$this->mDisable = !$useDB;
$this->mExpiry = $expiry;
+ $this->contLang = $contLang ?? MediaWikiServices::getInstance()->getContentLanguage();
}
/**
* (2) memcached
* (3) from the database.
*
- * When succesfully loading from (2) or (3), all higher level caches are
+ * 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 succesfully populated,
+ * 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.
*
if ( !$success ) {
$where[] = 'loading FAILED - cache is disabled';
$this->mDisable = true;
- $this->cache->set( $code, null );
+ $this->cache->set( $code, [] );
wfDebugLog( 'MessageCacheError', __METHOD__ . ": Failed to load $code\n" );
# This used to throw an exception, but that led to nasty side effects like
# the whole wiki being instantly down if the memcached server died
// (b) Update the shared caches in a deferred update with a fresh DB snapshot
DeferredUpdates::addCallableUpdate(
function () use ( $title, $msg, $code ) {
- global $wgContLang, $wgMaxMsgCacheEntrySize;
+ global $wgMaxMsgCacheEntrySize;
// Allow one caller at a time to avoid race conditions
$scopedLock = $this->getReentrantScopedLock(
$this->clusterCache->makeKey( 'messages', $code )
// Purge the message in the message blob store
$resourceloader = RequestContext::getMain()->getOutput()->getResourceLoader();
$blobStore = $resourceloader->getMessageBlobStore();
- $blobStore->updateMessage( $wgContLang->lcfirst( $msg ) );
+ $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
Hooks::run( 'MessageCacheReplace', [ $title, $text ] );
},
* @return string|bool The message, or false if not found
*/
protected function getMessageFromFallbackChain( $lang, $lckey, $useDB ) {
- global $wgContLang;
-
$alreadyTried = [];
// First try the requested language.
}
// Now try checking the site language.
- $message = $this->getMessageForLang( $wgContLang, $lckey, $useDB, $alreadyTried );
+ $message = $this->getMessageForLang( $this->contLang, $lckey, $useDB, $alreadyTried );
return $message;
}
* @return string|bool The message, or false if not found
*/
private function getMessageForLang( $lang, $lckey, $useDB, &$alreadyTried ) {
- global $wgContLang;
-
$langcode = $lang->getCode();
// Try checking the database for the requested language
if ( $useDB ) {
- $uckey = $wgContLang->ucfirst( $lckey );
+ $uckey = $this->contLang->ucfirst( $lckey );
if ( !isset( $alreadyTried[$langcode] ) ) {
$message = $this->getMsgFromNamespace(
* @return array Array of message keys (strings)
*/
public function getAllMessageKeys( $code ) {
- global $wgContLang;
-
$this->load( $code );
if ( !$this->cache->has( $code ) ) {
// Apparently load() failed
$cache = array_diff( $cache, [ '!NONEXISTENT' ] );
// Keys may appear with a capital first letter. lcfirst them.
- return array_map( [ $wgContLang, 'lcfirst' ], array_keys( $cache ) );
+ return array_map( [ $this->contLang, 'lcfirst' ], array_keys( $cache ) );
}
/**
* @since 1.29
*/
public function updateMessageOverride( Title $title, Content $content = null ) {
- global $wgContLang;
-
$msgText = $this->getMessageTextFromContent( $content );
if ( $msgText === null ) {
$msgText = false; // treat as not existing
$this->replace( $title->getDBkey(), $msgText );
- if ( $wgContLang->hasVariants() ) {
- $wgContLang->updateConversionTable( $title );
+ if ( $this->contLang->hasVariants() ) {
+ $this->contLang->updateConversionTable( $title );
}
}