69 MainConfigNames::UseDatabaseMessages,
70 MainConfigNames::MaxMsgCacheEntrySize,
71 MainConfigNames::AdaptiveMessageCache,
72 MainConfigNames::UseXssLanguage,
73 MainConfigNames::RawHtmlMessages,
82 private const FOR_UPDATE = 1;
85 private const WAIT_SEC = 15;
87 private const LOCK_TTL = 30;
93 private const WAN_TTL = ExpirationAwareness::TTL_DAY;
110 private $systemMessageNames;
115 private $cacheVolatile = [];
124 private $maxEntrySize;
130 private $useXssLanguage;
133 private $rawHtmlMessages;
139 private $parserOptions;
142 private $parser =
null;
147 private $inParser =
false;
152 private $clusterCache;
158 private $contLangCode;
160 private $contLangConverter;
162 private $langFactory;
164 private $localisationCache;
166 private $languageNameUtils;
168 private $languageFallback;
172 private $parserFactory;
175 private $messageKeyOverrides;
184 $lckey = strtr( $key,
' ',
'_' );
185 if ( $lckey ===
'' ) {
190 if ( ord( $lckey ) < 128 ) {
191 $lckey[0] = strtolower( $lckey[0] );
193 $lckey = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $lckey );
221 LoggerInterface $logger,
230 $this->wanCache = $wanCache;
231 $this->clusterCache = $clusterCache;
232 $this->srvCache = $serverCache;
233 $this->contLang = $contLang;
235 $this->contLangCode = $contLang->
getCode();
236 $this->logger = $logger;
237 $this->langFactory = $langFactory;
238 $this->localisationCache = $localisationCache;
239 $this->languageNameUtils = $languageNameUtils;
240 $this->languageFallback = $languageFallback;
241 $this->hookRunner =
new HookRunner( $hookContainer );
242 $this->parserFactory = $parserFactory;
245 $this->cache =
new MapCacheLRU( self::MAX_REQUEST_LANGUAGES );
248 $this->
disable = !$options->
get( MainConfigNames::UseDatabaseMessages );
249 $this->maxEntrySize = $options->
get( MainConfigNames::MaxMsgCacheEntrySize );
250 $this->adaptive = $options->
get( MainConfigNames::AdaptiveMessageCache );
251 $this->useXssLanguage = $options->
get( MainConfigNames::UseXssLanguage );
252 $this->rawHtmlMessages = $options->
get( MainConfigNames::RawHtmlMessages );
256 $this->logger = $logger;
264 private function getParserOptions() {
265 if ( !$this->parserOptions ) {
266 $context = RequestContext::getMain();
267 $user = $context->getUser();
268 if ( !$user->isSafeToLoad() ) {
272 $po = ParserOptions::newFromAnon();
273 $po->setAllowUnsafeRawHtml(
false );
281 $this->parserOptions->setAllowUnsafeRawHtml(
false );
284 return $this->parserOptions;
293 private function getLocalCache( $code ) {
294 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
296 return $this->srvCache->get( $cacheKey );
305 private function saveToLocalCache( $code, $cache ) {
306 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
307 $this->srvCache->set( $cacheKey, $cache );
330 private function load(
string $code, $mode =
null ) {
332 if ( $this->isLanguageLoaded( $code ) && $mode !== self::FOR_UPDATE ) {
337 if ( $this->disable ) {
338 static $shownDisabled =
false;
339 if ( !$shownDisabled ) {
340 $this->logger->debug( __METHOD__ .
': disabled' );
341 $shownDisabled =
true;
348 return $this->loadUnguarded( $code, $mode );
349 }
catch ( Throwable $e ) {
363 private function loadUnguarded( $code, $mode ) {
370 [ $hash, $hashVolatile ] = $this->getValidationHash( $code );
371 $this->cacheVolatile[$code] = $hashVolatile;
372 $volatilityOnlyStaleness =
false;
375 $cache = $this->getLocalCache( $code );
377 $where[] =
'local cache is empty';
378 } elseif ( !isset( $cache[
'HASH'] ) || $cache[
'HASH'] !== $hash ) {
379 $where[] =
'local cache has the wrong hash';
380 $staleCache = $cache;
381 } elseif ( $this->isCacheExpired( $cache ) ) {
382 $where[] =
'local cache is expired';
383 $staleCache = $cache;
384 } elseif ( $hashVolatile ) {
386 $where[] =
'local cache validation key is expired/volatile';
387 $staleCache = $cache;
388 $volatilityOnlyStaleness =
true;
390 $where[] =
'got from local cache';
391 $this->cache->set( $code, $cache );
397 $cacheKey = $this->clusterCache->makeKey(
'messages', $code );
398 for ( $failedAttempts = 0; $failedAttempts <= 1; $failedAttempts++ ) {
399 if ( $volatilityOnlyStaleness && $staleCache ) {
404 $where[] =
'global cache is presumed expired';
406 $cache = $this->clusterCache->get( $cacheKey );
408 $where[] =
'global cache is empty';
409 } elseif ( $this->isCacheExpired( $cache ) ) {
410 $where[] =
'global cache is expired';
411 $staleCache = $cache;
412 } elseif ( $hashVolatile ) {
414 $where[] =
'global cache is expired/volatile';
415 $staleCache = $cache;
417 $where[] =
'got from global cache';
418 $this->cache->set( $code, $cache );
419 $this->saveToCaches( $cache,
'local-only', $code );
428 $loadStatus = $this->loadFromDBWithMainLock( $code, $where, $mode );
429 if ( $loadStatus ===
true ) {
432 } elseif ( $staleCache ) {
434 $where[] =
'using stale cache';
435 $this->cache->set( $code, $staleCache );
438 } elseif ( $failedAttempts > 0 ) {
439 $where[] =
'failed to find cache after waiting';
444 } elseif ( $loadStatus ===
'cantacquire' ) {
447 $where[] =
'waiting for other thread to complete';
448 [ , $ioError ] = $this->getReentrantScopedLock( $code );
450 $where[] =
'failed waiting';
453 $success = $this->loadFromDBWithLocalLock( $code, $where, $mode );
464 $where[] =
'loading FAILED - cache is disabled';
466 $this->cache->set( $code, [] );
467 $this->logger->error( __METHOD__ .
": Failed to load $code" );
472 if ( !$this->isLanguageLoaded( $code ) ) {
473 throw new LogicException(
"Process cache for '$code' should be set by now." );
476 $info = implode(
', ', $where );
477 $this->logger->debug( __METHOD__ .
": Loading $code... $info" );
488 private function loadFromDBWithMainLock( $code, array &$where, $mode =
null ) {
491 $statusKey = $this->clusterCache->makeKey(
'messages', $code,
'status' );
492 $status = $this->clusterCache->get( $statusKey );
493 if ( $status ===
'error' ) {
494 $where[] =
"could not load; method is still globally disabled";
499 $where[] =
'loading from DB';
505 [ $scopedLock ] = $this->getReentrantScopedLock( $code, 0 );
506 if ( !$scopedLock ) {
507 $where[] =
'could not acquire main lock';
508 return 'cantacquire';
511 $cache = $this->loadFromDB( $code, $mode );
512 $this->cache->set( $code, $cache );
513 $saveSuccess = $this->saveToCaches( $cache,
'all', $code );
515 if ( !$saveSuccess ) {
530 $this->clusterCache->set( $statusKey,
'error', 60 * 5 );
531 $where[] =
'could not save cache, disabled globally for 5 minutes';
533 $where[] =
"could not save global cache";
546 private function loadFromDBWithLocalLock( $code, array &$where, $mode =
null ) {
548 $where[] =
'loading from DB using local lock';
550 $scopedLock = $this->srvCache->getScopedLock(
551 $this->srvCache->makeKey(
'messages', $code ),
557 $cache = $this->loadFromDB( $code, $mode );
558 $this->cache->set( $code, $cache );
559 $this->saveToCaches( $cache,
'local-only', $code );
575 private function loadFromDB( $code, $mode =
null ) {
576 $icp = MediaWikiServices::getInstance()->getConnectionProvider();
578 $dbr = ( $mode === self::FOR_UPDATE ) ? $icp->getPrimaryDatabase() : $icp->getReplicaDatabase();
583 if ( $this->adaptive && $code !== $this->contLangCode ) {
584 if ( !$this->cache->has( $this->contLangCode ) ) {
585 $this->load( $this->contLangCode );
587 $mostused = array_keys( $this->cache->get( $this->contLangCode ) );
588 foreach ( $mostused as $key => $value ) {
589 $mostused[$key] =
"$value/$code";
595 'page_is_redirect' => 0,
598 if ( count( $mostused ) ) {
599 $conds[
'page_title'] = $mostused;
600 } elseif ( $code !== $this->contLangCode ) {
601 $conds[] = $dbr->expr(
604 new LikeValue( $dbr->anyString(),
'/', $code )
609 $conds[] = $dbr->expr(
611 IExpression::NOT_LIKE,
612 new LikeValue( $dbr->anyString(),
'/', $dbr->anyString() )
617 $res = $dbr->newSelectQueryBuilder()
618 ->select( [
'page_title',
'page_latest' ] )
621 ->andWhere( [
'page_len > ' . intval( $this->maxEntrySize ) ] )
622 ->caller( __METHOD__ .
"($code)-big" )->fetchResultSet();
623 foreach ( $res as $row ) {
625 if ( $this->adaptive || $this->isMainCacheable( $row->page_title ) ) {
626 $cache[$row->page_title] =
'!TOO BIG';
629 $cache[
'EXCESSIVE'][$row->page_title] = $row->page_latest;
634 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
636 $revQuery = $revisionStore->getQueryInfo( [
'page' ] );
642 $revQuery[
'joins'][
'revision'] = $revQuery[
'joins'][
'page'];
643 unset( $revQuery[
'joins'][
'page'] );
647 $revQuery[
'tables'] = array_merge(
649 array_diff( $revQuery[
'tables'], [
'page' ] )
655 array_merge( $conds, [
656 'page_len <= ' . intval( $this->maxEntrySize ),
657 'page_latest = rev_id'
659 __METHOD__ .
"($code)-small",
665 [ $cacheableRows, $uncacheableRows ] = $this->separateCacheableRows( $res );
666 $result = $revisionStore->newRevisionsFromBatch( $cacheableRows, [
667 'slots' => [ SlotRecord::MAIN ],
670 $revisions = $result->isOK() ? $result->getValue() : [];
672 foreach ( $cacheableRows as $row ) {
674 $rev = $revisions[$row->rev_id] ??
null;
675 $content = $rev ? $rev->getContent( SlotRecord::MAIN ) :
null;
676 $text = $this->getMessageTextFromContent( $content );
677 }
catch ( TimeoutException $e ) {
679 }
catch ( Exception $ex ) {
683 if ( !is_string( $text ) ) {
685 $this->logger->error(
687 .
": failed to load message page text for {$row->page_title} ($code)"
690 $entry =
' ' . $text;
692 $cache[$row->page_title] = $entry;
695 foreach ( $uncacheableRows as $row ) {
698 $cache[
'EXCESSIVE'][$row->page_title] = $row->page_latest;
707 $cache[
'HASH'] = md5( serialize( $cache ) );
708 $cache[
'EXPIRY'] =
wfTimestamp( TS_MW, time() + self::WAN_TTL );
709 unset( $cache[
'EXCESSIVE'] );
720 private function isLanguageLoaded( $lang ) {
727 return $this->cache->hasField( $lang,
'VERSION' );
741 private function isMainCacheable( $name, $code =
null ) {
743 $name = $this->contLang->lcfirst( $name );
746 if ( strpos( $name,
'conversiontable/' ) === 0 ) {
749 $msg = preg_replace(
'/\/[a-z0-9-]{2,}$/',
'', $name );
751 if ( $code ===
null ) {
753 if ( $this->systemMessageNames ===
null ) {
754 $this->systemMessageNames = array_fill_keys(
755 $this->localisationCache->getSubitemList( $this->contLangCode,
'messages' ),
758 return isset( $this->systemMessageNames[$msg] );
761 return $this->localisationCache->getSubitem( $code,
'messages', $msg ) !==
null;
772 private function separateCacheableRows( $res ) {
773 if ( $this->adaptive ) {
778 $uncacheableRows = [];
779 foreach ( $res as $row ) {
780 if ( $this->isMainCacheable( $row->page_title ) ) {
781 $cacheableRows[] = $row;
783 $uncacheableRows[] = $row;
786 return [ $cacheableRows, $uncacheableRows ];
801 if ( strpos( $title,
'/' ) !==
false && $code === $this->contLangCode ) {
807 if ( $text ===
false ) {
809 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
812 $this->cache->setField( $code, $title,
' ' . $text );
816 DeferredUpdates::addUpdate(
818 DeferredUpdates::PRESEND
828 [ $scopedLock ] = $this->getReentrantScopedLock( $code );
829 if ( !$scopedLock ) {
830 foreach ( $replacements as [ $title ] ) {
831 $this->logger->error(
832 __METHOD__ .
': could not acquire lock to update {title} ({code})',
833 [
'title' => $title,
'code' => $code ] );
841 if ( $this->load( $code, self::FOR_UPDATE ) ) {
842 $cache = $this->cache->get( $code );
845 $cache = $this->loadFromDB( $code, self::FOR_UPDATE );
848 $newTextByTitle = [];
852 $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
853 foreach ( $replacements as [ $title ] ) {
854 $page = $wikiPageFactory->newFromTitle( Title::makeTitle(
NS_MEDIAWIKI, $title ) );
855 $page->loadPageData( IDBAccessObject::READ_LATEST );
856 $text = $this->getMessageTextFromContent( $page->getContent() );
858 $newTextByTitle[$title] = $text ??
'';
860 if ( !is_string( $text ) ) {
861 $cache[$title] =
'!NONEXISTENT';
862 } elseif ( strlen( $text ) > $this->maxEntrySize ) {
863 $cache[$title] =
'!TOO BIG';
864 $newBigTitles[$title] = $page->getLatest();
866 $cache[$title] =
' ' . $text;
873 $cache[
'HASH'] = md5( serialize( $cache + [
'EXCESSIVE' => $newBigTitles ] ) );
875 foreach ( $newBigTitles as $title => $id ) {
877 $this->wanCache->set(
878 $this->bigMessageCacheKey( $cache[
'HASH'], $title ),
879 ' ' . $newTextByTitle[$title],
885 $cache[
'LATEST'] = time();
887 $this->cache->set( $code, $cache );
892 $this->saveToCaches( $cache,
'all', $code );
894 ScopedCallback::consume( $scopedLock );
898 $this->wanCache->touchCheckKey( $this->
getCheckKey( $code ) );
901 $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
902 foreach ( $replacements as [ $title, $msg ] ) {
903 $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
904 $this->hookRunner->onMessageCacheReplace( $title, $newTextByTitle[$title] );
914 private function isCacheExpired( $cache ) {
915 return !isset( $cache[
'VERSION'] ) ||
916 !isset( $cache[
'EXPIRY'] ) ||
930 private function saveToCaches( array $cache, $dest, $code =
false ) {
931 if ( $dest ===
'all' ) {
932 $cacheKey = $this->clusterCache->makeKey(
'messages', $code );
933 $success = $this->clusterCache->set( $cacheKey, $cache );
934 $this->setValidationHash( $code, $cache );
939 $this->saveToLocalCache( $code, $cache );
950 private function getValidationHash( $code ) {
952 $value = $this->wanCache->get(
953 $this->wanCache->makeKey(
'messages', $code,
'hash',
'v1' ),
955 [ $this->getCheckKey( $code ) ]
959 $hash = $value[
'hash'];
960 if ( ( time() - $value[
'latest'] ) < WANObjectCache::TTL_MINUTE ) {
966 $expired = ( $curTTL < 0 );
974 return [ $hash, $expired ];
987 private function setValidationHash( $code, array $cache ) {
988 $this->wanCache->set(
989 $this->wanCache->makeKey(
'messages', $code,
'hash',
'v1' ),
991 'hash' => $cache[
'HASH'],
992 'latest' => $cache[
'LATEST'] ?? 0
994 WANObjectCache::TTL_INDEFINITE
1004 private function getReentrantScopedLock( $code, $timeout = self::WAIT_SEC ) {
1005 $key = $this->clusterCache->makeKey(
'messages', $code );
1007 $watchPoint = $this->clusterCache->watchErrors();
1008 $scopedLock = $this->clusterCache->getScopedLock(
1014 $error = ( !$scopedLock && $this->clusterCache->getLastError( $watchPoint ) );
1016 return [ $scopedLock, $error ];
1051 public function get( $key, $useDB =
true, $langcode = true ) {
1052 if ( is_int( $key ) ) {
1054 $key = (string)$key;
1055 } elseif ( !is_string( $key ) ) {
1056 throw new TypeError(
'Message key must be a string' );
1057 } elseif ( $key ===
'' ) {
1062 $language = $this->getLanguageObject( $langcode );
1065 $lckey = self::normalizeKey( $key );
1068 if ( $this->messageKeyOverrides ===
null ) {
1069 $this->messageKeyOverrides = [];
1070 $this->hookRunner->onMessageCacheFetchOverrides( $this->messageKeyOverrides );
1073 if ( isset( $this->messageKeyOverrides[$lckey] ) ) {
1074 $override = $this->messageKeyOverrides[$lckey];
1078 if ( is_string( $override ) ) {
1081 $lckey = $override( $lckey, $this, $language, $useDB );
1085 $this->hookRunner->onMessageCache__get( $lckey );
1088 $message = $this->getMessageFromFallbackChain(
1095 if ( $message ===
false ) {
1096 $parts = explode(
'/', $lckey );
1100 if ( count( $parts ) === 2 && $parts[1] !==
'' ) {
1101 $message = $this->localisationCache->getSubitem( $parts[1],
'messages', $parts[0] ) ??
false;
1106 if ( $message !==
false ) {
1108 $message = str_replace(
1145 private function getLanguageObject( $langcode ) {
1146 # Identify which language to get or create a language object for.
1147 # Using is_object here due to Stub objects.
1148 if ( is_object( $langcode ) ) {
1149 # Great, we already have the object (hopefully)!
1153 if ( $langcode ===
true || $langcode === $this->contLangCode ) {
1154 # $langcode is the language code of the wikis content language object.
1155 # or it is a boolean and value is true
1156 return $this->contLang;
1160 if ( $langcode ===
false || $langcode ===
$wgLang->getCode() ) {
1161 # $langcode is the language code of user language object.
1162 # or it was a boolean and value is false
1166 $validCodes = array_keys( $this->languageNameUtils->getLanguageNames() );
1167 if ( in_array( $langcode, $validCodes ) ) {
1168 # $langcode corresponds to a valid language.
1169 return $this->langFactory->getLanguage( $langcode );
1172 # $langcode is a string, but not a valid language code; use content language.
1173 $this->logger->debug(
'Invalid language code passed to' . __METHOD__ .
', falling back to content language.' );
1174 return $this->contLang;
1189 private function getMessageFromFallbackChain( $lang, $lckey, $useDB ) {
1193 $message = $this->getMessageForLang( $lang, $lckey, $useDB, $alreadyTried );
1194 if ( $message !==
false ) {
1199 $message = $this->getMessageForLang( $this->contLang, $lckey, $useDB, $alreadyTried );
1213 private function getMessageForLang( $lang, $lckey, $useDB, &$alreadyTried ) {
1214 $langcode = $lang->getCode();
1218 $uckey = $this->contLang->ucfirst( $lckey );
1220 if ( !isset( $alreadyTried[$langcode] ) ) {
1222 $this->getMessagePageName( $langcode, $uckey ),
1225 if ( $message !==
false ) {
1228 $alreadyTried[$langcode] =
true;
1237 if ( $langcode ===
'qqx' ) {
1240 $langcode ===
'x-xss' &&
1241 $this->useXssLanguage &&
1242 !in_array( $lckey, $this->rawHtmlMessages,
true )
1244 $xssViaInnerHtml =
"<script>alert('$lckey')</script>";
1245 $xssViaAttribute =
'">' . $xssViaInnerHtml .
'<x y="';
1246 return $xssViaInnerHtml . $xssViaAttribute .
'($*)';
1250 [ $defaultMessage, $messageSource ] =
1251 $this->localisationCache->getSubitemWithSource( $langcode,
'messages', $lckey );
1252 if ( $messageSource === $langcode ) {
1253 return $defaultMessage;
1258 $fallbackChain = $this->languageFallback->getAll( $langcode );
1260 foreach ( $fallbackChain as $code ) {
1261 if ( isset( $alreadyTried[$code] ) ) {
1267 $this->getMessagePageName( $code, $uckey ), $code );
1269 if ( $message !==
false ) {
1272 $alreadyTried[$code] =
true;
1276 if ( $code === $messageSource ) {
1277 return $defaultMessage;
1282 return $defaultMessage ??
false;
1292 private function getMessagePageName( $langcode, $uckey ) {
1293 if ( $langcode === $this->contLangCode ) {
1297 return "$uckey/$langcode";
1317 $this->load( $code );
1319 $entry = $this->cache->getField( $code, $title );
1321 if ( $entry !==
null ) {
1323 if ( substr( $entry, 0, 1 ) ===
' ' ) {
1325 return (
string)substr( $entry, 1 );
1326 } elseif ( $entry ===
'!NONEXISTENT' ) {
1332 $entry = $this->loadCachedMessagePageEntry(
1335 $this->cache->getField( $code,
'HASH' )
1339 if ( !$this->isMainCacheable( $title, $code ) ) {
1343 $entry = $this->loadCachedMessagePageEntry(
1346 $this->cache->getField( $code,
'HASH' )
1349 if ( $entry ===
null || substr( $entry, 0, 1 ) !==
' ' ) {
1353 $this->hookRunner->onMessagesPreLoad( $title, $message, $code );
1354 if ( $message !==
false ) {
1355 $this->cache->setField( $code, $title,
' ' . $message );
1357 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
1364 if ( $entry !==
false && substr( $entry, 0, 1 ) ===
' ' ) {
1365 if ( $this->cacheVolatile[$code] ) {
1367 $this->logger->debug(
1368 __METHOD__ .
': loading volatile key \'{titleKey}\'',
1369 [
'titleKey' => $title,
'code' => $code ] );
1371 $this->cache->setField( $code, $title, $entry );
1374 return (
string)substr( $entry, 1 );
1377 $this->cache->setField( $code, $title,
'!NONEXISTENT' );
1388 private function loadCachedMessagePageEntry( $dbKey, $code, $hash ) {
1389 $fname = __METHOD__;
1390 return $this->srvCache->getWithSetCallback(
1391 $this->srvCache->makeKey(
'messages-big', $hash, $dbKey ),
1392 BagOStuff::TTL_HOUR,
1393 function () use ( $code, $dbKey, $hash, $fname ) {
1394 return $this->wanCache->getWithSetCallback(
1395 $this->bigMessageCacheKey( $hash, $dbKey ),
1397 function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code, $fname ) {
1399 $setOpts += Database::getCacheSetOptions(
1400 MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase()
1406 $revision = MediaWikiServices::getInstance()
1407 ->getRevisionLookup()
1408 ->getKnownCurrentRevision( $title );
1412 return '!NONEXISTENT';
1414 $content = $revision->getContent( SlotRecord::MAIN );
1416 $message = $this->getMessageTextFromContent( $content );
1418 $this->logger->warning(
1419 $fname .
': failed to load page text for \'{titleKey}\'',
1420 [
'titleKey' => $dbKey,
'code' => $code ]
1425 if ( !is_string( $message ) ) {
1430 return '!NONEXISTENT';
1433 return ' ' . $message;
1449 if ( $this->inParser || !str_contains( $message,
'{{' ) ) {
1454 $popts = $this->getParserOptions();
1455 $popts->setInterfaceMessage( $interface );
1456 $popts->setTargetLanguage( $language );
1458 $userlang = $popts->setUserLang( $language );
1459 $this->inParser =
true;
1460 $message = $parser->
transformMsg( $message, $popts, $page );
1461 $this->inParser =
false;
1462 $popts->setUserLang( $userlang );
1471 if ( !$this->parser ) {
1472 $this->parser = $this->parserFactory->create();
1475 return $this->parser;
1487 $interface =
false, $language =
null
1491 if ( $this->inParser ) {
1492 return htmlspecialchars( $text );
1496 $popts = $this->getParserOptions();
1497 $popts->setInterfaceMessage( $interface );
1499 if ( is_string( $language ) ) {
1500 $language = $this->langFactory->getLanguage( $language );
1502 $popts->setTargetLanguage( $language );
1505 $logger = LoggerFactory::getInstance(
'GlobalTitleFail' );
1507 __METHOD__ .
' called with no title set.',
1508 [
'exception' =>
new RuntimeException ]
1516 $page = PageReferenceValue::localReference(
1518 'Badtitle/title not set in ' . __METHOD__
1522 $this->inParser =
true;
1523 $res = $parser->
parse( $text, $page, $popts, $linestart );
1524 $this->inParser =
false;
1550 return $this->disable;
1559 $langs = $this->languageNameUtils->getLanguageNames();
1560 foreach ( $langs as $code => $_ ) {
1561 $this->wanCache->touchCheckKey( $this->
getCheckKey( $code ) );
1563 $this->cache->clear();
1571 $pieces = explode(
'/', $key );
1572 if ( count( $pieces ) < 2 ) {
1573 return [ $key, $this->contLangCode ];
1576 $lang = array_pop( $pieces );
1577 if ( !$this->languageNameUtils->getLanguageName(
1579 LanguageNameUtils::AUTONYMS,
1580 LanguageNameUtils::DEFINED
1582 return [ $key, $this->contLangCode ];
1585 $message = implode(
'/', $pieces );
1587 return [ $message, $lang ];
1600 $this->load( $code );
1601 if ( !$this->cache->has( $code ) ) {
1606 $cache = $this->cache->get( $code );
1607 unset( $cache[
'VERSION'] );
1608 unset( $cache[
'EXPIRY'] );
1609 unset( $cache[
'EXCESSIVE'] );
1611 $cache = array_diff( $cache, [
'!NONEXISTENT' ] );
1614 return array_map( [ $this->contLang,
'lcfirst' ], array_keys( $cache ) );
1626 $msgText = $this->getMessageTextFromContent( $content ) ??
false;
1630 if ( $this->contLangConverter->hasVariants() ) {
1631 $this->contLangConverter->updateConversionTable( $linkTarget );
1640 return $this->wanCache->makeKey(
'messages', $code );
1647 private function getMessageTextFromContent(
Content $content =
null ) {
1655 $msgText = $content->getWikitextForTransclusion();
1656 if ( $msgText ===
false || $msgText ===
null ) {
1659 $this->logger->warning(
1660 __METHOD__ .
": message content doesn't provide wikitext "
1661 .
"(content model: " . $content->getModel() .
")" );
1676 private function bigMessageCacheKey( $hash, $title ) {
1677 return $this->wanCache->makeKey(
'messages-big', $hash, $title );