71 MainConfigNames::UseDatabaseMessages,
72 MainConfigNames::MaxMsgCacheEntrySize,
73 MainConfigNames::AdaptiveMessageCache,
74 MainConfigNames::UseXssLanguage,
75 MainConfigNames::RawHtmlMessages,
84 private const FOR_UPDATE = 1;
87 private const WAIT_SEC = 15;
89 private const LOCK_TTL = 30;
95 private const WAN_TTL = ExpirationAwareness::TTL_DAY;
112 private $systemMessageNames;
117 private $cacheVolatile = [];
126 private $maxEntrySize;
132 private $useXssLanguage;
135 private $rawHtmlMessages;
141 private $parserOptions;
144 private $parser =
null;
149 private $inParser =
false;
154 private $clusterCache;
160 private $contLangCode;
162 private $contLangConverter;
164 private $langFactory;
166 private $localisationCache;
168 private $languageNameUtils;
170 private $languageFallback;
174 private $parserFactory;
177 private $messageKeyOverrides;
186 $lckey = strtr( $key,
' ',
'_' );
187 if ( $lckey ===
'' ) {
192 if ( ord( $lckey ) < 128 ) {
193 $lckey[0] = strtolower( $lckey[0] );
195 $lckey = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $lckey );
223 LoggerInterface $logger,
232 $this->wanCache = $wanCache;
233 $this->clusterCache = $clusterCache;
234 $this->srvCache = $serverCache;
235 $this->contLang = $contLang;
237 $this->contLangCode = $contLang->
getCode();
238 $this->logger = $logger;
239 $this->langFactory = $langFactory;
240 $this->localisationCache = $localisationCache;
241 $this->languageNameUtils = $languageNameUtils;
242 $this->languageFallback = $languageFallback;
243 $this->hookRunner =
new HookRunner( $hookContainer );
244 $this->parserFactory = $parserFactory;
247 $this->cache =
new MapCacheLRU( self::MAX_REQUEST_LANGUAGES );
250 $this->
disable = !$options->
get( MainConfigNames::UseDatabaseMessages );
251 $this->maxEntrySize = $options->
get( MainConfigNames::MaxMsgCacheEntrySize );
252 $this->adaptive = $options->
get( MainConfigNames::AdaptiveMessageCache );
253 $this->useXssLanguage = $options->
get( MainConfigNames::UseXssLanguage );
254 $this->rawHtmlMessages = $options->
get( MainConfigNames::RawHtmlMessages );
258 $this->logger = $logger;
266 private function getParserOptions() {
267 if ( !$this->parserOptions ) {
268 $context = RequestContext::getMain();
269 $user = $context->getUser();
270 if ( !$user->isSafeToLoad() ) {
274 $po = ParserOptions::newFromAnon();
275 $po->setAllowUnsafeRawHtml(
false );
283 $this->parserOptions->setAllowUnsafeRawHtml(
false );
286 return $this->parserOptions;
295 private function getLocalCache( $code ) {
296 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
298 return $this->srvCache->get( $cacheKey );
307 private function saveToLocalCache( $code, $cache ) {
308 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
309 $this->srvCache->set( $cacheKey, $cache );
332 private function load(
string $code, $mode =
null ) {
334 if ( $this->isLanguageLoaded( $code ) && $mode !== self::FOR_UPDATE ) {
339 if ( $this->disable ) {
340 static $shownDisabled =
false;
341 if ( !$shownDisabled ) {
342 $this->logger->debug( __METHOD__ .
': disabled' );
343 $shownDisabled =
true;
350 return $this->loadUnguarded( $code, $mode );
351 }
catch ( Throwable $e ) {
365 private function loadUnguarded( $code, $mode ) {
372 [ $hash, $hashVolatile ] = $this->getValidationHash( $code );
373 $this->cacheVolatile[$code] = $hashVolatile;
374 $volatilityOnlyStaleness =
false;
377 $cache = $this->getLocalCache( $code );
379 $where[] =
'local cache is empty';
380 } elseif ( !isset( $cache[
'HASH'] ) || $cache[
'HASH'] !== $hash ) {
381 $where[] =
'local cache has the wrong hash';
382 $staleCache = $cache;
383 } elseif ( $this->isCacheExpired( $cache ) ) {
384 $where[] =
'local cache is expired';
385 $staleCache = $cache;
386 } elseif ( $hashVolatile ) {
388 $where[] =
'local cache validation key is expired/volatile';
389 $staleCache = $cache;
390 $volatilityOnlyStaleness =
true;
392 $where[] =
'got from local cache';
393 $this->cache->set( $code, $cache );
399 $cacheKey = $this->clusterCache->makeKey(
'messages', $code );
400 for ( $failedAttempts = 0; $failedAttempts <= 1; $failedAttempts++ ) {
401 if ( $volatilityOnlyStaleness && $staleCache ) {
406 $where[] =
'global cache is presumed expired';
408 $cache = $this->clusterCache->get( $cacheKey );
410 $where[] =
'global cache is empty';
411 } elseif ( $this->isCacheExpired( $cache ) ) {
412 $where[] =
'global cache is expired';
413 $staleCache = $cache;
414 } elseif ( $hashVolatile ) {
416 $where[] =
'global cache is expired/volatile';
417 $staleCache = $cache;
419 $where[] =
'got from global cache';
420 $this->cache->set( $code, $cache );
421 $this->saveToCaches( $cache,
'local-only', $code );
430 $loadStatus = $this->loadFromDBWithMainLock( $code, $where, $mode );
431 if ( $loadStatus ===
true ) {
434 } elseif ( $staleCache ) {
436 $where[] =
'using stale cache';
437 $this->cache->set( $code, $staleCache );
440 } elseif ( $failedAttempts > 0 ) {
441 $where[] =
'failed to find cache after waiting';
446 } elseif ( $loadStatus ===
'cantacquire' ) {
449 $where[] =
'waiting for other thread to complete';
450 [ , $ioError ] = $this->getReentrantScopedLock( $code );
452 $where[] =
'failed waiting';
455 $success = $this->loadFromDBWithLocalLock( $code, $where, $mode );
466 $where[] =
'loading FAILED - cache is disabled';
468 $this->cache->set( $code, [] );
469 $this->logger->error( __METHOD__ .
": Failed to load $code" );
474 if ( !$this->isLanguageLoaded( $code ) ) {
475 throw new LogicException(
"Process cache for '$code' should be set by now." );
478 $info = implode(
', ', $where );
479 $this->logger->debug( __METHOD__ .
": Loading $code... $info" );
490 private function loadFromDBWithMainLock( $code, array &$where, $mode =
null ) {
493 $statusKey = $this->clusterCache->makeKey(
'messages', $code,
'status' );
494 $status = $this->clusterCache->get( $statusKey );
495 if ( $status ===
'error' ) {
496 $where[] =
"could not load; method is still globally disabled";
501 $where[] =
'loading from DB';
507 [ $scopedLock ] = $this->getReentrantScopedLock( $code, 0 );
508 if ( !$scopedLock ) {
509 $where[] =
'could not acquire main lock';
510 return 'cantacquire';
513 $cache = $this->loadFromDB( $code, $mode );
514 $this->cache->set( $code, $cache );
515 $saveSuccess = $this->saveToCaches( $cache,
'all', $code );
517 if ( !$saveSuccess ) {
532 $this->clusterCache->set( $statusKey,
'error', 60 * 5 );
533 $where[] =
'could not save cache, disabled globally for 5 minutes';
535 $where[] =
"could not save global cache";
548 private function loadFromDBWithLocalLock( $code, array &$where, $mode =
null ) {
550 $where[] =
'loading from DB using local lock';
552 $scopedLock = $this->srvCache->getScopedLock(
553 $this->srvCache->makeKey(
'messages', $code ),
559 $cache = $this->loadFromDB( $code, $mode );
560 $this->cache->set( $code, $cache );
561 $this->saveToCaches( $cache,
'local-only', $code );
577 private function loadFromDB( $code, $mode =
null ) {
578 $icp = MediaWikiServices::getInstance()->getConnectionProvider();
580 $dbr = ( $mode === self::FOR_UPDATE ) ? $icp->getPrimaryDatabase() : $icp->getReplicaDatabase();
585 if ( $this->adaptive && $code !== $this->contLangCode ) {
586 if ( !$this->cache->has( $this->contLangCode ) ) {
587 $this->load( $this->contLangCode );
589 $mostused = array_keys( $this->cache->get( $this->contLangCode ) );
590 foreach ( $mostused as $key => $value ) {
591 $mostused[$key] =
"$value/$code";
597 'page_is_redirect' => 0,
600 if ( count( $mostused ) ) {
601 $conds[
'page_title'] = $mostused;
602 } elseif ( $code !== $this->contLangCode ) {
603 $conds[] = $dbr->expr(
606 new LikeValue( $dbr->anyString(),
'/', $code )
611 $conds[] = $dbr->expr(
613 IExpression::NOT_LIKE,
614 new LikeValue( $dbr->anyString(),
'/', $dbr->anyString() )
619 $res = $dbr->newSelectQueryBuilder()
620 ->select( [
'page_title',
'page_latest' ] )
623 ->andWhere( $dbr->expr(
'page_len',
'>', intval( $this->maxEntrySize ) ) )
624 ->caller( __METHOD__ .
"($code)-big" )->fetchResultSet();
625 foreach ( $res as $row ) {
627 if ( $this->adaptive || $this->isMainCacheable( $row->page_title ) ) {
628 $cache[$row->page_title] =
'!TOO BIG';
631 $cache[
'EXCESSIVE'][$row->page_title] = $row->page_latest;
636 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
638 $revQuery = $revisionStore->getQueryInfo( [
'page' ] );
644 $revQuery[
'joins'][
'revision'] = $revQuery[
'joins'][
'page'];
645 unset( $revQuery[
'joins'][
'page'] );
649 $revQuery[
'tables'] = array_merge(
651 array_diff( $revQuery[
'tables'], [
'page' ] )
654 $res = $dbr->newSelectQueryBuilder()
655 ->queryInfo( $revQuery )
658 $dbr->expr(
'page_len',
'<=', intval( $this->maxEntrySize ) ),
659 'page_latest = rev_id'
661 ->caller( __METHOD__ .
"($code)-small" )
662 ->straightJoinOption()
666 [ $cacheableRows, $uncacheableRows ] = $this->separateCacheableRows( $res );
667 $result = $revisionStore->newRevisionsFromBatch( $cacheableRows, [
668 'slots' => [ SlotRecord::MAIN ],
671 $revisions = $result->isOK() ? $result->getValue() : [];
673 foreach ( $cacheableRows as $row ) {
675 $rev = $revisions[$row->rev_id] ??
null;
676 $content = $rev ? $rev->getContent( SlotRecord::MAIN ) :
null;
677 $text = $this->getMessageTextFromContent( $content );
678 }
catch ( TimeoutException $e ) {
680 }
catch ( Exception $ex ) {
684 if ( !is_string( $text ) ) {
686 $this->logger->error(
688 .
": failed to load message page text for {$row->page_title} ($code)"
691 $entry =
' ' . $text;
693 $cache[$row->page_title] = $entry;
696 foreach ( $uncacheableRows as $row ) {
699 $cache[
'EXCESSIVE'][$row->page_title] = $row->page_latest;
708 $cache[
'HASH'] = md5( serialize( $cache ) );
709 $cache[
'EXPIRY'] =
wfTimestamp( TS_MW, time() + self::WAN_TTL );
710 unset( $cache[
'EXCESSIVE'] );
721 private function isLanguageLoaded( $lang ) {
728 return $this->cache->hasField( $lang,
'VERSION' );
742 private function isMainCacheable( $name, $code =
null ) {
744 $name = $this->contLang->lcfirst( $name );
747 if ( strpos( $name,
'conversiontable/' ) === 0 ) {
750 $msg = preg_replace(
'/\/[a-z0-9-]{2,}$/',
'', $name );
752 if ( $code ===
null ) {
754 if ( $this->systemMessageNames ===
null ) {
755 $this->systemMessageNames = array_fill_keys(
756 $this->localisationCache->getSubitemList( $this->contLangCode,
'messages' ),
759 return isset( $this->systemMessageNames[$msg] );
762 return $this->localisationCache->getSubitem( $code,
'messages', $msg ) !==
null;
773 private function separateCacheableRows( $res ) {
774 if ( $this->adaptive ) {
779 $uncacheableRows = [];
780 foreach ( $res as $row ) {
781 if ( $this->isMainCacheable( $row->page_title ) ) {
782 $cacheableRows[] = $row;
784 $uncacheableRows[] = $row;
787 return [ $cacheableRows, $uncacheableRows ];
802 if ( strpos( $title,
'/' ) !==
false && $code === $this->contLangCode ) {
808 if ( $text ===
false ) {
810 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
813 $this->cache->setField( $code, $title,
' ' . $text );
817 DeferredUpdates::addUpdate(
819 DeferredUpdates::PRESEND
829 [ $scopedLock ] = $this->getReentrantScopedLock( $code );
830 if ( !$scopedLock ) {
831 foreach ( $replacements as [ $title ] ) {
832 $this->logger->error(
833 __METHOD__ .
': could not acquire lock to update {title} ({code})',
834 [
'title' => $title,
'code' => $code ] );
842 if ( $this->load( $code, self::FOR_UPDATE ) ) {
843 $cache = $this->cache->get( $code );
846 $cache = $this->loadFromDB( $code, self::FOR_UPDATE );
849 $newTextByTitle = [];
853 $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
854 foreach ( $replacements as [ $title ] ) {
855 $page = $wikiPageFactory->newFromTitle( Title::makeTitle(
NS_MEDIAWIKI, $title ) );
856 $page->loadPageData( IDBAccessObject::READ_LATEST );
857 $text = $this->getMessageTextFromContent( $page->getContent() );
859 $newTextByTitle[$title] = $text ??
'';
861 if ( !is_string( $text ) ) {
862 $cache[$title] =
'!NONEXISTENT';
863 } elseif ( strlen( $text ) > $this->maxEntrySize ) {
864 $cache[$title] =
'!TOO BIG';
865 $newBigTitles[$title] = $page->getLatest();
867 $cache[$title] =
' ' . $text;
874 $cache[
'HASH'] = md5( serialize( $cache + [
'EXCESSIVE' => $newBigTitles ] ) );
876 foreach ( $newBigTitles as $title => $id ) {
878 $this->wanCache->set(
879 $this->bigMessageCacheKey( $cache[
'HASH'], $title ),
880 ' ' . $newTextByTitle[$title],
886 $cache[
'LATEST'] = time();
888 $this->cache->set( $code, $cache );
893 $this->saveToCaches( $cache,
'all', $code );
895 ScopedCallback::consume( $scopedLock );
899 $this->wanCache->touchCheckKey( $this->
getCheckKey( $code ) );
902 $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
903 foreach ( $replacements as [ $title, $msg ] ) {
904 $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
905 $this->hookRunner->onMessageCacheReplace( $title, $newTextByTitle[$title] );
915 private function isCacheExpired( $cache ) {
916 return !isset( $cache[
'VERSION'] ) ||
917 !isset( $cache[
'EXPIRY'] ) ||
931 private function saveToCaches( array $cache, $dest, $code =
false ) {
932 if ( $dest ===
'all' ) {
933 $cacheKey = $this->clusterCache->makeKey(
'messages', $code );
934 $success = $this->clusterCache->set( $cacheKey, $cache );
935 $this->setValidationHash( $code, $cache );
940 $this->saveToLocalCache( $code, $cache );
951 private function getValidationHash( $code ) {
953 $value = $this->wanCache->get(
954 $this->wanCache->makeKey(
'messages', $code,
'hash',
'v1' ),
956 [ $this->getCheckKey( $code ) ]
960 $hash = $value[
'hash'];
961 if ( ( time() - $value[
'latest'] ) < WANObjectCache::TTL_MINUTE ) {
967 $expired = ( $curTTL < 0 );
975 return [ $hash, $expired ];
988 private function setValidationHash( $code, array $cache ) {
989 $this->wanCache->set(
990 $this->wanCache->makeKey(
'messages', $code,
'hash',
'v1' ),
992 'hash' => $cache[
'HASH'],
993 'latest' => $cache[
'LATEST'] ?? 0
995 WANObjectCache::TTL_INDEFINITE
1005 private function getReentrantScopedLock( $code, $timeout = self::WAIT_SEC ) {
1006 $key = $this->clusterCache->makeKey(
'messages', $code );
1008 $watchPoint = $this->clusterCache->watchErrors();
1009 $scopedLock = $this->clusterCache->getScopedLock(
1015 $error = ( !$scopedLock && $this->clusterCache->getLastError( $watchPoint ) );
1017 return [ $scopedLock, $error ];
1056 public function get( $key, $useDB =
true, $language =
null, &$usedKey =
'' ) {
1057 if ( is_int( $key ) ) {
1059 $key = (string)$key;
1060 } elseif ( !is_string( $key ) ) {
1061 throw new TypeError(
'Message key must be a string' );
1062 } elseif ( $key ===
'' ) {
1067 $language ??= $this->contLang;
1068 $language = $this->getLanguageObject( $language );
1071 $lckey = self::normalizeKey( $key );
1074 if ( $this->messageKeyOverrides ===
null ) {
1075 $this->messageKeyOverrides = [];
1076 $this->hookRunner->onMessageCacheFetchOverrides( $this->messageKeyOverrides );
1079 if ( isset( $this->messageKeyOverrides[$lckey] ) ) {
1080 $override = $this->messageKeyOverrides[$lckey];
1084 if ( is_string( $override ) ) {
1087 $lckey = $override( $lckey, $this, $language, $useDB );
1091 $this->hookRunner->onMessageCache__get( $lckey );
1096 $message = $this->getMessageFromFallbackChain(
1103 if ( $message ===
false ) {
1104 $parts = explode(
'/', $lckey );
1108 if ( count( $parts ) === 2 && $parts[1] !==
'' ) {
1109 $message = $this->localisationCache->getSubitem( $parts[1],
'messages', $parts[0] ) ??
false;
1114 if ( $message !==
false ) {
1116 $message = str_replace(
1153 private function getLanguageObject( $langcode ) {
1154 # Identify which language to get or create a language object for.
1155 # Using is_object here due to Stub objects.
1156 if ( is_object( $langcode ) ) {
1157 # Great, we already have the object (hopefully)!
1161 wfDeprecated( __METHOD__ .
' with not a Language object in $langcode',
'1.43' );
1162 if ( $langcode ===
true || $langcode === $this->contLangCode ) {
1163 # $langcode is the language code of the wikis content language object.
1164 # or it is a boolean and value is true
1165 return $this->contLang;
1169 if ( $langcode ===
false || $langcode ===
$wgLang->getCode() ) {
1170 # $langcode is the language code of user language object.
1171 # or it was a boolean and value is false
1175 $validCodes = array_keys( $this->languageNameUtils->getLanguageNames() );
1176 if ( in_array( $langcode, $validCodes ) ) {
1177 # $langcode corresponds to a valid language.
1178 return $this->langFactory->getLanguage( $langcode );
1181 # $langcode is a string, but not a valid language code; use content language.
1182 $this->logger->debug(
'Invalid language code passed to' . __METHOD__ .
', falling back to content language.' );
1183 return $this->contLang;
1198 private function getMessageFromFallbackChain( $lang, $lckey, $useDB ) {
1202 $message = $this->getMessageForLang( $lang, $lckey, $useDB, $alreadyTried );
1203 if ( $message !==
false ) {
1208 $message = $this->getMessageForLang( $this->contLang, $lckey, $useDB, $alreadyTried );
1222 private function getMessageForLang( $lang, $lckey, $useDB, &$alreadyTried ) {
1223 $langcode = $lang->getCode();
1227 $uckey = $this->contLang->ucfirst( $lckey );
1229 if ( !isset( $alreadyTried[$langcode] ) ) {
1231 $this->getMessagePageName( $langcode, $uckey ),
1234 if ( $message !==
false ) {
1237 $alreadyTried[$langcode] =
true;
1246 if ( $langcode ===
'qqx' ) {
1249 $langcode ===
'x-xss' &&
1250 $this->useXssLanguage &&
1251 !in_array( $lckey, $this->rawHtmlMessages,
true )
1253 $xssViaInnerHtml =
"<script>alert('$lckey')</script>";
1254 $xssViaAttribute =
'">' . $xssViaInnerHtml .
'<x y="';
1255 return $xssViaInnerHtml . $xssViaAttribute .
'($*)';
1259 [ $defaultMessage, $messageSource ] =
1260 $this->localisationCache->getSubitemWithSource( $langcode,
'messages', $lckey );
1261 if ( $messageSource === $langcode ) {
1262 return $defaultMessage;
1267 $fallbackChain = $this->languageFallback->getAll( $langcode );
1269 foreach ( $fallbackChain as $code ) {
1270 if ( isset( $alreadyTried[$code] ) ) {
1276 $this->getMessagePageName( $code, $uckey ), $code );
1278 if ( $message !==
false ) {
1281 $alreadyTried[$code] =
true;
1285 if ( $code === $messageSource ) {
1286 return $defaultMessage;
1291 return $defaultMessage ??
false;
1301 private function getMessagePageName( $langcode, $uckey ) {
1302 if ( $langcode === $this->contLangCode ) {
1306 return "$uckey/$langcode";
1326 $this->load( $code );
1328 $entry = $this->cache->getField( $code, $title );
1330 if ( $entry !==
null ) {
1332 if ( substr( $entry, 0, 1 ) ===
' ' ) {
1334 return (
string)substr( $entry, 1 );
1335 } elseif ( $entry ===
'!NONEXISTENT' ) {
1341 $entry = $this->loadCachedMessagePageEntry(
1344 $this->cache->getField( $code,
'HASH' )
1348 if ( !$this->isMainCacheable( $title, $code ) ) {
1352 $entry = $this->loadCachedMessagePageEntry(
1355 $this->cache->getField( $code,
'HASH' )
1358 if ( $entry ===
null || substr( $entry, 0, 1 ) !==
' ' ) {
1362 $this->hookRunner->onMessagesPreLoad( $title, $message, $code );
1363 if ( $message !==
false ) {
1364 $this->cache->setField( $code, $title,
' ' . $message );
1366 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
1373 if ( $entry !==
false && substr( $entry, 0, 1 ) ===
' ' ) {
1374 if ( $this->cacheVolatile[$code] ) {
1376 $this->logger->debug(
1377 __METHOD__ .
': loading volatile key \'{titleKey}\'',
1378 [
'titleKey' => $title,
'code' => $code ] );
1380 $this->cache->setField( $code, $title, $entry );
1383 return (
string)substr( $entry, 1 );
1386 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
1397 private function loadCachedMessagePageEntry( $dbKey, $code, $hash ) {
1398 $fname = __METHOD__;
1399 return $this->srvCache->getWithSetCallback(
1400 $this->srvCache->makeKey(
'messages-big', $hash, $dbKey ),
1401 BagOStuff::TTL_HOUR,
1402 function () use ( $code, $dbKey, $hash, $fname ) {
1403 return $this->wanCache->getWithSetCallback(
1404 $this->bigMessageCacheKey( $hash, $dbKey ),
1406 function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code, $fname ) {
1408 $setOpts += Database::getCacheSetOptions(
1409 MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase()
1415 $revision = MediaWikiServices::getInstance()
1416 ->getRevisionLookup()
1417 ->getKnownCurrentRevision( $title );
1421 return '!NONEXISTENT';
1423 $content = $revision->getContent( SlotRecord::MAIN );
1425 $message = $this->getMessageTextFromContent( $content );
1427 $this->logger->warning(
1428 $fname .
': failed to load page text for \'{titleKey}\'',
1429 [
'titleKey' => $dbKey,
'code' => $code ]
1434 if ( !is_string( $message ) ) {
1439 return '!NONEXISTENT';
1442 return ' ' . $message;
1458 if ( $this->inParser || !str_contains( $message,
'{{' ) ) {
1463 $popts = $this->getParserOptions();
1464 $popts->setInterfaceMessage( $interface );
1465 $popts->setTargetLanguage( $language );
1467 $userlang = $popts->setUserLang( $language );
1468 $this->inParser =
true;
1469 $message = $parser->
transformMsg( $message, $popts, $page );
1470 $this->inParser =
false;
1471 $popts->setUserLang( $userlang );
1480 if ( !$this->parser ) {
1481 $this->parser = $this->parserFactory->create();
1484 return $this->parser;
1496 $interface =
false, $language =
null
1500 if ( $this->inParser ) {
1501 return htmlspecialchars( $text );
1505 $popts = $this->getParserOptions();
1506 $popts->setInterfaceMessage( $interface );
1508 if ( is_string( $language ) ) {
1509 $language = $this->langFactory->getLanguage( $language );
1511 $popts->setTargetLanguage( $language );
1514 $logger = LoggerFactory::getInstance(
'GlobalTitleFail' );
1516 __METHOD__ .
' called with no title set.',
1517 [
'exception' =>
new RuntimeException ]
1525 $page = PageReferenceValue::localReference(
1527 'Badtitle/title not set in ' . __METHOD__
1531 $this->inParser =
true;
1532 $res = $parser->
parse( $text, $page, $popts, $linestart );
1533 $this->inParser =
false;
1559 return $this->disable;
1568 $langs = $this->languageNameUtils->getLanguageNames();
1569 foreach ( $langs as $code => $_ ) {
1570 $this->wanCache->touchCheckKey( $this->
getCheckKey( $code ) );
1572 $this->cache->clear();
1580 $pieces = explode(
'/', $key );
1581 if ( count( $pieces ) < 2 ) {
1582 return [ $key, $this->contLangCode ];
1585 $lang = array_pop( $pieces );
1586 if ( !$this->languageNameUtils->getLanguageName(
1588 LanguageNameUtils::AUTONYMS,
1589 LanguageNameUtils::DEFINED
1591 return [ $key, $this->contLangCode ];
1594 $message = implode(
'/', $pieces );
1596 return [ $message, $lang ];
1609 $this->load( $code );
1610 if ( !$this->cache->has( $code ) ) {
1615 $cache = $this->cache->get( $code );
1616 unset( $cache[
'VERSION'] );
1617 unset( $cache[
'EXPIRY'] );
1618 unset( $cache[
'EXCESSIVE'] );
1620 $cache = array_diff( $cache, [
'!NONEXISTENT' ] );
1623 return array_map( [ $this->contLang,
'lcfirst' ], array_keys( $cache ) );
1635 $msgText = $this->getMessageTextFromContent( $content ) ??
false;
1639 if ( $this->contLangConverter->hasVariants() ) {
1640 $this->contLangConverter->updateConversionTable( $linkTarget );
1649 return $this->wanCache->makeKey(
'messages', $code );
1656 private function getMessageTextFromContent(
Content $content =
null ) {
1664 $msgText = $content->getWikitextForTransclusion();
1665 if ( $msgText ===
false || $msgText ===
null ) {
1668 $this->logger->warning(
1669 __METHOD__ .
": message content doesn't provide wikitext "
1670 .
"(content model: " . $content->getModel() .
")" );
1685 private function bigMessageCacheKey( $hash, $title ) {
1686 return $this->wanCache->makeKey(
'messages-big', $hash, $title );