38 use Psr\Log\LoggerAwareInterface;
39 use Psr\Log\LoggerInterface;
42 use Wikimedia\RequestTimeout\TimeoutException;
43 use Wikimedia\ScopedCallback;
49 define(
'MSG_CACHE_VERSION', 2 );
61 MainConfigNames::UseDatabaseMessages,
62 MainConfigNames::MaxMsgCacheEntrySize,
63 MainConfigNames::AdaptiveMessageCache,
72 private const FOR_UPDATE = 1;
75 private const WAIT_SEC = 15;
77 private const LOCK_TTL = 30;
83 private const WAN_TTL = IExpiringStore::TTL_DAY;
100 private $systemMessageNames;
105 private $cacheVolatile = [];
114 private $maxEntrySize;
123 private $parserOptions;
130 private $inParser =
false;
135 private $clusterCache;
141 private $contLangCode;
143 private $contLangConverter;
145 private $langFactory;
147 private $localisationCache;
149 private $languageNameUtils;
151 private $languageFallback;
156 private $messageKeyOverrides;
165 $lckey = strtr( $key,
' ',
'_' );
166 if ( $lckey ===
'' ) {
171 if ( ord( $lckey ) < 128 ) {
172 $lckey[0] = strtolower( $lckey[0] );
174 $lckey = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $lckey );
201 LoggerInterface $logger,
209 $this->wanCache = $wanCache;
210 $this->clusterCache = $clusterCache;
211 $this->srvCache = $serverCache;
212 $this->contLang = $contLang;
214 $this->contLangCode = $contLang->
getCode();
215 $this->logger = $logger;
216 $this->langFactory = $langFactory;
217 $this->localisationCache = $localisationCache;
218 $this->languageNameUtils = $languageNameUtils;
219 $this->languageFallback = $languageFallback;
220 $this->hookRunner =
new HookRunner( $hookContainer );
223 $this->cache =
new MapCacheLRU( self::MAX_REQUEST_LANGUAGES );
226 $this->
disable = !$options->
get( MainConfigNames::UseDatabaseMessages );
227 $this->maxEntrySize = $options->
get( MainConfigNames::MaxMsgCacheEntrySize );
228 $this->adaptive = $options->
get( MainConfigNames::AdaptiveMessageCache );
232 $this->logger = $logger;
240 private function getParserOptions() {
241 if ( !$this->parserOptions ) {
243 $user = $context->getUser();
244 if ( !$user->isSafeToLoad() ) {
249 $po->setAllowUnsafeRawHtml(
false );
257 $this->parserOptions->setAllowUnsafeRawHtml(
false );
260 return $this->parserOptions;
269 private function getLocalCache( $code ) {
270 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
272 return $this->srvCache->get( $cacheKey );
281 private function saveToLocalCache( $code, $cache ) {
282 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
283 $this->srvCache->set( $cacheKey, $cache );
306 private function load(
string $code, $mode =
null ) {
308 if ( $this->isLanguageLoaded( $code ) && $mode !== self::FOR_UPDATE ) {
314 static $shownDisabled =
false;
315 if ( !$shownDisabled ) {
316 $this->logger->debug( __METHOD__ .
': disabled' );
317 $shownDisabled =
true;
324 return $this->loadUnguarded( $code, $mode );
325 }
catch ( Throwable $e ) {
339 private function loadUnguarded( $code, $mode ) {
346 [ $hash, $hashVolatile ] = $this->getValidationHash( $code );
347 $this->cacheVolatile[$code] = $hashVolatile;
348 $volatilityOnlyStaleness =
false;
351 $cache = $this->getLocalCache( $code );
353 $where[] =
'local cache is empty';
354 } elseif ( !isset( $cache[
'HASH'] ) || $cache[
'HASH'] !== $hash ) {
355 $where[] =
'local cache has the wrong hash';
356 $staleCache = $cache;
357 } elseif ( $this->isCacheExpired( $cache ) ) {
358 $where[] =
'local cache is expired';
359 $staleCache = $cache;
360 } elseif ( $hashVolatile ) {
362 $where[] =
'local cache validation key is expired/volatile';
363 $staleCache = $cache;
364 $volatilityOnlyStaleness =
true;
366 $where[] =
'got from local cache';
367 $this->cache->set( $code, $cache );
373 $cacheKey = $this->clusterCache->makeKey(
'messages', $code );
374 for ( $failedAttempts = 0; $failedAttempts <= 1; $failedAttempts++ ) {
375 if ( $volatilityOnlyStaleness && $staleCache ) {
380 $where[] =
'global cache is presumed expired';
382 $cache = $this->clusterCache->get( $cacheKey );
384 $where[] =
'global cache is empty';
385 } elseif ( $this->isCacheExpired( $cache ) ) {
386 $where[] =
'global cache is expired';
387 $staleCache = $cache;
388 } elseif ( $hashVolatile ) {
390 $where[] =
'global cache is expired/volatile';
391 $staleCache = $cache;
393 $where[] =
'got from global cache';
394 $this->cache->set( $code, $cache );
395 $this->saveToCaches( $cache,
'local-only', $code );
404 $loadStatus = $this->loadFromDBWithMainLock( $code, $where, $mode );
405 if ( $loadStatus ===
true ) {
408 } elseif ( $staleCache ) {
410 $where[] =
'using stale cache';
411 $this->cache->set( $code, $staleCache );
414 } elseif ( $failedAttempts > 0 ) {
415 $where[] =
'failed to find cache after waiting';
420 } elseif ( $loadStatus ===
'cantacquire' ) {
423 $where[] =
'waiting for other thread to complete';
424 [ , $ioError ] = $this->getReentrantScopedLock( $code );
426 $where[] =
'failed waiting';
429 $success = $this->loadFromDBWithLocalLock( $code, $where, $mode );
440 $where[] =
'loading FAILED - cache is disabled';
442 $this->cache->set( $code, [] );
443 $this->logger->error( __METHOD__ .
": Failed to load $code" );
448 if ( !$this->isLanguageLoaded( $code ) ) {
449 throw new LogicException(
"Process cache for '$code' should be set by now." );
452 $info = implode(
', ', $where );
453 $this->logger->debug( __METHOD__ .
": Loading $code... $info" );
464 private function loadFromDBWithMainLock( $code, array &$where, $mode =
null ) {
467 $statusKey = $this->clusterCache->makeKey(
'messages', $code,
'status' );
468 $status = $this->clusterCache->get( $statusKey );
469 if ( $status ===
'error' ) {
470 $where[] =
"could not load; method is still globally disabled";
475 $where[] =
'loading from DB';
481 [ $scopedLock ] = $this->getReentrantScopedLock( $code, 0 );
482 if ( !$scopedLock ) {
483 $where[] =
'could not acquire main lock';
484 return 'cantacquire';
487 $cache = $this->loadFromDB( $code, $mode );
488 $this->cache->set( $code, $cache );
489 $saveSuccess = $this->saveToCaches( $cache,
'all', $code );
491 if ( !$saveSuccess ) {
506 $this->clusterCache->set( $statusKey,
'error', 60 * 5 );
507 $where[] =
'could not save cache, disabled globally for 5 minutes';
509 $where[] =
"could not save global cache";
522 private function loadFromDBWithLocalLock( $code, array &$where, $mode =
null ) {
524 $where[] =
'loading from DB using local lock';
526 $scopedLock = $this->srvCache->getScopedLock(
527 $this->srvCache->makeKey(
'messages', $code ),
533 $cache = $this->loadFromDB( $code, $mode );
534 $this->cache->set( $code, $cache );
535 $this->saveToCaches( $cache,
'local-only', $code );
551 private function loadFromDB( $code, $mode =
null ) {
557 if ( $this->adaptive && $code !== $this->contLangCode ) {
558 if ( !$this->cache->has( $this->contLangCode ) ) {
559 $this->load( $this->contLangCode );
561 $mostused = array_keys( $this->cache->get( $this->contLangCode ) );
562 foreach ( $mostused as $key => $value ) {
563 $mostused[$key] =
"$value/$code";
569 'page_is_redirect' => 0,
572 if ( count( $mostused ) ) {
573 $conds[
'page_title'] = $mostused;
574 } elseif ( $code !== $this->contLangCode ) {
575 $conds[] =
'page_title' .
$dbr->buildLike(
$dbr->anyString(),
'/', $code );
579 $conds[] =
'page_title NOT' .
580 $dbr->buildLike(
$dbr->anyString(),
'/',
$dbr->anyString() );
586 [
'page_title',
'page_latest' ],
587 array_merge( $conds, [
'page_len > ' . intval( $this->maxEntrySize ) ] ),
588 __METHOD__ .
"($code)-big"
590 foreach (
$res as $row ) {
592 if ( $this->adaptive || $this->isMainCacheable( $row->page_title ) ) {
593 $cache[$row->page_title] =
'!TOO BIG';
596 $cache[
'EXCESSIVE'][$row->page_title] = $row->page_latest;
601 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
603 $revQuery = $revisionStore->getQueryInfo( [
'page' ] );
616 array_diff(
$revQuery[
'tables'], [
'page' ] )
622 array_merge( $conds, [
623 'page_len <= ' . intval( $this->maxEntrySize ),
624 'page_latest = rev_id'
626 __METHOD__ .
"($code)-small",
632 [ $cacheableRows, $uncacheableRows ] = $this->separateCacheableRows(
$res );
633 $result = $revisionStore->newRevisionsFromBatch( $cacheableRows, [
634 'slots' => [ SlotRecord::MAIN ],
637 $revisions = $result->isOK() ? $result->getValue() : [];
639 foreach ( $cacheableRows as $row ) {
641 $rev = $revisions[$row->rev_id] ??
null;
642 $content = $rev ? $rev->getContent( SlotRecord::MAIN ) :
null;
643 $text = $this->getMessageTextFromContent(
$content );
644 }
catch ( TimeoutException $e ) {
646 }
catch ( Exception $ex ) {
650 if ( !is_string( $text ) ) {
652 $this->logger->error(
654 .
": failed to load message page text for {$row->page_title} ($code)"
657 $entry =
' ' . $text;
659 $cache[$row->page_title] = $entry;
662 foreach ( $uncacheableRows as $row ) {
665 $cache[
'EXCESSIVE'][$row->page_title] = $row->page_latest;
674 $cache[
'HASH'] = md5( serialize( $cache ) );
675 $cache[
'EXPIRY'] =
wfTimestamp( TS_MW, time() + self::WAN_TTL );
676 unset( $cache[
'EXCESSIVE'] );
687 private function isLanguageLoaded(
$lang ) {
694 return $this->cache->hasField(
$lang,
'VERSION' );
708 private function isMainCacheable( $name, $code =
null ) {
710 $name = $this->contLang->lcfirst( $name );
713 if ( strpos( $name,
'conversiontable/' ) === 0 ) {
716 $msg = preg_replace(
'/\/[a-z0-9-]{2,}$/',
'', $name );
718 if ( $code ===
null ) {
720 if ( $this->systemMessageNames ===
null ) {
721 $this->systemMessageNames = array_fill_keys(
722 $this->localisationCache->getSubitemList( $this->contLangCode,
'messages' ),
725 return isset( $this->systemMessageNames[$msg] );
728 return $this->localisationCache->getSubitem( $code,
'messages', $msg ) !==
null;
739 private function separateCacheableRows(
$res ) {
740 if ( $this->adaptive ) {
745 $uncacheableRows = [];
746 foreach (
$res as $row ) {
747 if ( $this->isMainCacheable( $row->page_title ) ) {
748 $cacheableRows[] = $row;
750 $uncacheableRows[] = $row;
753 return [ $cacheableRows, $uncacheableRows ];
768 if ( strpos(
$title,
'/' ) !==
false && $code === $this->contLangCode ) {
774 if ( $text ===
false ) {
776 $this->cache->setField( $code,
$title,
'!NONEXISTENT' );
779 $this->cache->setField( $code,
$title,
' ' . $text );
785 DeferredUpdates::PRESEND
795 [ $scopedLock ] = $this->getReentrantScopedLock( $code );
796 if ( !$scopedLock ) {
797 foreach ( $replacements as [
$title ] ) {
798 $this->logger->error(
799 __METHOD__ .
': could not acquire lock to update {title} ({code})',
800 [
'title' =>
$title,
'code' => $code ] );
808 if ( $this->load( $code, self::FOR_UPDATE ) ) {
809 $cache = $this->cache->get( $code );
812 $cache = $this->loadFromDB( $code, self::FOR_UPDATE );
815 $newTextByTitle = [];
819 $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
820 foreach ( $replacements as [
$title ] ) {
822 $page->loadPageData( $page::READ_LATEST );
823 $text = $this->getMessageTextFromContent( $page->getContent() );
825 $newTextByTitle[
$title] = $text ??
'';
827 if ( !is_string( $text ) ) {
828 $cache[
$title] =
'!NONEXISTENT';
829 } elseif ( strlen( $text ) > $this->maxEntrySize ) {
830 $cache[
$title] =
'!TOO BIG';
831 $newBigTitles[
$title] = $page->getLatest();
833 $cache[
$title] =
' ' . $text;
840 $cache[
'HASH'] = md5( serialize( $cache + [
'EXCESSIVE' => $newBigTitles ] ) );
842 foreach ( $newBigTitles as
$title => $id ) {
844 $this->wanCache->set(
845 $this->bigMessageCacheKey( $cache[
'HASH'],
$title ),
846 ' ' . $newTextByTitle[
$title],
852 $cache[
'LATEST'] = time();
854 $this->cache->set( $code, $cache );
859 $this->saveToCaches( $cache,
'all', $code );
861 ScopedCallback::consume( $scopedLock );
865 $this->wanCache->touchCheckKey( $this->
getCheckKey( $code ) );
868 $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
869 foreach ( $replacements as [
$title, $msg ] ) {
870 $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
871 $this->hookRunner->onMessageCacheReplace(
$title, $newTextByTitle[
$title] );
881 private function isCacheExpired( $cache ) {
882 if ( !isset( $cache[
'VERSION'] ) || !isset( $cache[
'EXPIRY'] ) ) {
904 private function saveToCaches( array $cache, $dest, $code =
false ) {
905 if ( $dest ===
'all' ) {
906 $cacheKey = $this->clusterCache->makeKey(
'messages', $code );
907 $success = $this->clusterCache->set( $cacheKey, $cache );
908 $this->setValidationHash( $code, $cache );
913 $this->saveToLocalCache( $code, $cache );
924 private function getValidationHash( $code ) {
926 $value = $this->wanCache->get(
927 $this->wanCache->makeKey(
'messages', $code,
'hash',
'v1' ),
929 [ $this->getCheckKey( $code ) ]
933 $hash = $value[
'hash'];
934 if ( ( time() - $value[
'latest'] ) < WANObjectCache::TTL_MINUTE ) {
940 $expired = ( $curTTL < 0 );
948 return [ $hash, $expired ];
961 private function setValidationHash( $code, array $cache ) {
962 $this->wanCache->set(
963 $this->wanCache->makeKey(
'messages', $code,
'hash',
'v1' ),
965 'hash' => $cache[
'HASH'],
966 'latest' => $cache[
'LATEST'] ?? 0
968 WANObjectCache::TTL_INDEFINITE
978 private function getReentrantScopedLock( $code, $timeout = self::WAIT_SEC ) {
979 $key = $this->clusterCache->makeKey(
'messages', $code );
981 $watchPoint = $this->clusterCache->watchErrors();
982 $scopedLock = $this->clusterCache->getScopedLock(
988 $error = ( !$scopedLock && $this->clusterCache->getLastError( $watchPoint ) );
990 return [ $scopedLock, $error ];
1025 public function get( $key, $useDB =
true, $langcode =
true ) {
1026 if ( is_int( $key ) ) {
1028 $key = (string)$key;
1029 } elseif ( !is_string( $key ) ) {
1030 throw new TypeError(
'Message key must be a string' );
1031 } elseif ( $key ===
'' ) {
1036 $language = $this->getLanguageObject( $langcode );
1042 if ( $this->messageKeyOverrides ===
null ) {
1043 $this->messageKeyOverrides = [];
1044 $this->hookRunner->onMessageCacheFetchOverrides( $this->messageKeyOverrides );
1047 if ( isset( $this->messageKeyOverrides[$lckey] ) ) {
1048 $override = $this->messageKeyOverrides[$lckey];
1052 if ( is_string( $override ) ) {
1055 $lckey = $override( $lckey, $this, $language, $useDB );
1059 $this->hookRunner->onMessageCache__get( $lckey );
1062 $message = $this->getMessageFromFallbackChain(
1069 if ( $message ===
false ) {
1070 $parts = explode(
'/', $lckey );
1074 if ( count( $parts ) === 2 && $parts[1] !==
'' ) {
1075 $message = $this->localisationCache->getSubitem( $parts[1],
'messages', $parts[0] ) ??
false;
1080 if ( $message !==
false ) {
1082 $message = str_replace(
1119 private function getLanguageObject( $langcode ) {
1120 # Identify which language to get or create a language object for.
1121 # Using is_object here due to Stub objects.
1122 if ( is_object( $langcode ) ) {
1123 # Great, we already have the object (hopefully)!
1127 if ( $langcode ===
true || $langcode === $this->contLangCode ) {
1128 # $langcode is the language code of the wikis content language object.
1129 # or it is a boolean and value is true
1130 return $this->contLang;
1134 if ( $langcode ===
false || $langcode ===
$wgLang->getCode() ) {
1135 # $langcode is the language code of user language object.
1136 # or it was a boolean and value is false
1140 $validCodes = array_keys( $this->languageNameUtils->getLanguageNames() );
1141 if ( in_array( $langcode, $validCodes ) ) {
1142 # $langcode corresponds to a valid language.
1143 return $this->langFactory->getLanguage( $langcode );
1146 # $langcode is a string, but not a valid language code; use content language.
1147 $this->logger->debug(
'Invalid language code passed to' . __METHOD__ .
', falling back to content language.' );
1148 return $this->contLang;
1163 private function getMessageFromFallbackChain(
$lang, $lckey, $useDB ) {
1167 $message = $this->getMessageForLang(
$lang, $lckey, $useDB, $alreadyTried );
1168 if ( $message !==
false ) {
1173 $message = $this->getMessageForLang( $this->contLang, $lckey, $useDB, $alreadyTried );
1187 private function getMessageForLang(
$lang, $lckey, $useDB, &$alreadyTried ) {
1188 $langcode =
$lang->getCode();
1192 $uckey = $this->contLang->ucfirst( $lckey );
1194 if ( !isset( $alreadyTried[$langcode] ) ) {
1196 $this->getMessagePageName( $langcode, $uckey ),
1199 if ( $message !==
false ) {
1202 $alreadyTried[$langcode] =
true;
1209 $message =
$lang->getMessage( $lckey );
1210 if ( $message !==
null ) {
1216 $fallbackChain = $this->languageFallback->getAll( $langcode );
1218 foreach ( $fallbackChain as $code ) {
1219 if ( isset( $alreadyTried[$code] ) ) {
1225 $this->getMessagePageName( $code, $uckey ), $code );
1227 if ( $message !==
false ) {
1230 $alreadyTried[$code] =
true;
1244 private function getMessagePageName( $langcode, $uckey ) {
1245 if ( $langcode === $this->contLangCode ) {
1249 return "$uckey/$langcode";
1269 $this->load( $code );
1271 $entry = $this->cache->getField( $code,
$title );
1273 if ( $entry !==
null ) {
1275 if ( substr( $entry, 0, 1 ) ===
' ' ) {
1277 return (
string)substr( $entry, 1 );
1278 } elseif ( $entry ===
'!NONEXISTENT' ) {
1284 $entry = $this->loadCachedMessagePageEntry(
1287 $this->cache->getField( $code,
'HASH' )
1291 if ( !$this->isMainCacheable(
$title, $code ) ) {
1295 $entry = $this->loadCachedMessagePageEntry(
1298 $this->cache->getField( $code,
'HASH' )
1301 if ( $entry ===
null || substr( $entry, 0, 1 ) !==
' ' ) {
1305 $this->hookRunner->onMessagesPreLoad(
$title, $message, $code );
1306 if ( $message !==
false ) {
1307 $this->cache->setField( $code,
$title,
' ' . $message );
1309 $this->cache->setField( $code,
$title,
'!NONEXISTENT' );
1316 if ( $entry !==
false && substr( $entry, 0, 1 ) ===
' ' ) {
1317 if ( $this->cacheVolatile[$code] ) {
1319 $this->logger->debug(
1320 __METHOD__ .
': loading volatile key \'{titleKey}\'',
1321 [
'titleKey' =>
$title,
'code' => $code ] );
1323 $this->cache->setField( $code,
$title, $entry );
1326 return (
string)substr( $entry, 1 );
1329 $this->cache->setField( $code,
$title,
'!NONEXISTENT' );
1340 private function loadCachedMessagePageEntry( $dbKey, $code, $hash ) {
1341 $fname = __METHOD__;
1342 return $this->srvCache->getWithSetCallback(
1343 $this->srvCache->makeKey(
'messages-big', $hash, $dbKey ),
1344 BagOStuff::TTL_HOUR,
1345 function () use ( $code, $dbKey, $hash, $fname ) {
1346 return $this->wanCache->getWithSetCallback(
1347 $this->bigMessageCacheKey( $hash, $dbKey ),
1349 function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code, $fname ) {
1356 $revision = MediaWikiServices::getInstance()
1357 ->getRevisionLookup()
1358 ->getKnownCurrentRevision(
$title );
1362 return '!NONEXISTENT';
1364 $content = $revision->getContent( SlotRecord::MAIN );
1366 $message = $this->getMessageTextFromContent(
$content );
1368 $this->logger->warning(
1369 $fname .
': failed to load page text for \'{titleKey}\'',
1370 [
'titleKey' => $dbKey,
'code' => $code ]
1375 if ( !is_string( $message ) ) {
1380 return '!NONEXISTENT';
1383 return ' ' . $message;
1399 if ( strpos( $message,
'{{' ) ===
false ) {
1403 if ( $this->inParser ) {
1409 $popts = $this->getParserOptions();
1410 $popts->setInterfaceMessage( $interface );
1411 $popts->setTargetLanguage( $language );
1413 $userlang = $popts->setUserLang( $language );
1414 $this->inParser =
true;
1415 $message = $parser->
transformMsg( $message, $popts, $page );
1416 $this->inParser =
false;
1417 $popts->setUserLang( $userlang );
1427 if ( !$this->parser ) {
1428 $parser = MediaWikiServices::getInstance()->getParser();
1430 $this->parser = clone $parser;
1433 return $this->parser;
1445 $interface =
false, $language =
null
1449 if ( $this->inParser ) {
1450 return htmlspecialchars( $text );
1454 $popts = $this->getParserOptions();
1455 $popts->setInterfaceMessage( $interface );
1457 if ( is_string( $language ) ) {
1458 $language = $this->langFactory->getLanguage( $language );
1460 $popts->setTargetLanguage( $language );
1463 $logger = LoggerFactory::getInstance(
'GlobalTitleFail' );
1465 __METHOD__ .
' called with no title set.',
1466 [
'exception' =>
new Exception ]
1474 $page = PageReferenceValue::localReference(
1476 'Badtitle/title not set in ' . __METHOD__
1480 $this->inParser =
true;
1481 $res = $parser->
parse( $text, $page, $popts, $linestart );
1482 $this->inParser =
false;
1508 return $this->disable;
1517 $langs = $this->languageNameUtils->getLanguageNames();
1518 foreach ( array_keys( $langs ) as $code ) {
1519 $this->wanCache->touchCheckKey( $this->
getCheckKey( $code ) );
1521 $this->cache->clear();
1529 $pieces = explode(
'/', $key );
1530 if ( count( $pieces ) < 2 ) {
1531 return [ $key, $this->contLangCode ];
1534 $lang = array_pop( $pieces );
1535 if ( !$this->languageNameUtils->getLanguageName(
1537 LanguageNameUtils::AUTONYMS,
1538 LanguageNameUtils::DEFINED
1540 return [ $key, $this->contLangCode ];
1543 $message = implode(
'/', $pieces );
1545 return [ $message,
$lang ];
1557 $this->load( $code );
1558 if ( !$this->cache->has( $code ) ) {
1563 $cache = $this->cache->get( $code );
1564 unset( $cache[
'VERSION'] );
1565 unset( $cache[
'EXPIRY'] );
1566 unset( $cache[
'EXCESSIVE'] );
1568 $cache = array_diff( $cache, [
'!NONEXISTENT' ] );
1571 return array_map( [ $this->contLang,
'lcfirst' ], array_keys( $cache ) );
1583 $msgText = $this->getMessageTextFromContent(
$content ) ??
false;
1587 if ( $this->contLangConverter->hasVariants() ) {
1588 $this->contLangConverter->updateConversionTable( $linkTarget );
1597 return $this->wanCache->makeKey(
'messages', $code );
1604 private function getMessageTextFromContent(
Content $content =
null ) {
1612 $msgText =
$content->getWikitextForTransclusion();
1613 if ( $msgText ===
false || $msgText ===
null ) {
1616 $this->logger->warning(
1617 __METHOD__ .
": message content doesn't provide wikitext "
1618 .
"(content model: " .
$content->getModel() .
")" );
1633 private function bigMessageCacheKey( $hash,
$title ) {
1634 return $this->wanCache->makeKey(
'messages-big', $hash,
$title );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const MSG_CACHE_VERSION
MediaWiki message cache structure version.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgTitle
Class representing a cache/ephemeral data store.
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the pending update queue for execution at the appropriate time.
A BagOStuff object with no objects in it.
Base class for language-specific code.
getCode()
Get the internal language code for this language object.
Caching for the contents of localisation files.
Handles a simple LRU key/value map with a maximum number of entries.
A class containing constants representing the names of configuration variables.
Message cache purging and in-place update handler for specific message page changes.
Cache messages that are defined by MediaWiki-namespace pages or by hooks.
refreshAndReplaceInternal(string $code, array $replacements)
const MAX_REQUEST_LANGUAGES
The size of the MapCacheLRU which stores message data.
__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)
getMsgFromNamespace( $title, $code)
Get a message from the MediaWiki namespace, with caching.
parse( $text, PageReference $page=null, $linestart=true, $interface=false, $language=null)
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.
const CONSTRUCTOR_OPTIONS
Options to be included in the ServiceOptions.
isDisabled()
Whether DB/cache usage is disabled for determining messages.
setLogger(LoggerInterface $logger)
clear()
Clear all stored messages in global and local cache.
getAllMessageKeys( $code)
Get all message keys stored in the message cache for a given language.
static normalizeKey( $key)
Normalize message key input.
replace( $title, $text)
Updates cache as necessary when message page is changed.
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
static newFromAnon()
Get a ParserOptions object for an anonymous user.
parse( $text, PageReference $page, ParserOptions $options, $linestart=true, $clearState=true, $revid=null)
Convert wikitext to HTML Do not call this function recursively.
transformMsg( $text, ParserOptions $options, ?PageReference $page=null)
Wrapper for preprocess()
static getMain()
Get the RequestContext object associated with the main request.
Multi-datacenter aware caching interface.
Base interface for representing page content.
if(!isset( $args[0])) $lang