78 MainConfigNames::UseDatabaseMessages,
79 MainConfigNames::MaxMsgCacheEntrySize,
80 MainConfigNames::AdaptiveMessageCache,
81 MainConfigNames::UseXssLanguage,
82 MainConfigNames::RawHtmlMessages,
91 private const FOR_UPDATE = 1;
94 private const WAIT_SEC = 15;
96 private const LOCK_TTL = 30;
101 private const WAN_TTL = ExpirationAwareness::TTL_DAY;
118 private $systemMessageNames;
123 private $cacheVolatile = [];
132 private $maxEntrySize;
138 private $useXssLanguage;
141 private $rawHtmlMessages;
147 private $parserOptions;
150 private $parser =
null;
155 private $inParser =
false;
160 private $clusterCache;
166 private $contLangCode;
168 private $contLangConverter;
170 private $langFactory;
172 private $localisationCache;
174 private $languageNameUtils;
176 private $languageFallback;
180 private $parserFactory;
183 private $messageKeyOverrides;
192 $lckey = strtr( $key,
' ',
'_' );
193 if ( $lckey ===
'' ) {
198 if ( ord( $lckey ) < 128 ) {
199 $lckey[0] = strtolower( $lckey[0] );
201 $lckey = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $lckey );
229 LoggerInterface $logger,
238 $this->wanCache = $wanCache;
239 $this->clusterCache = $clusterCache;
240 $this->srvCache = $serverCache;
241 $this->contLang = $contLang;
243 $this->contLangCode = $contLang->
getCode();
244 $this->logger = $logger;
245 $this->langFactory = $langFactory;
246 $this->localisationCache = $localisationCache;
247 $this->languageNameUtils = $languageNameUtils;
248 $this->languageFallback = $languageFallback;
249 $this->hookRunner =
new HookRunner( $hookContainer );
250 $this->parserFactory = $parserFactory;
253 $this->cache =
new MapCacheLRU( self::MAX_REQUEST_LANGUAGES );
256 $this->
disable = !$options->
get( MainConfigNames::UseDatabaseMessages );
257 $this->maxEntrySize = $options->
get( MainConfigNames::MaxMsgCacheEntrySize );
258 $this->adaptive = $options->
get( MainConfigNames::AdaptiveMessageCache );
259 $this->useXssLanguage = $options->
get( MainConfigNames::UseXssLanguage );
260 $this->rawHtmlMessages = $options->
get( MainConfigNames::RawHtmlMessages );
264 $this->logger = $logger;
272 private function getParserOptions() {
273 if ( !$this->parserOptions ) {
274 $context = RequestContext::getMain();
275 $user = $context->getUser();
276 if ( !$user->isSafeToLoad() ) {
280 $po = ParserOptions::newFromAnon();
281 $po->setAllowUnsafeRawHtml(
false );
285 $this->parserOptions = ParserOptions::newFromContext( $context );
289 $this->parserOptions->setAllowUnsafeRawHtml(
false );
292 return $this->parserOptions;
301 private function getLocalCache( $code ) {
302 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
304 return $this->srvCache->get( $cacheKey );
313 private function saveToLocalCache( $code, $cache ) {
314 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
315 $this->srvCache->set( $cacheKey, $cache );
338 private function load(
string $code, $mode =
null ) {
340 if ( $this->isLanguageLoaded( $code ) && $mode !== self::FOR_UPDATE ) {
345 if ( $this->disable ) {
346 static $shownDisabled =
false;
347 if ( !$shownDisabled ) {
348 $this->logger->debug( __METHOD__ .
': disabled' );
349 $shownDisabled =
true;
356 return $this->loadUnguarded( $code, $mode );
357 }
catch ( Throwable $e ) {
371 private function loadUnguarded( $code, $mode ) {
378 [ $hash, $hashVolatile ] = $this->getValidationHash( $code );
379 $this->cacheVolatile[$code] = $hashVolatile;
380 $volatilityOnlyStaleness =
false;
383 $cache = $this->getLocalCache( $code );
385 $where[] =
'local cache is empty';
386 } elseif ( !isset( $cache[
'HASH'] ) || $cache[
'HASH'] !== $hash ) {
387 $where[] =
'local cache has the wrong hash';
388 $staleCache = $cache;
389 } elseif ( $this->isCacheExpired( $cache ) ) {
390 $where[] =
'local cache is expired';
391 $staleCache = $cache;
392 } elseif ( $hashVolatile ) {
394 $where[] =
'local cache validation key is expired/volatile';
395 $staleCache = $cache;
396 $volatilityOnlyStaleness =
true;
398 $where[] =
'got from local cache';
399 $this->cache->set( $code, $cache );
405 $cacheKey = $this->clusterCache->makeKey(
'messages', $code );
406 for ( $failedAttempts = 0; $failedAttempts <= 1; $failedAttempts++ ) {
407 if ( $volatilityOnlyStaleness && $staleCache ) {
412 $where[] =
'global cache is presumed expired';
414 $cache = $this->clusterCache->get( $cacheKey );
416 $where[] =
'global cache is empty';
417 } elseif ( $this->isCacheExpired( $cache ) ) {
418 $where[] =
'global cache is expired';
419 $staleCache = $cache;
420 } elseif ( $hashVolatile ) {
422 $where[] =
'global cache is expired/volatile';
423 $staleCache = $cache;
425 $where[] =
'got from global cache';
426 $this->cache->set( $code, $cache );
427 $this->saveToCaches( $cache,
'local-only', $code );
436 $loadStatus = $this->loadFromDBWithMainLock( $code, $where, $mode );
437 if ( $loadStatus ===
true ) {
440 } elseif ( $staleCache ) {
442 $where[] =
'using stale cache';
443 $this->cache->set( $code, $staleCache );
446 } elseif ( $failedAttempts > 0 ) {
447 $where[] =
'failed to find cache after waiting';
452 } elseif ( $loadStatus ===
'cantacquire' ) {
455 $where[] =
'waiting for other thread to complete';
456 [ , $ioError ] = $this->getReentrantScopedLock( $code );
458 $where[] =
'failed waiting';
461 $success = $this->loadFromDBWithLocalLock( $code, $where, $mode );
472 $where[] =
'loading FAILED - cache is disabled';
474 $this->cache->set( $code, [] );
475 $this->logger->error( __METHOD__ .
": Failed to load $code" );
480 if ( !$this->isLanguageLoaded( $code ) ) {
481 throw new LogicException(
"Process cache for '$code' should be set by now." );
484 $info = implode(
', ', $where );
485 $this->logger->debug( __METHOD__ .
": Loading $code... $info" );
496 private function loadFromDBWithMainLock( $code, array &$where, $mode =
null ) {
499 $statusKey = $this->clusterCache->makeKey(
'messages', $code,
'status' );
500 $status = $this->clusterCache->get( $statusKey );
501 if ( $status ===
'error' ) {
502 $where[] =
"could not load; method is still globally disabled";
507 $where[] =
'loading from DB';
513 [ $scopedLock ] = $this->getReentrantScopedLock( $code, 0 );
514 if ( !$scopedLock ) {
515 $where[] =
'could not acquire main lock';
516 return 'cantacquire';
519 $cache = $this->loadFromDB( $code, $mode );
520 $this->cache->set( $code, $cache );
521 $saveSuccess = $this->saveToCaches( $cache,
'all', $code );
523 if ( !$saveSuccess ) {
538 $this->clusterCache->set( $statusKey,
'error', 60 * 5 );
539 $where[] =
'could not save cache, disabled globally for 5 minutes';
541 $where[] =
"could not save global cache";
554 private function loadFromDBWithLocalLock( $code, array &$where, $mode =
null ) {
556 $where[] =
'loading from DB using local lock';
558 $scopedLock = $this->srvCache->getScopedLock(
559 $this->srvCache->makeKey(
'messages', $code ),
565 $cache = $this->loadFromDB( $code, $mode );
566 $this->cache->set( $code, $cache );
567 $this->saveToCaches( $cache,
'local-only', $code );
583 private function loadFromDB( $code, $mode =
null ) {
584 $icp = MediaWikiServices::getInstance()->getConnectionProvider();
586 $dbr = ( $mode === self::FOR_UPDATE ) ? $icp->getPrimaryDatabase() : $icp->getReplicaDatabase();
591 if ( $this->adaptive && $code !== $this->contLangCode ) {
592 if ( !$this->cache->has( $this->contLangCode ) ) {
593 $this->load( $this->contLangCode );
595 $mostused = array_keys( $this->cache->get( $this->contLangCode ) );
596 foreach ( $mostused as $key => $value ) {
597 $mostused[$key] =
"$value/$code";
604 'page_is_redirect' => 0,
607 if ( count( $mostused ) ) {
608 $conds[
'page_title'] = $mostused;
609 } elseif ( $code !== $this->contLangCode ) {
610 $conds[] = $dbr->expr(
613 new LikeValue( $dbr->anyString(),
'/', $code )
618 $conds[] = $dbr->expr(
620 IExpression::NOT_LIKE,
621 new LikeValue( $dbr->anyString(),
'/', $dbr->anyString() )
626 $res = $dbr->newSelectQueryBuilder()
627 ->select( [
'page_title',
'page_latest' ] )
630 ->andWhere( $dbr->expr(
'page_len',
'>', intval( $this->maxEntrySize ) ) )
631 ->caller( __METHOD__ .
"($code)-big" )->fetchResultSet();
632 foreach ( $res as $row ) {
634 if ( $this->adaptive || $this->isMainCacheable( $row->page_title ) ) {
635 $cache[$row->page_title] =
'!TOO BIG';
638 $cache[
'EXCESSIVE'][$row->page_title] = $row->page_latest;
643 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
645 $revQuery = $revisionStore->getQueryInfo( [
'page' ] );
651 $revQuery[
'joins'][
'revision'] = $revQuery[
'joins'][
'page'];
652 unset( $revQuery[
'joins'][
'page'] );
656 $revQuery[
'tables'] = array_merge(
658 array_diff( $revQuery[
'tables'], [
'page' ] )
661 $res = $dbr->newSelectQueryBuilder()
662 ->queryInfo( $revQuery )
665 $dbr->expr(
'page_len',
'<=', intval( $this->maxEntrySize ) ),
666 'page_latest = rev_id'
668 ->caller( __METHOD__ .
"($code)-small" )
669 ->straightJoinOption()
673 [ $cacheableRows, $uncacheableRows ] = $this->separateCacheableRows( $res );
674 $result = $revisionStore->newRevisionsFromBatch( $cacheableRows, [
675 'slots' => [ SlotRecord::MAIN ],
678 $revisions = $result->isOK() ? $result->getValue() : [];
680 foreach ( $cacheableRows as $row ) {
682 $rev = $revisions[$row->rev_id] ??
null;
683 $content = $rev ? $rev->getContent( SlotRecord::MAIN ) :
null;
684 $text = $this->getMessageTextFromContent( $content );
685 }
catch ( TimeoutException $e ) {
687 }
catch ( Exception $ex ) {
691 if ( !is_string( $text ) ) {
693 $this->logger->error(
695 .
": failed to load message page text for {$row->page_title} ($code)"
698 $entry =
' ' . $text;
700 $cache[$row->page_title] = $entry;
703 foreach ( $uncacheableRows as $row ) {
706 $cache[
'EXCESSIVE'][$row->page_title] = $row->page_latest;
715 $cache[
'HASH'] = md5( serialize( $cache ) );
716 $cache[
'EXPIRY'] =
wfTimestamp( TS_MW, time() + self::WAN_TTL );
717 unset( $cache[
'EXCESSIVE'] );
728 private function isLanguageLoaded( $lang ) {
735 return $this->cache->hasField( $lang,
'VERSION' );
749 private function isMainCacheable( $name, $code =
null ) {
751 $name = $this->contLang->lcfirst( $name );
754 if ( strpos( $name,
'conversiontable/' ) === 0 ) {
757 $msg = preg_replace(
'/\/[a-z0-9-]{2,}$/',
'', $name );
759 if ( $code ===
null ) {
761 if ( $this->systemMessageNames ===
null ) {
762 $this->systemMessageNames = array_fill_keys(
763 $this->localisationCache->getSubitemList( $this->contLangCode,
'messages' ),
766 return isset( $this->systemMessageNames[$msg] );
769 return $this->localisationCache->getSubitem( $code,
'messages', $msg ) !==
null;
780 private function separateCacheableRows( $res ) {
781 if ( $this->adaptive ) {
786 $uncacheableRows = [];
787 foreach ( $res as $row ) {
788 if ( $this->isMainCacheable( $row->page_title ) ) {
789 $cacheableRows[] = $row;
791 $uncacheableRows[] = $row;
794 return [ $cacheableRows, $uncacheableRows ];
809 if ( strpos( $title,
'/' ) !==
false && $code === $this->contLangCode ) {
815 if ( $text ===
false ) {
817 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
820 $this->cache->setField( $code, $title,
' ' . $text );
824 DeferredUpdates::addUpdate(
826 DeferredUpdates::PRESEND
836 [ $scopedLock ] = $this->getReentrantScopedLock( $code );
837 if ( !$scopedLock ) {
838 foreach ( $replacements as [ $title ] ) {
839 $this->logger->error(
840 __METHOD__ .
': could not acquire lock to update {title} ({code})',
841 [
'title' => $title,
'code' => $code ] );
849 if ( $this->load( $code, self::FOR_UPDATE ) ) {
850 $cache = $this->cache->get( $code );
853 $cache = $this->loadFromDB( $code, self::FOR_UPDATE );
856 $newTextByTitle = [];
860 $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
861 foreach ( $replacements as [ $title ] ) {
862 $page = $wikiPageFactory->newFromTitle( Title::makeTitle(
NS_MEDIAWIKI, $title ) );
863 $page->loadPageData( IDBAccessObject::READ_LATEST );
864 $text = $this->getMessageTextFromContent( $page->getContent() );
866 $newTextByTitle[$title] = $text ??
'';
868 if ( !is_string( $text ) ) {
869 $cache[$title] =
'!NONEXISTENT';
870 } elseif ( strlen( $text ) > $this->maxEntrySize ) {
871 $cache[$title] =
'!TOO BIG';
872 $newBigTitles[$title] = $page->getLatest();
874 $cache[$title] =
' ' . $text;
881 $cache[
'HASH'] = md5( serialize( $cache + [
'EXCESSIVE' => $newBigTitles ] ) );
883 foreach ( $newBigTitles as $title => $id ) {
885 $this->wanCache->set(
886 $this->bigMessageCacheKey( $cache[
'HASH'], $title ),
887 ' ' . $newTextByTitle[$title],
893 $cache[
'LATEST'] = time();
895 $this->cache->set( $code, $cache );
900 $this->saveToCaches( $cache,
'all', $code );
902 ScopedCallback::consume( $scopedLock );
906 $this->wanCache->touchCheckKey( $this->
getCheckKey( $code ) );
909 $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
910 foreach ( $replacements as [ $title, $msg ] ) {
911 $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
912 $this->hookRunner->onMessageCacheReplace( $title, $newTextByTitle[$title] );
922 private function isCacheExpired( $cache ) {
923 return !isset( $cache[
'VERSION'] ) ||
924 !isset( $cache[
'EXPIRY'] ) ||
938 private function saveToCaches( array $cache, $dest, $code =
false ) {
939 if ( $dest ===
'all' ) {
940 $cacheKey = $this->clusterCache->makeKey(
'messages', $code );
941 $success = $this->clusterCache->set( $cacheKey, $cache );
942 $this->setValidationHash( $code, $cache );
947 $this->saveToLocalCache( $code, $cache );
958 private function getValidationHash( $code ) {
960 $value = $this->wanCache->get(
961 $this->wanCache->makeKey(
'messages', $code,
'hash',
'v1' ),
963 [ $this->getCheckKey( $code ) ]
967 $hash = $value[
'hash'];
968 if ( ( time() - $value[
'latest'] ) < WANObjectCache::TTL_MINUTE ) {
974 $expired = ( $curTTL < 0 );
982 return [ $hash, $expired ];
995 private function setValidationHash( $code, array $cache ) {
996 $this->wanCache->set(
997 $this->wanCache->makeKey(
'messages', $code,
'hash',
'v1' ),
999 'hash' => $cache[
'HASH'],
1000 'latest' => $cache[
'LATEST'] ?? 0
1002 WANObjectCache::TTL_INDEFINITE
1012 private function getReentrantScopedLock( $code, $timeout = self::WAIT_SEC ) {
1013 $key = $this->clusterCache->makeKey(
'messages', $code );
1015 $watchPoint = $this->clusterCache->watchErrors();
1016 $scopedLock = $this->clusterCache->getScopedLock(
1022 $error = ( !$scopedLock && $this->clusterCache->getLastError( $watchPoint ) );
1024 return [ $scopedLock, $error ];
1063 public function get( $key, $useDB =
true, $language =
null, &$usedKey =
'' ) {
1064 if ( is_int( $key ) ) {
1066 $key = (string)$key;
1067 } elseif ( !is_string( $key ) ) {
1068 throw new TypeError(
'Message key must be a string' );
1069 } elseif ( $key ===
'' ) {
1074 $language ??= $this->contLang;
1075 $language = $this->getLanguageObject( $language );
1078 $lckey = self::normalizeKey( $key );
1081 if ( $this->messageKeyOverrides ===
null ) {
1082 $this->messageKeyOverrides = [];
1083 $this->hookRunner->onMessageCacheFetchOverrides( $this->messageKeyOverrides );
1086 if ( isset( $this->messageKeyOverrides[$lckey] ) ) {
1087 $override = $this->messageKeyOverrides[$lckey];
1091 if ( is_string( $override ) ) {
1094 $lckey = $override( $lckey, $this, $language, $useDB );
1098 $this->hookRunner->onMessageCache__get( $lckey );
1103 $message = $this->getMessageFromFallbackChain(
1110 if ( $message ===
false ) {
1111 $parts = explode(
'/', $lckey );
1115 if ( count( $parts ) === 2 && $parts[1] !==
'' ) {
1116 $message = $this->localisationCache->getSubitem( $parts[1],
'messages', $parts[0] ) ??
false;
1121 if ( $message !==
false ) {
1123 $message = str_replace(
1160 private function getLanguageObject( $langcode ) {
1161 # Identify which language to get or create a language object for.
1162 # Using is_object here due to Stub objects.
1163 if ( is_object( $langcode ) ) {
1164 # Great, we already have the object (hopefully)!
1168 wfDeprecated( __METHOD__ .
' with not a Language object in $langcode',
'1.43' );
1169 if ( $langcode ===
true || $langcode === $this->contLangCode ) {
1170 # $langcode is the language code of the wikis content language object.
1171 # or it is a boolean and value is true
1172 return $this->contLang;
1176 if ( $langcode ===
false || $langcode ===
$wgLang->getCode() ) {
1177 # $langcode is the language code of user language object.
1178 # or it was a boolean and value is false
1182 $validCodes = array_keys( $this->languageNameUtils->getLanguageNames() );
1183 if ( in_array( $langcode, $validCodes ) ) {
1184 # $langcode corresponds to a valid language.
1185 return $this->langFactory->getLanguage( $langcode );
1188 # $langcode is a string, but not a valid language code; use content language.
1189 $this->logger->debug(
'Invalid language code passed to' . __METHOD__ .
', falling back to content language.' );
1190 return $this->contLang;
1205 private function getMessageFromFallbackChain( $lang, $lckey, $useDB ) {
1209 $message = $this->getMessageForLang( $lang, $lckey, $useDB, $alreadyTried );
1210 if ( $message !==
false ) {
1215 $message = $this->getMessageForLang( $this->contLang, $lckey, $useDB, $alreadyTried );
1229 private function getMessageForLang( $lang, $lckey, $useDB, &$alreadyTried ) {
1230 $langcode = $lang->getCode();
1234 $uckey = $this->contLang->ucfirst( $lckey );
1236 if ( !isset( $alreadyTried[$langcode] ) ) {
1238 $this->getMessagePageName( $langcode, $uckey ),
1241 if ( $message !==
false ) {
1244 $alreadyTried[$langcode] =
true;
1253 if ( $langcode ===
'qqx' ) {
1256 $langcode ===
'x-xss' &&
1257 $this->useXssLanguage &&
1258 !in_array( $lckey, $this->rawHtmlMessages,
true )
1260 $xssViaInnerHtml =
"<script>alert('$lckey')</script>";
1261 $xssViaAttribute =
'">' . $xssViaInnerHtml .
'<x y="';
1262 return $xssViaInnerHtml . $xssViaAttribute .
'($*)';
1266 [ $defaultMessage, $messageSource ] =
1267 $this->localisationCache->getSubitemWithSource( $langcode,
'messages', $lckey );
1268 if ( $messageSource === $langcode ) {
1269 return $defaultMessage;
1274 $fallbackChain = $this->languageFallback->getAll( $langcode );
1276 foreach ( $fallbackChain as $code ) {
1277 if ( isset( $alreadyTried[$code] ) ) {
1283 $this->getMessagePageName( $code, $uckey ), $code );
1285 if ( $message !==
false ) {
1288 $alreadyTried[$code] =
true;
1292 if ( $code === $messageSource ) {
1293 return $defaultMessage;
1298 return $defaultMessage ??
false;
1308 private function getMessagePageName( $langcode, $uckey ) {
1309 if ( $langcode === $this->contLangCode ) {
1313 return "$uckey/$langcode";
1333 $this->load( $code );
1335 $entry = $this->cache->getField( $code, $title );
1337 if ( $entry !==
null ) {
1339 if ( substr( $entry, 0, 1 ) ===
' ' ) {
1341 return (
string)substr( $entry, 1 );
1342 } elseif ( $entry ===
'!NONEXISTENT' ) {
1348 $entry = $this->loadCachedMessagePageEntry(
1351 $this->cache->getField( $code,
'HASH' )
1355 if ( !$this->isMainCacheable( $title, $code ) ) {
1359 $entry = $this->loadCachedMessagePageEntry(
1362 $this->cache->getField( $code,
'HASH' )
1365 if ( $entry ===
null || substr( $entry, 0, 1 ) !==
' ' ) {
1369 $this->hookRunner->onMessagesPreLoad( $title, $message, $code );
1370 if ( $message !==
false ) {
1371 $this->cache->setField( $code, $title,
' ' . $message );
1373 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
1380 if ( $entry !==
false && substr( $entry, 0, 1 ) ===
' ' ) {
1381 if ( $this->cacheVolatile[$code] ) {
1383 $this->logger->debug(
1384 __METHOD__ .
': loading volatile key \'{titleKey}\'',
1385 [
'titleKey' => $title,
'code' => $code ] );
1387 $this->cache->setField( $code, $title, $entry );
1390 return (
string)substr( $entry, 1 );
1393 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
1404 private function loadCachedMessagePageEntry( $dbKey, $code, $hash ) {
1405 $fname = __METHOD__;
1406 return $this->srvCache->getWithSetCallback(
1407 $this->srvCache->makeKey(
'messages-big', $hash, $dbKey ),
1408 BagOStuff::TTL_HOUR,
1409 function () use ( $code, $dbKey, $hash, $fname ) {
1410 return $this->wanCache->getWithSetCallback(
1411 $this->bigMessageCacheKey( $hash, $dbKey ),
1413 function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code, $fname ) {
1415 $setOpts += Database::getCacheSetOptions(
1416 MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase()
1422 $revision = MediaWikiServices::getInstance()
1423 ->getRevisionLookup()
1424 ->getKnownCurrentRevision( $title );
1428 return '!NONEXISTENT';
1430 $content = $revision->getContent( SlotRecord::MAIN );
1432 $message = $this->getMessageTextFromContent( $content );
1434 $this->logger->warning(
1435 $fname .
': failed to load page text for \'{titleKey}\'',
1436 [
'titleKey' => $dbKey,
'code' => $code ]
1441 if ( !is_string( $message ) ) {
1446 return '!NONEXISTENT';
1449 return ' ' . $message;
1465 if ( $this->inParser || !str_contains( $message,
'{{' ) ) {
1470 $popts = $this->getParserOptions();
1471 $popts->setInterfaceMessage( $interface );
1472 $popts->setTargetLanguage( $language );
1474 $userlang = $popts->setUserLang( $language );
1475 $this->inParser =
true;
1476 $message = $parser->
transformMsg( $message, $popts, $page );
1477 $this->inParser =
false;
1478 $popts->setUserLang( $userlang );
1487 if ( !$this->parser ) {
1488 $this->parser = $this->parserFactory->create();
1491 return $this->parser;
1503 $interface =
false, $language =
null
1508 if ( $this->inParser ) {
1509 return htmlspecialchars( $text );
1513 $popts = $this->getParserOptions();
1514 $popts->setInterfaceMessage( $interface );
1516 if ( is_string( $language ) ) {
1517 $language = $this->langFactory->getLanguage( $language );
1519 $popts->setTargetLanguage( $language );
1522 $logger = LoggerFactory::getInstance(
'GlobalTitleFail' );
1524 __METHOD__ .
' called with no title set.',
1525 [
'exception' =>
new RuntimeException ]
1533 $page = PageReferenceValue::localReference(
1535 'Badtitle/title not set in ' . __METHOD__
1539 $this->inParser =
true;
1540 $res = $parser->
parse( $text, $page, $popts, $linestart );
1541 $this->inParser =
false;
1567 return $this->disable;
1576 $langs = $this->languageNameUtils->getLanguageNames();
1577 foreach ( $langs as $code => $_ ) {
1578 $this->wanCache->touchCheckKey( $this->
getCheckKey( $code ) );
1580 $this->cache->clear();
1588 $pieces = explode(
'/', $key );
1589 if ( count( $pieces ) < 2 ) {
1590 return [ $key, $this->contLangCode ];
1593 $lang = array_pop( $pieces );
1594 if ( !$this->languageNameUtils->getLanguageName(
1596 LanguageNameUtils::AUTONYMS,
1597 LanguageNameUtils::DEFINED
1599 return [ $key, $this->contLangCode ];
1602 $message = implode(
'/', $pieces );
1604 return [ $message, $lang ];
1617 $this->load( $code );
1618 if ( !$this->cache->has( $code ) ) {
1623 $cache = $this->cache->get( $code );
1624 unset( $cache[
'VERSION'] );
1625 unset( $cache[
'EXPIRY'] );
1626 unset( $cache[
'EXCESSIVE'] );
1628 $cache = array_diff( $cache, [
'!NONEXISTENT' ] );
1631 return array_map( [ $this->contLang,
'lcfirst' ], array_keys( $cache ) );
1643 $msgText = $this->getMessageTextFromContent( $content ) ??
false;
1647 if ( $this->contLangConverter->hasVariants() ) {
1648 $this->contLangConverter->updateConversionTable( $linkTarget );
1657 return $this->wanCache->makeKey(
'messages', $code );
1664 private function getMessageTextFromContent( ?
Content $content =
null ) {
1666 if ( $content && $content->isRedirect() ) {
1669 } elseif ( $content ) {
1674 $msgText = $content->getWikitextForTransclusion();
1675 if ( $msgText ===
false || $msgText ===
null ) {
1678 $this->logger->warning(
1679 __METHOD__ .
": message content doesn't provide wikitext "
1680 .
"(content model: " . $content->getModel() .
")" );
1695 private function bigMessageCacheKey( $hash, $title ) {
1696 return $this->wanCache->makeKey(
'messages-big', $hash, $title );