MediaWiki  master
MessageCache.php
Go to the documentation of this file.
1 <?php
33 use Psr\Log\LoggerAwareInterface;
34 use Psr\Log\LoggerInterface;
36 use Wikimedia\ScopedCallback;
37 
42 define( 'MSG_CACHE_VERSION', 2 );
43 
50 class MessageCache implements LoggerAwareInterface {
51  private const FOR_UPDATE = 1; // force message reload
52 
54  private const WAIT_SEC = 15;
56  private const LOCK_TTL = 30;
57 
62  private const WAN_TTL = IExpiringStore::TTL_DAY;
63 
65  private $logger;
66 
72  protected $cache;
73 
79  protected $overridable;
80 
84  protected $cacheVolatile = [];
85 
90  protected $mDisable;
91 
96  protected $mParserOptions;
98  protected $mParser;
99 
103  protected $mInParser = false;
104 
106  protected $wanCache;
108  protected $clusterCache;
110  protected $srvCache;
112  protected $contLang;
116  protected $langFactory;
122  protected $languageFallback;
124  private $hookRunner;
125 
133  public static function singleton() {
134  return MediaWikiServices::getInstance()->getMessageCache();
135  }
136 
143  public static function normalizeKey( $key ) {
144  $lckey = strtr( $key, ' ', '_' );
145  if ( ord( $lckey ) < 128 ) {
146  $lckey[0] = strtolower( $lckey[0] );
147  } else {
148  $lckey = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $lckey );
149  }
150 
151  return $lckey;
152  }
153 
171  public function __construct(
174  BagOStuff $serverCache,
177  LoggerInterface $logger,
178  array $options,
183  HookContainer $hookContainer
184  ) {
185  $this->wanCache = $wanCache;
186  $this->clusterCache = $clusterCache;
187  $this->srvCache = $serverCache;
188  $this->contLang = $contLang;
189  $this->contLangConverter = $contLangConverter;
190  $this->logger = $logger;
191  $this->langFactory = $langFactory;
192  $this->localisationCache = $localisationCache;
193  $this->languageNameUtils = $languageNameUtils;
194  $this->languageFallback = $languageFallback;
195  $this->hookRunner = new HookRunner( $hookContainer );
196 
197  $this->cache = new MapCacheLRU( 5 ); // limit size for sanity
198 
199  $this->mDisable = !( $options['useDB'] ?? true );
200  }
201 
202  public function setLogger( LoggerInterface $logger ) {
203  $this->logger = $logger;
204  }
205 
211  private function getParserOptions() {
212  global $wgUser;
213 
214  if ( !$this->mParserOptions ) {
215  if ( !$wgUser || !$wgUser->isSafeToLoad() ) {
216  // $wgUser isn't available yet, so don't try to get a
217  // ParserOptions for it. And don't cache this ParserOptions
218  // either.
220  $po->setAllowUnsafeRawHtml( false );
221  return $po;
222  }
223 
224  $this->mParserOptions = new ParserOptions( $wgUser );
225  // Messages may take parameters that could come
226  // from malicious sources. As a precaution, disable
227  // the <html> parser tag when parsing messages.
228  $this->mParserOptions->setAllowUnsafeRawHtml( false );
229  }
230 
231  return $this->mParserOptions;
232  }
233 
240  protected function getLocalCache( $code ) {
241  $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
242 
243  return $this->srvCache->get( $cacheKey );
244  }
245 
252  protected function saveToLocalCache( $code, $cache ) {
253  $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
254  $this->srvCache->set( $cacheKey, $cache );
255  }
256 
278  protected function load( $code, $mode = null ) {
279  if ( !is_string( $code ) ) {
280  throw new InvalidArgumentException( "Missing language code" );
281  }
282 
283  # Don't do double loading...
284  if ( $this->isLanguageLoaded( $code ) && $mode != self::FOR_UPDATE ) {
285  return true;
286  }
287 
288  $this->overridable =
289  array_flip( $this->localisationCache->getSubitemList( $code, 'messages' ) );
290 
291  # 8 lines of code just to say (once) that message cache is disabled
292  if ( $this->mDisable ) {
293  static $shownDisabled = false;
294  if ( !$shownDisabled ) {
295  $this->logger->debug( __METHOD__ . ': disabled' );
296  $shownDisabled = true;
297  }
298 
299  return true;
300  }
301 
302  # Loading code starts
303  $success = false; # Keep track of success
304  $staleCache = false; # a cache array with expired data, or false if none has been loaded
305  $where = []; # Debug info, delayed to avoid spamming debug log too much
306 
307  # Hash of the contents is stored in memcache, to detect if data-center cache
308  # or local cache goes out of date (e.g. due to replace() on some other server)
309  list( $hash, $hashVolatile ) = $this->getValidationHash( $code );
310  $this->cacheVolatile[$code] = $hashVolatile;
311 
312  # Try the local cache and check against the cluster hash key...
313  $cache = $this->getLocalCache( $code );
314  if ( !$cache ) {
315  $where[] = 'local cache is empty';
316  } elseif ( !isset( $cache['HASH'] ) || $cache['HASH'] !== $hash ) {
317  $where[] = 'local cache has the wrong hash';
318  $staleCache = $cache;
319  } elseif ( $this->isCacheExpired( $cache ) ) {
320  $where[] = 'local cache is expired';
321  $staleCache = $cache;
322  } elseif ( $hashVolatile ) {
323  $where[] = 'local cache validation key is expired/volatile';
324  $staleCache = $cache;
325  } else {
326  $where[] = 'got from local cache';
327  $this->cache->set( $code, $cache );
328  $success = true;
329  }
330 
331  if ( !$success ) {
332  $cacheKey = $this->clusterCache->makeKey( 'messages', $code );
333  # Try the global cache. If it is empty, try to acquire a lock. If
334  # the lock can't be acquired, wait for the other thread to finish
335  # and then try the global cache a second time.
336  for ( $failedAttempts = 0; $failedAttempts <= 1; $failedAttempts++ ) {
337  if ( $hashVolatile && $staleCache ) {
338  # Do not bother fetching the whole cache blob to avoid I/O.
339  # Instead, just try to get the non-blocking $statusKey lock
340  # below, and use the local stale value if it was not acquired.
341  $where[] = 'global cache is presumed expired';
342  } else {
343  $cache = $this->clusterCache->get( $cacheKey );
344  if ( !$cache ) {
345  $where[] = 'global cache is empty';
346  } elseif ( $this->isCacheExpired( $cache ) ) {
347  $where[] = 'global cache is expired';
348  $staleCache = $cache;
349  } elseif ( $hashVolatile ) {
350  # DB results are replica DB lag prone until the holdoff TTL passes.
351  # By then, updates should be reflected in loadFromDBWithLock().
352  # One thread regenerates the cache while others use old values.
353  $where[] = 'global cache is expired/volatile';
354  $staleCache = $cache;
355  } else {
356  $where[] = 'got from global cache';
357  $this->cache->set( $code, $cache );
358  $this->saveToCaches( $cache, 'local-only', $code );
359  $success = true;
360  }
361  }
362 
363  if ( $success ) {
364  # Done, no need to retry
365  break;
366  }
367 
368  # We need to call loadFromDB. Limit the concurrency to one process.
369  # This prevents the site from going down when the cache expires.
370  # Note that the DB slam protection lock here is non-blocking.
371  $loadStatus = $this->loadFromDBWithLock( $code, $where, $mode );
372  if ( $loadStatus === true ) {
373  $success = true;
374  break;
375  } elseif ( $staleCache ) {
376  # Use the stale cache while some other thread constructs the new one
377  $where[] = 'using stale cache';
378  $this->cache->set( $code, $staleCache );
379  $success = true;
380  break;
381  } elseif ( $failedAttempts > 0 ) {
382  # Already blocked once, so avoid another lock/unlock cycle.
383  # This case will typically be hit if memcached is down, or if
384  # loadFromDB() takes longer than LOCK_WAIT.
385  $where[] = "could not acquire status key.";
386  break;
387  } elseif ( $loadStatus === 'cantacquire' ) {
388  # Wait for the other thread to finish, then retry. Normally,
389  # the memcached get() will then yield the other thread's result.
390  $where[] = 'waited for other thread to complete';
391  $this->getReentrantScopedLock( $cacheKey );
392  } else {
393  # Disable cache; $loadStatus is 'disabled'
394  break;
395  }
396  }
397  }
398 
399  if ( !$success ) {
400  $where[] = 'loading FAILED - cache is disabled';
401  $this->mDisable = true;
402  $this->cache->set( $code, [] );
403  $this->logger->error( __METHOD__ . ": Failed to load $code" );
404  # This used to throw an exception, but that led to nasty side effects like
405  # the whole wiki being instantly down if the memcached server died
406  }
407 
408  if ( !$this->isLanguageLoaded( $code ) ) { // sanity
409  throw new LogicException( "Process cache for '$code' should be set by now." );
410  }
411 
412  $info = implode( ', ', $where );
413  $this->logger->debug( __METHOD__ . ": Loading $code... $info" );
414 
415  return $success;
416  }
417 
424  protected function loadFromDBWithLock( $code, array &$where, $mode = null ) {
425  # If cache updates on all levels fail, give up on message overrides.
426  # This is to avoid easy site outages; see $saveSuccess comments below.
427  $statusKey = $this->clusterCache->makeKey( 'messages', $code, 'status' );
428  $status = $this->clusterCache->get( $statusKey );
429  if ( $status === 'error' ) {
430  $where[] = "could not load; method is still globally disabled";
431  return 'disabled';
432  }
433 
434  # Now let's regenerate
435  $where[] = 'loading from database';
436 
437  # Lock the cache to prevent conflicting writes.
438  # This lock is non-blocking so stale cache can quickly be used.
439  # Note that load() will call a blocking getReentrantScopedLock()
440  # after this if it really need to wait for any current thread.
441  $cacheKey = $this->clusterCache->makeKey( 'messages', $code );
442  $scopedLock = $this->getReentrantScopedLock( $cacheKey, 0 );
443  if ( !$scopedLock ) {
444  $where[] = 'could not acquire main lock';
445  return 'cantacquire';
446  }
447 
448  $cache = $this->loadFromDB( $code, $mode );
449  $this->cache->set( $code, $cache );
450  $saveSuccess = $this->saveToCaches( $cache, 'all', $code );
451 
452  if ( !$saveSuccess ) {
466  if ( $this->srvCache instanceof EmptyBagOStuff ) {
467  $this->clusterCache->set( $statusKey, 'error', 60 * 5 );
468  $where[] = 'could not save cache, disabled globally for 5 minutes';
469  } else {
470  $where[] = "could not save global cache";
471  }
472  }
473 
474  return true;
475  }
476 
486  protected function loadFromDB( $code, $mode = null ) {
488 
489  // (T164666) The query here performs really poorly on WMF's
490  // contributions replicas. We don't have a way to say "any group except
491  // contributions", so for the moment let's specify 'api'.
492  // @todo: Get rid of this hack.
493  $dbr = wfGetDB( ( $mode == self::FOR_UPDATE ) ? DB_MASTER : DB_REPLICA, 'api' );
494 
495  $cache = [];
496 
497  $mostused = []; // list of "<cased message key>/<code>"
498  if ( $wgAdaptiveMessageCache && $code !== $wgLanguageCode ) {
499  if ( !$this->cache->has( $wgLanguageCode ) ) {
500  $this->load( $wgLanguageCode );
501  }
502  $mostused = array_keys( $this->cache->get( $wgLanguageCode ) );
503  foreach ( $mostused as $key => $value ) {
504  $mostused[$key] = "$value/$code";
505  }
506  }
507 
508  // Get the list of software-defined messages in core/extensions
509  $overridable =
510  array_flip( $this->localisationCache->getSubitemList( $wgLanguageCode, 'messages' ) );
511 
512  // Common conditions
513  $conds = [
514  'page_is_redirect' => 0,
515  'page_namespace' => NS_MEDIAWIKI,
516  ];
517  if ( count( $mostused ) ) {
518  $conds['page_title'] = $mostused;
519  } elseif ( $code !== $wgLanguageCode ) {
520  $conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), '/', $code );
521  } else {
522  # Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
523  # other than language code.
524  $conds[] = 'page_title NOT' .
525  $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
526  }
527 
528  // Set the stubs for oversized software-defined messages in the main cache map
529  $res = $dbr->select(
530  'page',
531  [ 'page_title', 'page_latest' ],
532  array_merge( $conds, [ 'page_len > ' . intval( $wgMaxMsgCacheEntrySize ) ] ),
533  __METHOD__ . "($code)-big"
534  );
535  foreach ( $res as $row ) {
536  // Include entries/stubs for all keys in $mostused in adaptive mode
537  if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $row->page_title, $overridable ) ) {
538  $cache[$row->page_title] = '!TOO BIG';
539  }
540  // At least include revision ID so page changes are reflected in the hash
541  $cache['EXCESSIVE'][$row->page_title] = $row->page_latest;
542  }
543 
544  // Can not inject the RevisionStore as it would break the installer since
545  // it instantiates MessageCache before the DB.
546  $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
547  // Set the text for small software-defined messages in the main cache map
548  $revQuery = $revisionStore->getQueryInfo( [ 'page', 'user' ] );
549 
550  // T231196: MySQL/MariaDB (10.1.37) can sometimes irrationally decide that querying `actor` then
551  // `revision` then `page` is somehow better than starting with `page`. Tell it not to reorder the
552  // query (and also reorder it ourselves because as generated by RevisionStore it'll have
553  // `revision` first rather than `page`).
554  $revQuery['joins']['revision'] = $revQuery['joins']['page'];
555  unset( $revQuery['joins']['page'] );
556  // It isn't actually necesssary to reorder $revQuery['tables'] as Database does the right thing
557  // when join conditions are given for all joins, but GergÅ‘ is wary of relying on that so pull
558  // `page` to the start.
559  $revQuery['tables'] = array_merge(
560  [ 'page' ],
561  array_diff( $revQuery['tables'], [ 'page' ] )
562  );
563 
564  $res = $dbr->select(
565  $revQuery['tables'],
566  $revQuery['fields'],
567  array_merge( $conds, [
568  'page_len <= ' . intval( $wgMaxMsgCacheEntrySize ),
569  'page_latest = rev_id' // get the latest revision only
570  ] ),
571  __METHOD__ . "($code)-small",
572  [ 'STRAIGHT_JOIN' ],
573  $revQuery['joins']
574  );
575  foreach ( $res as $row ) {
576  // Include entries/stubs for all keys in $mostused in adaptive mode
577  if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $row->page_title, $overridable ) ) {
578  try {
579  $rev = $revisionStore->newRevisionFromRow( $row, 0, Title::newFromRow( $row ) );
580  $content = $rev->getContent( MediaWiki\Revision\SlotRecord::MAIN );
581  $text = $this->getMessageTextFromContent( $content );
582  } catch ( Exception $ex ) {
583  $text = false;
584  }
585 
586  if ( !is_string( $text ) ) {
587  $entry = '!ERROR';
588  $this->logger->error(
589  __METHOD__
590  . ": failed to load message page text for {$row->page_title} ($code)"
591  );
592  } else {
593  $entry = ' ' . $text;
594  }
595  $cache[$row->page_title] = $entry;
596  } else {
597  // T193271: cache object gets too big and slow to generate.
598  // At least include revision ID so page changes are reflected in the hash.
599  $cache['EXCESSIVE'][$row->page_title] = $row->page_latest;
600  }
601  }
602 
603  $cache['VERSION'] = MSG_CACHE_VERSION;
604  ksort( $cache );
605 
606  # Hash for validating local cache (APC). No need to take into account
607  # messages larger than $wgMaxMsgCacheEntrySize, since those are only
608  # stored and fetched from memcache.
609  $cache['HASH'] = md5( serialize( $cache ) );
610  $cache['EXPIRY'] = wfTimestamp( TS_MW, time() + self::WAN_TTL );
611  unset( $cache['EXCESSIVE'] ); // only needed for hash
612 
613  return $cache;
614  }
615 
622  private function isLanguageLoaded( $lang ) {
623  // It is important that this only returns true if the cache was fully
624  // populated by load(), so that callers can assume all cache keys exist.
625  // It is possible for $this->cache to be only patially populated through
626  // methods like MessageCache::replace(), which must not make this method
627  // return true (T208897). And this method must cease to return true
628  // if the language was evicted by MapCacheLRU (T230690).
629  return $this->cache->hasField( $lang, 'VERSION' );
630  }
631 
637  private function isMainCacheable( $name, array $overridable ) {
638  // Convert first letter to lowercase, and strip /code suffix
639  $name = $this->contLang->lcfirst( $name );
640  $msg = preg_replace( '/\/[a-z0-9-]{2,}$/', '', $name );
641  // Include common conversion table pages. This also avoids problems with
642  // Installer::parse() bailing out due to disallowed DB queries (T207979).
643  return ( isset( $overridable[$msg] ) || strpos( $name, 'conversiontable/' ) === 0 );
644  }
645 
652  public function replace( $title, $text ) {
653  global $wgLanguageCode;
654 
655  if ( $this->mDisable ) {
656  return;
657  }
658 
659  list( $msg, $code ) = $this->figureMessage( $title );
660  if ( strpos( $title, '/' ) !== false && $code === $wgLanguageCode ) {
661  // Content language overrides do not use the /<code> suffix
662  return;
663  }
664 
665  // (a) Update the process cache with the new message text
666  if ( $text === false ) {
667  // Page deleted
668  $this->cache->setField( $code, $title, '!NONEXISTENT' );
669  } else {
670  // Ignore $wgMaxMsgCacheEntrySize so the process cache is up to date
671  $this->cache->setField( $code, $title, ' ' . $text );
672  }
673 
674  // (b) Update the shared caches in a deferred update with a fresh DB snapshot
676  new MessageCacheUpdate( $code, $title, $msg ),
678  );
679  }
680 
686  public function refreshAndReplaceInternal( $code, array $replacements ) {
688 
689  // Allow one caller at a time to avoid race conditions
690  $scopedLock = $this->getReentrantScopedLock(
691  $this->clusterCache->makeKey( 'messages', $code )
692  );
693  if ( !$scopedLock ) {
694  foreach ( $replacements as list( $title ) ) {
695  $this->logger->error(
696  __METHOD__ . ': could not acquire lock to update {title} ({code})',
697  [ 'title' => $title, 'code' => $code ] );
698  }
699 
700  return;
701  }
702 
703  // Load the existing cache to update it in the local DC cache.
704  // The other DCs will see a hash mismatch.
705  if ( $this->load( $code, self::FOR_UPDATE ) ) {
706  $cache = $this->cache->get( $code );
707  } else {
708  // Err? Fall back to loading from the database.
709  $cache = $this->loadFromDB( $code, self::FOR_UPDATE );
710  }
711  // Check if individual cache keys should exist and update cache accordingly
712  $newTextByTitle = []; // map of (title => content)
713  $newBigTitles = []; // map of (title => latest revision ID), like EXCESSIVE in loadFromDB()
714  foreach ( $replacements as list( $title ) ) {
716  $page->loadPageData( $page::READ_LATEST );
717  $text = $this->getMessageTextFromContent( $page->getContent() );
718  // Remember the text for the blob store update later on
719  $newTextByTitle[$title] = $text;
720  // Note that if $text is false, then $cache should have a !NONEXISTANT entry
721  if ( !is_string( $text ) ) {
722  $cache[$title] = '!NONEXISTENT';
723  } elseif ( strlen( $text ) > $wgMaxMsgCacheEntrySize ) {
724  $cache[$title] = '!TOO BIG';
725  $newBigTitles[$title] = $page->getLatest();
726  } else {
727  $cache[$title] = ' ' . $text;
728  }
729  }
730  // Update HASH for the new key. Incorporates various administrative keys,
731  // including the old HASH (and thereby the EXCESSIVE value from loadFromDB()
732  // and previous replace() calls), but that doesn't really matter since we
733  // only ever compare it for equality with a copy saved by saveToCaches().
734  $cache['HASH'] = md5( serialize( $cache + [ 'EXCESSIVE' => $newBigTitles ] ) );
735  // Update the too-big WAN cache entries now that we have the new HASH
736  foreach ( $newBigTitles as $title => $id ) {
737  // Match logic of loadCachedMessagePageEntry()
738  $this->wanCache->set(
739  $this->bigMessageCacheKey( $cache['HASH'], $title ),
740  ' ' . $newTextByTitle[$title],
741  self::WAN_TTL
742  );
743  }
744  // Mark this cache as definitely being "latest" (non-volatile) so
745  // load() calls do not try to refresh the cache with replica DB data
746  $cache['LATEST'] = time();
747  // Update the process cache
748  $this->cache->set( $code, $cache );
749  // Pre-emptively update the local datacenter cache so things like edit filter and
750  // blacklist changes are reflected immediately; these often use MediaWiki: pages.
751  // The datacenter handling replace() calls should be the same one handling edits
752  // as they require HTTP POST.
753  $this->saveToCaches( $cache, 'all', $code );
754  // Release the lock now that the cache is saved
755  ScopedCallback::consume( $scopedLock );
756 
757  // Relay the purge. Touching this check key expires cache contents
758  // and local cache (APC) validation hash across all datacenters.
759  $this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
760 
761  // Purge the messages in the message blob store and fire any hook handlers
762  $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
763  foreach ( $replacements as list( $title, $msg ) ) {
764  $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
765  $this->hookRunner->onMessageCacheReplace( $title, $newTextByTitle[$title] );
766  }
767  }
768 
775  protected function isCacheExpired( $cache ) {
776  if ( !isset( $cache['VERSION'] ) || !isset( $cache['EXPIRY'] ) ) {
777  return true;
778  }
779  if ( $cache['VERSION'] != MSG_CACHE_VERSION ) {
780  return true;
781  }
782  if ( wfTimestampNow() >= $cache['EXPIRY'] ) {
783  return true;
784  }
785 
786  return false;
787  }
788 
798  protected function saveToCaches( array $cache, $dest, $code = false ) {
799  if ( $dest === 'all' ) {
800  $cacheKey = $this->clusterCache->makeKey( 'messages', $code );
801  $success = $this->clusterCache->set( $cacheKey, $cache );
802  $this->setValidationHash( $code, $cache );
803  } else {
804  $success = true;
805  }
806 
807  $this->saveToLocalCache( $code, $cache );
808 
809  return $success;
810  }
811 
818  protected function getValidationHash( $code ) {
819  $curTTL = null;
820  $value = $this->wanCache->get(
821  $this->wanCache->makeKey( 'messages', $code, 'hash', 'v1' ),
822  $curTTL,
823  [ $this->getCheckKey( $code ) ]
824  );
825 
826  if ( $value ) {
827  $hash = $value['hash'];
828  if ( ( time() - $value['latest'] ) < WANObjectCache::TTL_MINUTE ) {
829  // Cache was recently updated via replace() and should be up-to-date.
830  // That method is only called in the primary datacenter and uses FOR_UPDATE.
831  // Also, it is unlikely that the current datacenter is *now* secondary one.
832  $expired = false;
833  } else {
834  // See if the "check" key was bumped after the hash was generated
835  $expired = ( $curTTL < 0 );
836  }
837  } else {
838  // No hash found at all; cache must regenerate to be safe
839  $hash = false;
840  $expired = true;
841  }
842 
843  return [ $hash, $expired ];
844  }
845 
856  protected function setValidationHash( $code, array $cache ) {
857  $this->wanCache->set(
858  $this->wanCache->makeKey( 'messages', $code, 'hash', 'v1' ),
859  [
860  'hash' => $cache['HASH'],
861  'latest' => $cache['LATEST'] ?? 0
862  ],
863  WANObjectCache::TTL_INDEFINITE
864  );
865  }
866 
872  protected function getReentrantScopedLock( $key, $timeout = self::WAIT_SEC ) {
873  return $this->clusterCache->getScopedLock( $key, $timeout, self::LOCK_TTL, __METHOD__ );
874  }
875 
909  public function get( $key, $useDB = true, $langcode = true ) {
910  if ( is_int( $key ) ) {
911  // Fix numerical strings that somehow become ints
912  // on their way here
913  $key = (string)$key;
914  } elseif ( !is_string( $key ) ) {
915  throw new MWException( 'Non-string key given' );
916  } elseif ( $key === '' ) {
917  // Shortcut: the empty key is always missing
918  return false;
919  }
920 
921  // Normalise title-case input (with some inlining)
922  $lckey = self::normalizeKey( $key );
923 
924  $this->hookRunner->onMessageCache__get( $lckey );
925 
926  // Loop through each language in the fallback list until we find something useful
927  $message = $this->getMessageFromFallbackChain(
928  wfGetLangObj( $langcode ),
929  $lckey,
930  !$this->mDisable && $useDB
931  );
932 
933  // If we still have no message, maybe the key was in fact a full key so try that
934  if ( $message === false ) {
935  $parts = explode( '/', $lckey );
936  // We may get calls for things that are http-urls from sidebar
937  // Let's not load nonexistent languages for those
938  // They usually have more than one slash.
939  if ( count( $parts ) == 2 && $parts[1] !== '' ) {
940  $message = $this->localisationCache->getSubitem( $parts[1], 'messages', $parts[0] );
941  if ( $message === null ) {
942  $message = false;
943  }
944  }
945  }
946 
947  // Post-processing if the message exists
948  if ( $message !== false ) {
949  // Fix whitespace
950  $message = str_replace(
951  [
952  # Fix for trailing whitespace, removed by textarea
953  '&#32;',
954  # Fix for NBSP, converted to space by firefox
955  '&nbsp;',
956  '&#160;',
957  '&shy;'
958  ],
959  [
960  ' ',
961  "\u{00A0}",
962  "\u{00A0}",
963  "\u{00AD}"
964  ],
965  $message
966  );
967  }
968 
969  return $message;
970  }
971 
984  protected function getMessageFromFallbackChain( $lang, $lckey, $useDB ) {
985  $alreadyTried = [];
986 
987  // First try the requested language.
988  $message = $this->getMessageForLang( $lang, $lckey, $useDB, $alreadyTried );
989  if ( $message !== false ) {
990  return $message;
991  }
992 
993  // Now try checking the site language.
994  $message = $this->getMessageForLang( $this->contLang, $lckey, $useDB, $alreadyTried );
995  return $message;
996  }
997 
1008  private function getMessageForLang( $lang, $lckey, $useDB, &$alreadyTried ) {
1009  $langcode = $lang->getCode();
1010 
1011  // Try checking the database for the requested language
1012  if ( $useDB ) {
1013  $uckey = $this->contLang->ucfirst( $lckey );
1014 
1015  if ( !isset( $alreadyTried[$langcode] ) ) {
1016  $message = $this->getMsgFromNamespace(
1017  $this->getMessagePageName( $langcode, $uckey ),
1018  $langcode
1019  );
1020  if ( $message !== false ) {
1021  return $message;
1022  }
1023  $alreadyTried[$langcode] = true;
1024  }
1025  } else {
1026  $uckey = null;
1027  }
1028 
1029  // Check the CDB cache
1030  $message = $lang->getMessage( $lckey );
1031  if ( $message !== null ) {
1032  return $message;
1033  }
1034 
1035  // Try checking the database for all of the fallback languages
1036  if ( $useDB ) {
1037  $fallbackChain = $this->languageFallback->getAll( $langcode );
1038 
1039  foreach ( $fallbackChain as $code ) {
1040  if ( isset( $alreadyTried[$code] ) ) {
1041  continue;
1042  }
1043 
1044  $message = $this->getMsgFromNamespace(
1045  $this->getMessagePageName( $code, $uckey ), $code );
1046 
1047  if ( $message !== false ) {
1048  return $message;
1049  }
1050  $alreadyTried[$code] = true;
1051  }
1052  }
1053 
1054  return false;
1055  }
1056 
1064  private function getMessagePageName( $langcode, $uckey ) {
1065  global $wgLanguageCode;
1066 
1067  if ( $langcode === $wgLanguageCode ) {
1068  // Messages created in the content language will not have the /lang extension
1069  return $uckey;
1070  } else {
1071  return "$uckey/$langcode";
1072  }
1073  }
1074 
1087  public function getMsgFromNamespace( $title, $code ) {
1088  // Load all MediaWiki page definitions into cache. Note that individual keys
1089  // already loaded into cache during this request remain in the cache, which
1090  // includes the value of hook-defined messages.
1091  $this->load( $code );
1092 
1093  $entry = $this->cache->getField( $code, $title );
1094 
1095  if ( $entry !== null ) {
1096  // Message page exists as an override of a software messages
1097  if ( substr( $entry, 0, 1 ) === ' ' ) {
1098  // The message exists and is not '!TOO BIG' or '!ERROR'
1099  return (string)substr( $entry, 1 );
1100  } elseif ( $entry === '!NONEXISTENT' ) {
1101  // The text might be '-' or missing due to some data loss
1102  return false;
1103  }
1104  // Load the message page, utilizing the individual message cache.
1105  // If the page does not exist, there will be no hook handler fallbacks.
1106  $entry = $this->loadCachedMessagePageEntry(
1107  $title,
1108  $code,
1109  $this->cache->getField( $code, 'HASH' )
1110  );
1111  } else {
1112  // Message page either does not exist or does not override a software message
1113  if ( !$this->isMainCacheable( $title, $this->overridable ) ) {
1114  // Message page does not override any software-defined message. A custom
1115  // message might be defined to have content or settings specific to the wiki.
1116  // Load the message page, utilizing the individual message cache as needed.
1117  $entry = $this->loadCachedMessagePageEntry(
1118  $title,
1119  $code,
1120  $this->cache->getField( $code, 'HASH' )
1121  );
1122  }
1123  if ( $entry === null || substr( $entry, 0, 1 ) !== ' ' ) {
1124  // Message does not have a MediaWiki page definition; try hook handlers
1125  $message = false;
1126  $this->hookRunner->onMessagesPreLoad( $title, $message, $code );
1127  if ( $message !== false ) {
1128  $this->cache->setField( $code, $title, ' ' . $message );
1129  } else {
1130  $this->cache->setField( $code, $title, '!NONEXISTENT' );
1131  }
1132 
1133  return $message;
1134  }
1135  }
1136 
1137  if ( $entry !== false && substr( $entry, 0, 1 ) === ' ' ) {
1138  if ( $this->cacheVolatile[$code] ) {
1139  // Make sure that individual keys respect the WAN cache holdoff period too
1140  $this->logger->debug(
1141  __METHOD__ . ': loading volatile key \'{titleKey}\'',
1142  [ 'titleKey' => $title, 'code' => $code ] );
1143  } else {
1144  $this->cache->setField( $code, $title, $entry );
1145  }
1146  // The message exists, so make sure a string is returned
1147  return (string)substr( $entry, 1 );
1148  }
1149 
1150  $this->cache->setField( $code, $title, '!NONEXISTENT' );
1151 
1152  return false;
1153  }
1154 
1161  private function loadCachedMessagePageEntry( $dbKey, $code, $hash ) {
1162  $fname = __METHOD__;
1163  return $this->srvCache->getWithSetCallback(
1164  $this->srvCache->makeKey( 'messages-big', $hash, $dbKey ),
1165  BagOStuff::TTL_HOUR,
1166  function () use ( $code, $dbKey, $hash, $fname ) {
1167  return $this->wanCache->getWithSetCallback(
1168  $this->bigMessageCacheKey( $hash, $dbKey ),
1169  self::WAN_TTL,
1170  function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code, $fname ) {
1171  // Try loading the message from the database
1172  $setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
1173  // Use newKnownCurrent() to avoid querying revision/user tables
1174  $title = Title::makeTitle( NS_MEDIAWIKI, $dbKey );
1175  // Injecting RevisionStore breaks installer since it
1176  // instantiates MessageCache before DB.
1177  $revision = MediaWikiServices::getInstance()
1178  ->getRevisionLookup()
1179  ->getKnownCurrentRevision( $title );
1180  if ( !$revision ) {
1181  // The wiki doesn't have a local override page. Cache absence with normal TTL.
1182  // When overrides are created, self::replace() takes care of the cache.
1183  return '!NONEXISTENT';
1184  }
1185  $content = $revision->getContent( SlotRecord::MAIN );
1186  if ( $content ) {
1187  $message = $this->getMessageTextFromContent( $content );
1188  } else {
1189  $this->logger->warning(
1190  $fname . ': failed to load page text for \'{titleKey}\'',
1191  [ 'titleKey' => $dbKey, 'code' => $code ]
1192  );
1193  $message = null;
1194  }
1195 
1196  if ( !is_string( $message ) ) {
1197  // Revision failed to load Content, or Content is incompatible with wikitext.
1198  // Possibly a temporary loading failure.
1199  $ttl = 5;
1200 
1201  return '!NONEXISTENT';
1202  }
1203 
1204  return ' ' . $message;
1205  }
1206  );
1207  }
1208  );
1209  }
1210 
1218  public function transform( $message, $interface = false, $language = null, $title = null ) {
1219  // Avoid creating parser if nothing to transform
1220  if ( strpos( $message, '{{' ) === false ) {
1221  return $message;
1222  }
1223 
1224  if ( $this->mInParser ) {
1225  return $message;
1226  }
1227 
1228  $parser = $this->getParser();
1229  if ( $parser ) {
1230  $popts = $this->getParserOptions();
1231  $popts->setInterfaceMessage( $interface );
1232  $popts->setTargetLanguage( $language );
1233 
1234  $userlang = $popts->setUserLang( $language );
1235  $this->mInParser = true;
1236  $message = $parser->transformMsg( $message, $popts, $title );
1237  $this->mInParser = false;
1238  $popts->setUserLang( $userlang );
1239  }
1240 
1241  return $message;
1242  }
1243 
1247  public function getParser() {
1248  if ( !$this->mParser ) {
1249  $parser = MediaWikiServices::getInstance()->getParser();
1250  # Do some initialisation so that we don't have to do it twice
1251  $parser->firstCallInit();
1252  # Clone it and store it
1253  $this->mParser = clone $parser;
1254  }
1255 
1256  return $this->mParser;
1257  }
1258 
1267  public function parse( $text, $title = null, $linestart = true,
1268  $interface = false, $language = null
1269  ) {
1270  global $wgTitle;
1271 
1272  if ( $this->mInParser ) {
1273  return htmlspecialchars( $text );
1274  }
1275 
1276  $parser = $this->getParser();
1277  $popts = $this->getParserOptions();
1278  $popts->setInterfaceMessage( $interface );
1279 
1280  if ( is_string( $language ) ) {
1281  $language = $this->langFactory->getLanguage( $language );
1282  }
1283  $popts->setTargetLanguage( $language );
1284 
1285  if ( !$title || !$title instanceof Title ) {
1286  $logger = LoggerFactory::getInstance( 'GlobalTitleFail' );
1287  $logger->info(
1288  __METHOD__ . ' called with no title set.',
1289  [ 'exception' => new Exception ]
1290  );
1291  $title = $wgTitle;
1292  }
1293  // Sometimes $wgTitle isn't set either...
1294  if ( !$title ) {
1295  # It's not uncommon having a null $wgTitle in scripts. See r80898
1296  # Create a ghost title in such case
1297  $title = Title::makeTitle( NS_SPECIAL, 'Badtitle/title not set in ' . __METHOD__ );
1298  }
1299 
1300  $this->mInParser = true;
1301  $res = $parser->parse( $text, $title, $popts, $linestart );
1302  $this->mInParser = false;
1303 
1304  return $res;
1305  }
1306 
1307  public function disable() {
1308  $this->mDisable = true;
1309  }
1310 
1311  public function enable() {
1312  $this->mDisable = false;
1313  }
1314 
1327  public function isDisabled() {
1328  return $this->mDisable;
1329  }
1330 
1336  public function clear() {
1337  $langs = $this->languageNameUtils->getLanguageNames( null, 'mw' );
1338  foreach ( array_keys( $langs ) as $code ) {
1339  $this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
1340  }
1341  $this->cache->clear();
1342  }
1343 
1348  public function figureMessage( $key ) {
1349  global $wgLanguageCode;
1350 
1351  $pieces = explode( '/', $key );
1352  if ( count( $pieces ) < 2 ) {
1353  return [ $key, $wgLanguageCode ];
1354  }
1355 
1356  $lang = array_pop( $pieces );
1357  if ( !$this->languageNameUtils->getLanguageName( $lang, null, 'mw' ) ) {
1358  return [ $key, $wgLanguageCode ];
1359  }
1360 
1361  $message = implode( '/', $pieces );
1362 
1363  return [ $message, $lang ];
1364  }
1365 
1374  public function getAllMessageKeys( $code ) {
1375  $this->load( $code );
1376  if ( !$this->cache->has( $code ) ) {
1377  // Apparently load() failed
1378  return null;
1379  }
1380  // Remove administrative keys
1381  $cache = $this->cache->get( $code );
1382  unset( $cache['VERSION'] );
1383  unset( $cache['EXPIRY'] );
1384  unset( $cache['EXCESSIVE'] );
1385  // Remove any !NONEXISTENT keys
1386  $cache = array_diff( $cache, [ '!NONEXISTENT' ] );
1387 
1388  // Keys may appear with a capital first letter. lcfirst them.
1389  return array_map( [ $this->contLang, 'lcfirst' ], array_keys( $cache ) );
1390  }
1391 
1399  public function updateMessageOverride( LinkTarget $linkTarget, Content $content = null ) {
1400  $msgText = $this->getMessageTextFromContent( $content );
1401  if ( $msgText === null ) {
1402  $msgText = false; // treat as not existing
1403  }
1404 
1405  $this->replace( $linkTarget->getDBkey(), $msgText );
1406 
1407  if ( $this->contLangConverter->hasVariants() ) {
1408  $this->contLangConverter->updateConversionTable( $linkTarget );
1409  }
1410  }
1411 
1416  public function getCheckKey( $code ) {
1417  return $this->wanCache->makeKey( 'messages', $code );
1418  }
1419 
1424  private function getMessageTextFromContent( Content $content = null ) {
1425  // @TODO: could skip pseudo-messages like js/css here, based on content model
1426  if ( $content ) {
1427  // Message page exists...
1428  // XXX: Is this the right way to turn a Content object into a message?
1429  // NOTE: $content is typically either WikitextContent, JavaScriptContent or
1430  // CssContent. MessageContent is *not* used for storing messages, it's
1431  // only used for wrapping them when needed.
1432  $msgText = $content->getWikitextForTransclusion();
1433  if ( $msgText === false || $msgText === null ) {
1434  // This might be due to some kind of misconfiguration...
1435  $msgText = null;
1436  $this->logger->warning(
1437  __METHOD__ . ": message content doesn't provide wikitext "
1438  . "(content model: " . $content->getModel() . ")" );
1439  }
1440  } else {
1441  // Message page does not exist...
1442  $msgText = false;
1443  }
1444 
1445  return $msgText;
1446  }
1447 
1453  private function bigMessageCacheKey( $hash, $title ) {
1454  return $this->wanCache->makeKey( 'messages-big', $hash, $title );
1455  }
1456 }
MessageCache\transform
transform( $message, $interface=false, $language=null, $title=null)
Definition: MessageCache.php:1218
MessageCache\$mParser
Parser $mParser
Definition: MessageCache.php:98
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:44
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:50
MessageCache\$contLangConverter
ILanguageConverter $contLangConverter
Definition: MessageCache.php:114
MessageCache\setValidationHash
setValidationHash( $code, array $cache)
Set the md5 used to validate the local disk cache.
Definition: MessageCache.php:856
MessageCache\updateMessageOverride
updateMessageOverride(LinkTarget $linkTarget, Content $content=null)
Purge message caches when a MediaWiki: page is created, updated, or deleted.
Definition: MessageCache.php:1399
MessageCache\isLanguageLoaded
isLanguageLoaded( $lang)
Whether the language was loaded and its data is still in the process cache.
Definition: MessageCache.php:622
MessageCache\$clusterCache
BagOStuff $clusterCache
Definition: MessageCache.php:108
MessageCache\normalizeKey
static normalizeKey( $key)
Normalize message key input.
Definition: MessageCache.php:143
MessageCache\parse
parse( $text, $title=null, $linestart=true, $interface=false, $language=null)
Definition: MessageCache.php:1267
EmptyBagOStuff
A BagOStuff object with no objects in it.
Definition: EmptyBagOStuff.php:29
MessageCache\saveToCaches
saveToCaches(array $cache, $dest, $code=false)
Shortcut to update caches.
Definition: MessageCache.php:798
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:158
MessageCache\enable
enable()
Definition: MessageCache.php:1311
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
MessageCache\$mParserOptions
ParserOptions $mParserOptions
Message cache has its own parser which it uses to transform messages.
Definition: MessageCache.php:96
true
return true
Definition: router.php:90
MediaWiki\Languages\LanguageFactory
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: LanguageFactory.php:42
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1815
MessageCache\$mInParser
bool $mInParser
Definition: MessageCache.php:103
MessageCache\loadCachedMessagePageEntry
loadCachedMessagePageEntry( $dbKey, $code, $hash)
Definition: MessageCache.php:1161
MessageCache\$logger
LoggerInterface $logger
Definition: MessageCache.php:58
$wgMaxMsgCacheEntrySize
$wgMaxMsgCacheEntrySize
Maximum entry size in the message cache, in bytes.
Definition: DefaultSettings.php:3237
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred update queue for execution at the appropriate time.
Definition: DeferredUpdates.php:106
ParserOptions\newFromAnon
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Definition: ParserOptions.php:1063
MediaWiki\Languages\LanguageFallback
Definition: LanguageFallback.php:31
MessageCache\setLogger
setLogger(LoggerInterface $logger)
Definition: MessageCache.php:202
MessageCache\LOCK_TTL
const LOCK_TTL
How long memcached locks last.
Definition: MessageCache.php:56
BagOStuff
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:71
MessageCache\saveToLocalCache
saveToLocalCache( $code, $cache)
Save the cache to APC.
Definition: MessageCache.php:252
$success
$success
Definition: NoLocalSettings.php:42
$res
$res
Definition: testCompression.php:57
serialize
serialize()
Definition: ApiMessageTrait.php:138
$revQuery
$revQuery
Definition: testCompression.php:56
$wgTitle
$wgTitle
Definition: Setup.php:794
MediaWiki\Languages\LanguageNameUtils
A service that provides utilities to do with language names and codes.
Definition: LanguageNameUtils.php:42
MessageCache\getValidationHash
getValidationHash( $code)
Get the md5 used to validate the local APC cache.
Definition: MessageCache.php:818
$dbr
$dbr
Definition: testCompression.php:54
Revision
Definition: Revision.php:40
MessageCache\getMessageTextFromContent
getMessageTextFromContent(Content $content=null)
Definition: MessageCache.php:1424
MessageCache\$hookRunner
HookRunner $hookRunner
Definition: MessageCache.php:124
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:58
$wgAdaptiveMessageCache
$wgAdaptiveMessageCache
Instead of caching everything, only cache those messages which have been customised in the site conte...
Definition: DefaultSettings.php:2712
MessageCache\loadFromDB
loadFromDB( $code, $mode=null)
Loads cacheable messages from the database.
Definition: MessageCache.php:486
MWException
MediaWiki exception.
Definition: MWException.php:29
MessageCache\getCheckKey
getCheckKey( $code)
Definition: MessageCache.php:1416
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:157
MessageCache\getMsgFromNamespace
getMsgFromNamespace( $title, $code)
Get a message from the MediaWiki namespace, with caching.
Definition: MessageCache.php:1087
MessageCache\isMainCacheable
isMainCacheable( $name, array $overridable)
Definition: MessageCache.php:637
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
MessageCache\bigMessageCacheKey
bigMessageCacheKey( $hash, $title)
Definition: MessageCache.php:1453
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:523
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2475
MessageCache\$languageFallback
LanguageFallback $languageFallback
Definition: MessageCache.php:122
MediaWiki
A helper class for throttling authentication attempts.
MessageCache\getMessagePageName
getMessagePageName( $langcode, $uckey)
Get the message page name for a given language.
Definition: MessageCache.php:1064
MSG_CACHE_VERSION
const MSG_CACHE_VERSION
MediaWiki message cache structure version.
Definition: MessageCache.php:42
MapCacheLRU
Handles a simple LRU key/value map with a maximum number of entries.
Definition: MapCacheLRU.php:38
MessageCache\$cacheVolatile
bool[] $cacheVolatile
Map of (language code => boolean)
Definition: MessageCache.php:84
MessageCache\figureMessage
figureMessage( $key)
Definition: MessageCache.php:1348
wfGetLangObj
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
Definition: GlobalFunctions.php:1170
MessageCache\$srvCache
BagOStuff $srvCache
Definition: MessageCache.php:110
$title
$title
Definition: testCompression.php:38
MessageCache\replace
replace( $title, $text)
Updates cache as necessary when message page is changed.
Definition: MessageCache.php:652
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:591
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1844
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MessageCache\getMessageFromFallbackChain
getMessageFromFallbackChain( $lang, $lckey, $useDB)
Given a language, try and fetch messages from that language.
Definition: MessageCache.php:984
MessageCacheUpdate
Message cache purging and in-place update handler for specific message page changes.
Definition: MessageCacheUpdate.php:32
MessageCache\FOR_UPDATE
const FOR_UPDATE
Definition: MessageCache.php:51
MessageCache\singleton
static singleton()
Get the singleton instance of this class.
Definition: MessageCache.php:133
MessageCache\WAIT_SEC
const WAIT_SEC
How long to wait for memcached locks.
Definition: MessageCache.php:54
MessageCache\$overridable
array $overridable
Map of (lowercase message key => index) for all software defined messages.
Definition: MessageCache.php:79
MessageCache\$cache
MapCacheLRU $cache
Process cache of loaded messages that are defined in MediaWiki namespace.
Definition: MessageCache.php:72
$content
$content
Definition: router.php:76
MessageCache\$languageNameUtils
LanguageNameUtils $languageNameUtils
Definition: MessageCache.php:120
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:28
MessageCache\clear
clear()
Clear all stored messages in global and local cache.
Definition: MessageCache.php:1336
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:125
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3093
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part with underscores.
MessageCache\getReentrantScopedLock
getReentrantScopedLock( $key, $timeout=self::WAIT_SEC)
Definition: MessageCache.php:872
MapCacheLRU\set
set( $key, $value, $rank=self::RANK_TOP)
Set a key/value pair.
Definition: MapCacheLRU.php:111
MessageCache\$localisationCache
LocalisationCache $localisationCache
Definition: MessageCache.php:118
LocalisationCache
Class for caching the contents of localisation files, Messages*.php and *.i18n.php.
Definition: LocalisationCache.php:43
Parser
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition: Parser.php:84
Content
Base interface for content objects.
Definition: Content.php:35
MessageCache\getParser
getParser()
Definition: MessageCache.php:1247
MessageCache\getLocalCache
getLocalCache( $code)
Try to load the cache from APC.
Definition: MessageCache.php:240
MessageCache\$langFactory
LanguageFactory $langFactory
Definition: MessageCache.php:116
MessageCache\refreshAndReplaceInternal
refreshAndReplaceInternal( $code, array $replacements)
Definition: MessageCache.php:686
Title
Represents a title within MediaWiki.
Definition: Title.php:41
MessageCache\loadFromDBWithLock
loadFromDBWithLock( $code, array &$where, $mode=null)
Definition: MessageCache.php:424
MessageCache\$mDisable
bool $mDisable
Should mean that database cannot be used, but check.
Definition: MessageCache.php:90
MessageCache\load
load( $code, $mode=null)
Loads messages from caches or from database in this order: (1) local message cache (if $wgUseLocalMes...
Definition: MessageCache.php:278
MessageCache\__construct
__construct(WANObjectCache $wanCache, BagOStuff $clusterCache, BagOStuff $serverCache, Language $contLang, ILanguageConverter $contLangConverter, LoggerInterface $logger, array $options, LanguageFactory $langFactory, LocalisationCache $localisationCache, LanguageNameUtils $languageNameUtils, LanguageFallback $languageFallback, HookContainer $hookContainer)
Definition: MessageCache.php:171
MessageCache\$wanCache
WANObjectCache $wanCache
Definition: MessageCache.php:106
DeferredUpdates\PRESEND
const PRESEND
Definition: DeferredUpdates.php:84
MapCacheLRU\get
get( $key, $maxAge=INF, $default=null)
Get the value for a key.
Definition: MapCacheLRU.php:169
MessageCache\isDisabled
isDisabled()
Whether DB/cache usage is disabled for determining messages.
Definition: MessageCache.php:1327
MessageCache\getParserOptions
getParserOptions()
ParserOptions is lazy initialised.
Definition: MessageCache.php:211
MessageCache\isCacheExpired
isCacheExpired( $cache)
Is the given cache array expired due to time passing or a version change?
Definition: MessageCache.php:775
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:44
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:77
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:564
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
MessageCache\disable
disable()
Definition: MessageCache.php:1307
MessageCache
Cache of messages that are defined by MediaWiki namespace pages or by hooks.
Definition: MessageCache.php:50
MessageCache\getMessageForLang
getMessageForLang( $lang, $lckey, $useDB, &$alreadyTried)
Given a language, try and fetch messages from that language and its fallbacks.
Definition: MessageCache.php:1008
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
MessageCache\getAllMessageKeys
getAllMessageKeys( $code)
Get all message keys stored in the message cache for a given language.
Definition: MessageCache.php:1374
MessageCache\$contLang
Language $contLang
Definition: MessageCache.php:112