Merge "filerepo: Inject the WAN cache info FileRepo instances"
[lhc/web/wiklou.git] / includes / cache / MessageCache.php
1 <?php
2 /**
3 * Localisation messages cache.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Cache
22 */
23 use MediaWiki\MediaWikiServices;
24 use Wikimedia\ScopedCallback;
25 use MediaWiki\Logger\LoggerFactory;
26 use Wikimedia\Rdbms\Database;
27
28 /**
29 * MediaWiki message cache structure version.
30 * Bump this whenever the message cache format has changed.
31 */
32 define( 'MSG_CACHE_VERSION', 2 );
33
34 /**
35 * Cache of messages that are defined by MediaWiki namespace pages or by hooks
36 *
37 * Performs various MediaWiki namespace-related functions
38 * @ingroup Cache
39 */
40 class MessageCache {
41 const FOR_UPDATE = 1; // force message reload
42
43 /** How long to wait for memcached locks */
44 const WAIT_SEC = 15;
45 /** How long memcached locks last */
46 const LOCK_TTL = 30;
47
48 /**
49 * Process cache of loaded messages that are defined in MediaWiki namespace
50 *
51 * @var MapCacheLRU Map of (language code => key => " <MESSAGE>" or "!TOO BIG")
52 */
53 protected $cache;
54
55 /**
56 * Map of (lowercase message key => index) for all software defined messages
57 *
58 * @var array
59 */
60 protected $overridable;
61
62 /**
63 * @var bool[] Map of (language code => boolean)
64 */
65 protected $cacheVolatile = [];
66
67 /**
68 * Should mean that database cannot be used, but check
69 * @var bool $mDisable
70 */
71 protected $mDisable;
72
73 /**
74 * Lifetime for cache, used by object caching.
75 * Set on construction, see __construct().
76 */
77 protected $mExpiry;
78
79 /**
80 * Message cache has its own parser which it uses to transform messages
81 * @var ParserOptions
82 */
83 protected $mParserOptions;
84 /** @var Parser */
85 protected $mParser;
86
87 /**
88 * @var bool $mInParser
89 */
90 protected $mInParser = false;
91
92 /** @var WANObjectCache */
93 protected $wanCache;
94 /** @var BagOStuff */
95 protected $clusterCache;
96 /** @var BagOStuff */
97 protected $srvCache;
98 /** @var Language */
99 protected $contLang;
100
101 /**
102 * Singleton instance
103 *
104 * @var MessageCache $instance
105 */
106 private static $instance;
107
108 /**
109 * Get the signleton instance of this class
110 *
111 * @since 1.18
112 * @return MessageCache
113 */
114 public static function singleton() {
115 if ( self::$instance === null ) {
116 global $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgUseLocalMessageCache;
117 $services = MediaWikiServices::getInstance();
118 self::$instance = new self(
119 $services->getMainWANObjectCache(),
120 wfGetMessageCacheStorage(),
121 $wgUseLocalMessageCache
122 ? $services->getLocalServerObjectCache()
123 : new EmptyBagOStuff(),
124 $wgUseDatabaseMessages,
125 $wgMsgCacheExpiry,
126 $services->getContentLanguage()
127 );
128 }
129
130 return self::$instance;
131 }
132
133 /**
134 * Destroy the singleton instance
135 *
136 * @since 1.18
137 */
138 public static function destroyInstance() {
139 self::$instance = null;
140 }
141
142 /**
143 * Normalize message key input
144 *
145 * @param string $key Input message key to be normalized
146 * @return string Normalized message key
147 */
148 public static function normalizeKey( $key ) {
149 $lckey = strtr( $key, ' ', '_' );
150 if ( ord( $lckey ) < 128 ) {
151 $lckey[0] = strtolower( $lckey[0] );
152 } else {
153 $lckey = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $lckey );
154 }
155
156 return $lckey;
157 }
158
159 /**
160 * @param WANObjectCache $wanCache
161 * @param BagOStuff $clusterCache
162 * @param BagOStuff $serverCache
163 * @param bool $useDB Whether to look for message overrides (e.g. MediaWiki: pages)
164 * @param int $expiry Lifetime for cache. @see $mExpiry.
165 * @param Language|null $contLang Content language of site
166 */
167 public function __construct(
168 WANObjectCache $wanCache,
169 BagOStuff $clusterCache,
170 BagOStuff $serverCache,
171 $useDB,
172 $expiry,
173 Language $contLang = null
174 ) {
175 $this->wanCache = $wanCache;
176 $this->clusterCache = $clusterCache;
177 $this->srvCache = $serverCache;
178
179 $this->cache = new MapCacheLRU( 5 ); // limit size for sanity
180
181 $this->mDisable = !$useDB;
182 $this->mExpiry = $expiry;
183 $this->contLang = $contLang ?? MediaWikiServices::getInstance()->getContentLanguage();
184 }
185
186 /**
187 * ParserOptions is lazy initialised.
188 *
189 * @return ParserOptions
190 */
191 function getParserOptions() {
192 global $wgUser;
193
194 if ( !$this->mParserOptions ) {
195 if ( !$wgUser->isSafeToLoad() ) {
196 // $wgUser isn't unstubbable yet, so don't try to get a
197 // ParserOptions for it. And don't cache this ParserOptions
198 // either.
199 $po = ParserOptions::newFromAnon();
200 $po->setAllowUnsafeRawHtml( false );
201 $po->setTidy( true );
202 return $po;
203 }
204
205 $this->mParserOptions = new ParserOptions;
206 // Messages may take parameters that could come
207 // from malicious sources. As a precaution, disable
208 // the <html> parser tag when parsing messages.
209 $this->mParserOptions->setAllowUnsafeRawHtml( false );
210 // For the same reason, tidy the output!
211 $this->mParserOptions->setTidy( true );
212 }
213
214 return $this->mParserOptions;
215 }
216
217 /**
218 * Try to load the cache from APC.
219 *
220 * @param string $code Optional language code, see documenation of load().
221 * @return array|bool The cache array, or false if not in cache.
222 */
223 protected function getLocalCache( $code ) {
224 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
225
226 return $this->srvCache->get( $cacheKey );
227 }
228
229 /**
230 * Save the cache to APC.
231 *
232 * @param string $code
233 * @param array $cache The cache array
234 */
235 protected function saveToLocalCache( $code, $cache ) {
236 $cacheKey = $this->srvCache->makeKey( __CLASS__, $code );
237 $this->srvCache->set( $cacheKey, $cache );
238 }
239
240 /**
241 * Loads messages from caches or from database in this order:
242 * (1) local message cache (if $wgUseLocalMessageCache is enabled)
243 * (2) memcached
244 * (3) from the database.
245 *
246 * When successfully loading from (2) or (3), all higher level caches are
247 * updated for the newest version.
248 *
249 * Nothing is loaded if member variable mDisable is true, either manually
250 * set by calling code or if message loading fails (is this possible?).
251 *
252 * Returns true if cache is already populated or it was successfully populated,
253 * or false if populating empty cache fails. Also returns true if MessageCache
254 * is disabled.
255 *
256 * @param string $code Language to which load messages
257 * @param int|null $mode Use MessageCache::FOR_UPDATE to skip process cache [optional]
258 * @throws InvalidArgumentException
259 * @return bool
260 */
261 protected function load( $code, $mode = null ) {
262 if ( !is_string( $code ) ) {
263 throw new InvalidArgumentException( "Missing language code" );
264 }
265
266 # Don't do double loading...
267 if ( $this->cache->has( $code ) && $mode != self::FOR_UPDATE ) {
268 return true;
269 }
270
271 $this->overridable = array_flip( Language::getMessageKeysFor( $code ) );
272
273 # 8 lines of code just to say (once) that message cache is disabled
274 if ( $this->mDisable ) {
275 static $shownDisabled = false;
276 if ( !$shownDisabled ) {
277 wfDebug( __METHOD__ . ": disabled\n" );
278 $shownDisabled = true;
279 }
280
281 return true;
282 }
283
284 # Loading code starts
285 $success = false; # Keep track of success
286 $staleCache = false; # a cache array with expired data, or false if none has been loaded
287 $where = []; # Debug info, delayed to avoid spamming debug log too much
288
289 # Hash of the contents is stored in memcache, to detect if data-center cache
290 # or local cache goes out of date (e.g. due to replace() on some other server)
291 list( $hash, $hashVolatile ) = $this->getValidationHash( $code );
292 $this->cacheVolatile[$code] = $hashVolatile;
293
294 # Try the local cache and check against the cluster hash key...
295 $cache = $this->getLocalCache( $code );
296 if ( !$cache ) {
297 $where[] = 'local cache is empty';
298 } elseif ( !isset( $cache['HASH'] ) || $cache['HASH'] !== $hash ) {
299 $where[] = 'local cache has the wrong hash';
300 $staleCache = $cache;
301 } elseif ( $this->isCacheExpired( $cache ) ) {
302 $where[] = 'local cache is expired';
303 $staleCache = $cache;
304 } elseif ( $hashVolatile ) {
305 $where[] = 'local cache validation key is expired/volatile';
306 $staleCache = $cache;
307 } else {
308 $where[] = 'got from local cache';
309 $this->cache->set( $code, $cache );
310 $success = true;
311 }
312
313 if ( !$success ) {
314 $cacheKey = $this->clusterCache->makeKey( 'messages', $code );
315 # Try the global cache. If it is empty, try to acquire a lock. If
316 # the lock can't be acquired, wait for the other thread to finish
317 # and then try the global cache a second time.
318 for ( $failedAttempts = 0; $failedAttempts <= 1; $failedAttempts++ ) {
319 if ( $hashVolatile && $staleCache ) {
320 # Do not bother fetching the whole cache blob to avoid I/O.
321 # Instead, just try to get the non-blocking $statusKey lock
322 # below, and use the local stale value if it was not acquired.
323 $where[] = 'global cache is presumed expired';
324 } else {
325 $cache = $this->clusterCache->get( $cacheKey );
326 if ( !$cache ) {
327 $where[] = 'global cache is empty';
328 } elseif ( $this->isCacheExpired( $cache ) ) {
329 $where[] = 'global cache is expired';
330 $staleCache = $cache;
331 } elseif ( $hashVolatile ) {
332 # DB results are replica DB lag prone until the holdoff TTL passes.
333 # By then, updates should be reflected in loadFromDBWithLock().
334 # One thread renerates the cache while others use old values.
335 $where[] = 'global cache is expired/volatile';
336 $staleCache = $cache;
337 } else {
338 $where[] = 'got from global cache';
339 $this->cache->set( $code, $cache );
340 $this->saveToCaches( $cache, 'local-only', $code );
341 $success = true;
342 }
343 }
344
345 if ( $success ) {
346 # Done, no need to retry
347 break;
348 }
349
350 # We need to call loadFromDB. Limit the concurrency to one process.
351 # This prevents the site from going down when the cache expires.
352 # Note that the DB slam protection lock here is non-blocking.
353 $loadStatus = $this->loadFromDBWithLock( $code, $where, $mode );
354 if ( $loadStatus === true ) {
355 $success = true;
356 break;
357 } elseif ( $staleCache ) {
358 # Use the stale cache while some other thread constructs the new one
359 $where[] = 'using stale cache';
360 $this->cache->set( $code, $staleCache );
361 $success = true;
362 break;
363 } elseif ( $failedAttempts > 0 ) {
364 # Already blocked once, so avoid another lock/unlock cycle.
365 # This case will typically be hit if memcached is down, or if
366 # loadFromDB() takes longer than LOCK_WAIT.
367 $where[] = "could not acquire status key.";
368 break;
369 } elseif ( $loadStatus === 'cantacquire' ) {
370 # Wait for the other thread to finish, then retry. Normally,
371 # the memcached get() will then yeild the other thread's result.
372 $where[] = 'waited for other thread to complete';
373 $this->getReentrantScopedLock( $cacheKey );
374 } else {
375 # Disable cache; $loadStatus is 'disabled'
376 break;
377 }
378 }
379 }
380
381 if ( !$success ) {
382 $where[] = 'loading FAILED - cache is disabled';
383 $this->mDisable = true;
384 $this->cache->set( $code, [] );
385 wfDebugLog( 'MessageCacheError', __METHOD__ . ": Failed to load $code\n" );
386 # This used to throw an exception, but that led to nasty side effects like
387 # the whole wiki being instantly down if the memcached server died
388 }
389
390 if ( !$this->cache->has( $code ) ) { // sanity
391 throw new LogicException( "Process cache for '$code' should be set by now." );
392 }
393
394 $info = implode( ', ', $where );
395 wfDebugLog( 'MessageCache', __METHOD__ . ": Loading $code... $info\n" );
396
397 return $success;
398 }
399
400 /**
401 * @param string $code
402 * @param array &$where List of wfDebug() comments
403 * @param int|null $mode Use MessageCache::FOR_UPDATE to use DB_MASTER
404 * @return bool|string True on success or one of ("cantacquire", "disabled")
405 */
406 protected function loadFromDBWithLock( $code, array &$where, $mode = null ) {
407 # If cache updates on all levels fail, give up on message overrides.
408 # This is to avoid easy site outages; see $saveSuccess comments below.
409 $statusKey = $this->clusterCache->makeKey( 'messages', $code, 'status' );
410 $status = $this->clusterCache->get( $statusKey );
411 if ( $status === 'error' ) {
412 $where[] = "could not load; method is still globally disabled";
413 return 'disabled';
414 }
415
416 # Now let's regenerate
417 $where[] = 'loading from database';
418
419 # Lock the cache to prevent conflicting writes.
420 # This lock is non-blocking so stale cache can quickly be used.
421 # Note that load() will call a blocking getReentrantScopedLock()
422 # after this if it really need to wait for any current thread.
423 $cacheKey = $this->clusterCache->makeKey( 'messages', $code );
424 $scopedLock = $this->getReentrantScopedLock( $cacheKey, 0 );
425 if ( !$scopedLock ) {
426 $where[] = 'could not acquire main lock';
427 return 'cantacquire';
428 }
429
430 $cache = $this->loadFromDB( $code, $mode );
431 $this->cache->set( $code, $cache );
432 $saveSuccess = $this->saveToCaches( $cache, 'all', $code );
433
434 if ( !$saveSuccess ) {
435 /**
436 * Cache save has failed.
437 *
438 * There are two main scenarios where this could be a problem:
439 * - The cache is more than the maximum size (typically 1MB compressed).
440 * - Memcached has no space remaining in the relevant slab class. This is
441 * unlikely with recent versions of memcached.
442 *
443 * Either way, if there is a local cache, nothing bad will happen. If there
444 * is no local cache, disabling the message cache for all requests avoids
445 * incurring a loadFromDB() overhead on every request, and thus saves the
446 * wiki from complete downtime under moderate traffic conditions.
447 */
448 if ( $this->srvCache instanceof EmptyBagOStuff ) {
449 $this->clusterCache->set( $statusKey, 'error', 60 * 5 );
450 $where[] = 'could not save cache, disabled globally for 5 minutes';
451 } else {
452 $where[] = "could not save global cache";
453 }
454 }
455
456 return true;
457 }
458
459 /**
460 * Loads cacheable messages from the database. Messages bigger than
461 * $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded
462 * on-demand from the database later.
463 *
464 * @param string $code Language code
465 * @param int|null $mode Use MessageCache::FOR_UPDATE to skip process cache
466 * @return array Loaded messages for storing in caches
467 */
468 protected function loadFromDB( $code, $mode = null ) {
469 global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache;
470
471 // (T164666) The query here performs really poorly on WMF's
472 // contributions replicas. We don't have a way to say "any group except
473 // contributions", so for the moment let's specify 'api'.
474 // @todo: Get rid of this hack.
475 $dbr = wfGetDB( ( $mode == self::FOR_UPDATE ) ? DB_MASTER : DB_REPLICA, 'api' );
476
477 $cache = [];
478
479 $mostused = []; // list of "<cased message key>/<code>"
480 if ( $wgAdaptiveMessageCache && $code !== $wgLanguageCode ) {
481 if ( !$this->cache->has( $wgLanguageCode ) ) {
482 $this->load( $wgLanguageCode );
483 }
484 $mostused = array_keys( $this->cache->get( $wgLanguageCode ) );
485 foreach ( $mostused as $key => $value ) {
486 $mostused[$key] = "$value/$code";
487 }
488 }
489
490 // Get the list of software-defined messages in core/extensions
491 $overridable = array_flip( Language::getMessageKeysFor( $wgLanguageCode ) );
492
493 // Common conditions
494 $conds = [
495 'page_is_redirect' => 0,
496 'page_namespace' => NS_MEDIAWIKI,
497 ];
498 if ( count( $mostused ) ) {
499 $conds['page_title'] = $mostused;
500 } elseif ( $code !== $wgLanguageCode ) {
501 $conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), '/', $code );
502 } else {
503 # Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
504 # other than language code.
505 $conds[] = 'page_title NOT' .
506 $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
507 }
508
509 // Set the stubs for oversized software-defined messages in the main cache map
510 $res = $dbr->select(
511 'page',
512 [ 'page_title', 'page_latest' ],
513 array_merge( $conds, [ 'page_len > ' . intval( $wgMaxMsgCacheEntrySize ) ] ),
514 __METHOD__ . "($code)-big"
515 );
516 foreach ( $res as $row ) {
517 $name = $this->contLang->lcfirst( $row->page_title );
518 // Include entries/stubs for all keys in $mostused in adaptive mode
519 if ( $wgAdaptiveMessageCache || isset( $overridable[$name] ) ) {
520 $cache[$row->page_title] = '!TOO BIG';
521 }
522 // At least include revision ID so page changes are reflected in the hash
523 $cache['EXCESSIVE'][$row->page_title] = $row->page_latest;
524 }
525
526 // Set the text for small software-defined messages in the main cache map
527 $res = $dbr->select(
528 [ 'page', 'revision', 'text' ],
529 [ 'page_title', 'page_latest', 'old_id', 'old_text', 'old_flags' ],
530 array_merge( $conds, [ 'page_len <= ' . intval( $wgMaxMsgCacheEntrySize ) ] ),
531 __METHOD__ . "($code)-small",
532 [],
533 [
534 'revision' => [ 'JOIN', 'page_latest=rev_id' ],
535 'text' => [ 'JOIN', 'rev_text_id=old_id' ],
536 ]
537 );
538 foreach ( $res as $row ) {
539 $name = $this->contLang->lcfirst( $row->page_title );
540 // Include entries/stubs for all keys in $mostused in adaptive mode
541 if ( $wgAdaptiveMessageCache || isset( $overridable[$name] ) ) {
542 $text = Revision::getRevisionText( $row );
543 if ( $text === false ) {
544 // Failed to fetch data; possible ES errors?
545 // Store a marker to fetch on-demand as a workaround...
546 // TODO Use a differnt marker
547 $entry = '!TOO BIG';
548 wfDebugLog(
549 'MessageCache',
550 __METHOD__
551 . ": failed to load message page text for {$row->page_title} ($code)"
552 );
553 } else {
554 $entry = ' ' . $text;
555 }
556 $cache[$row->page_title] = $entry;
557 } else {
558 // T193271: cache object gets too big and slow to generate.
559 // At least include revision ID so page changes are reflected in the hash.
560 $cache['EXCESSIVE'][$row->page_title] = $row->page_latest;
561 }
562 }
563
564 $cache['VERSION'] = MSG_CACHE_VERSION;
565 ksort( $cache );
566
567 # Hash for validating local cache (APC). No need to take into account
568 # messages larger than $wgMaxMsgCacheEntrySize, since those are only
569 # stored and fetched from memcache.
570 $cache['HASH'] = md5( serialize( $cache ) );
571 $cache['EXPIRY'] = wfTimestamp( TS_MW, time() + $this->mExpiry );
572 unset( $cache['EXCESSIVE'] ); // only needed for hash
573
574 return $cache;
575 }
576
577 /**
578 * Updates cache as necessary when message page is changed
579 *
580 * @param string $title Message cache key with initial uppercase letter
581 * @param string|bool $text New contents of the page (false if deleted)
582 */
583 public function replace( $title, $text ) {
584 global $wgLanguageCode;
585
586 if ( $this->mDisable ) {
587 return;
588 }
589
590 list( $msg, $code ) = $this->figureMessage( $title );
591 if ( strpos( $title, '/' ) !== false && $code === $wgLanguageCode ) {
592 // Content language overrides do not use the /<code> suffix
593 return;
594 }
595
596 // (a) Update the process cache with the new message text
597 if ( $text === false ) {
598 // Page deleted
599 $this->cache->setField( $code, $title, '!NONEXISTENT' );
600 } else {
601 // Ignore $wgMaxMsgCacheEntrySize so the process cache is up to date
602 $this->cache->setField( $code, $title, ' ' . $text );
603 }
604
605 // (b) Update the shared caches in a deferred update with a fresh DB snapshot
606 DeferredUpdates::addUpdate(
607 new MessageCacheUpdate( $code, $title, $msg ),
608 DeferredUpdates::PRESEND
609 );
610 }
611
612 /**
613 * @param string $code
614 * @param array[] $replacements List of (title, message key) pairs
615 * @throws MWException
616 */
617 public function refreshAndReplaceInternal( $code, array $replacements ) {
618 global $wgMaxMsgCacheEntrySize;
619
620 // Allow one caller at a time to avoid race conditions
621 $scopedLock = $this->getReentrantScopedLock(
622 $this->clusterCache->makeKey( 'messages', $code )
623 );
624 if ( !$scopedLock ) {
625 foreach ( $replacements as list( $title ) ) {
626 LoggerFactory::getInstance( 'MessageCache' )->error(
627 __METHOD__ . ': could not acquire lock to update {title} ({code})',
628 [ 'title' => $title, 'code' => $code ] );
629 }
630
631 return;
632 }
633
634 // Load the existing cache to update it in the local DC cache.
635 // The other DCs will see a hash mismatch.
636 if ( $this->load( $code, self::FOR_UPDATE ) ) {
637 $cache = $this->cache->get( $code );
638 } else {
639 // Err? Fall back to loading from the database.
640 $cache = $this->loadFromDB( $code, self::FOR_UPDATE );
641 }
642 // Check if individual cache keys should exist and update cache accordingly
643 $newTextByTitle = []; // map of (title => content)
644 $newBigTitles = []; // map of (title => latest revision ID), like EXCESSIVE in loadFromDB()
645 foreach ( $replacements as list( $title ) ) {
646 $page = WikiPage::factory( Title::makeTitle( NS_MEDIAWIKI, $title ) );
647 $page->loadPageData( $page::READ_LATEST );
648 $text = $this->getMessageTextFromContent( $page->getContent() );
649 // Remember the text for the blob store update later on
650 $newTextByTitle[$title] = $text;
651 // Note that if $text is false, then $cache should have a !NONEXISTANT entry
652 if ( !is_string( $text ) ) {
653 $cache[$title] = '!NONEXISTENT';
654 } elseif ( strlen( $text ) > $wgMaxMsgCacheEntrySize ) {
655 $cache[$title] = '!TOO BIG';
656 $newBigTitles[$title] = $page->getLatest();
657 } else {
658 $cache[$title] = ' ' . $text;
659 }
660 }
661 // Update HASH for the new key. Incorporates various administrative keys,
662 // including the old HASH (and thereby the EXCESSIVE value from loadFromDB()
663 // and previous replace() calls), but that doesn't really matter since we
664 // only ever compare it for equality with a copy saved by saveToCaches().
665 $cache['HASH'] = md5( serialize( $cache + [ 'EXCESSIVE' => $newBigTitles ] ) );
666 // Update the too-big WAN cache entries now that we have the new HASH
667 foreach ( $newBigTitles as $title => $id ) {
668 // Match logic of loadCachedMessagePageEntry()
669 $this->wanCache->set(
670 $this->bigMessageCacheKey( $cache['HASH'], $title ),
671 ' ' . $newTextByTitle[$title],
672 $this->mExpiry
673 );
674 }
675 // Mark this cache as definitely being "latest" (non-volatile) so
676 // load() calls do not try to refresh the cache with replica DB data
677 $cache['LATEST'] = time();
678 // Update the process cache
679 $this->cache->set( $code, $cache );
680 // Pre-emptively update the local datacenter cache so things like edit filter and
681 // blacklist changes are reflected immediately; these often use MediaWiki: pages.
682 // The datacenter handling replace() calls should be the same one handling edits
683 // as they require HTTP POST.
684 $this->saveToCaches( $cache, 'all', $code );
685 // Release the lock now that the cache is saved
686 ScopedCallback::consume( $scopedLock );
687
688 // Relay the purge. Touching this check key expires cache contents
689 // and local cache (APC) validation hash across all datacenters.
690 $this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
691
692 // Purge the messages in the message blob store and fire any hook handlers
693 $resourceloader = RequestContext::getMain()->getOutput()->getResourceLoader();
694 $blobStore = $resourceloader->getMessageBlobStore();
695 foreach ( $replacements as list( $title, $msg ) ) {
696 $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
697 Hooks::run( 'MessageCacheReplace', [ $title, $newTextByTitle[$title] ] );
698 }
699 }
700
701 /**
702 * Is the given cache array expired due to time passing or a version change?
703 *
704 * @param array $cache
705 * @return bool
706 */
707 protected function isCacheExpired( $cache ) {
708 if ( !isset( $cache['VERSION'] ) || !isset( $cache['EXPIRY'] ) ) {
709 return true;
710 }
711 if ( $cache['VERSION'] != MSG_CACHE_VERSION ) {
712 return true;
713 }
714 if ( wfTimestampNow() >= $cache['EXPIRY'] ) {
715 return true;
716 }
717
718 return false;
719 }
720
721 /**
722 * Shortcut to update caches.
723 *
724 * @param array $cache Cached messages with a version.
725 * @param string $dest Either "local-only" to save to local caches only
726 * or "all" to save to all caches.
727 * @param string|bool $code Language code (default: false)
728 * @return bool
729 */
730 protected function saveToCaches( array $cache, $dest, $code = false ) {
731 if ( $dest === 'all' ) {
732 $cacheKey = $this->clusterCache->makeKey( 'messages', $code );
733 $success = $this->clusterCache->set( $cacheKey, $cache );
734 $this->setValidationHash( $code, $cache );
735 } else {
736 $success = true;
737 }
738
739 $this->saveToLocalCache( $code, $cache );
740
741 return $success;
742 }
743
744 /**
745 * Get the md5 used to validate the local APC cache
746 *
747 * @param string $code
748 * @return array (hash or false, bool expiry/volatility status)
749 */
750 protected function getValidationHash( $code ) {
751 $curTTL = null;
752 $value = $this->wanCache->get(
753 $this->wanCache->makeKey( 'messages', $code, 'hash', 'v1' ),
754 $curTTL,
755 [ $this->getCheckKey( $code ) ]
756 );
757
758 if ( $value ) {
759 $hash = $value['hash'];
760 if ( ( time() - $value['latest'] ) < WANObjectCache::TTL_MINUTE ) {
761 // Cache was recently updated via replace() and should be up-to-date.
762 // That method is only called in the primary datacenter and uses FOR_UPDATE.
763 // Also, it is unlikely that the current datacenter is *now* secondary one.
764 $expired = false;
765 } else {
766 // See if the "check" key was bumped after the hash was generated
767 $expired = ( $curTTL < 0 );
768 }
769 } else {
770 // No hash found at all; cache must regenerate to be safe
771 $hash = false;
772 $expired = true;
773 }
774
775 return [ $hash, $expired ];
776 }
777
778 /**
779 * Set the md5 used to validate the local disk cache
780 *
781 * If $cache has a 'LATEST' UNIX timestamp key, then the hash will not
782 * be treated as "volatile" by getValidationHash() for the next few seconds.
783 * This is triggered when $cache is generated using FOR_UPDATE mode.
784 *
785 * @param string $code
786 * @param array $cache Cached messages with a version
787 */
788 protected function setValidationHash( $code, array $cache ) {
789 $this->wanCache->set(
790 $this->wanCache->makeKey( 'messages', $code, 'hash', 'v1' ),
791 [
792 'hash' => $cache['HASH'],
793 'latest' => $cache['LATEST'] ?? 0
794 ],
795 WANObjectCache::TTL_INDEFINITE
796 );
797 }
798
799 /**
800 * @param string $key A language message cache key that stores blobs
801 * @param int $timeout Wait timeout in seconds
802 * @return null|ScopedCallback
803 */
804 protected function getReentrantScopedLock( $key, $timeout = self::WAIT_SEC ) {
805 return $this->clusterCache->getScopedLock( $key, $timeout, self::LOCK_TTL, __METHOD__ );
806 }
807
808 /**
809 * Get a message from either the content language or the user language.
810 *
811 * First, assemble a list of languages to attempt getting the message from. This
812 * chain begins with the requested language and its fallbacks and then continues with
813 * the content language and its fallbacks. For each language in the chain, the following
814 * process will occur (in this order):
815 * 1. If a language-specific override, i.e., [[MW:msg/lang]], is available, use that.
816 * Note: for the content language, there is no /lang subpage.
817 * 2. Fetch from the static CDB cache.
818 * 3. If available, check the database for fallback language overrides.
819 *
820 * This process provides a number of guarantees. When changing this code, make sure all
821 * of these guarantees are preserved.
822 * * If the requested language is *not* the content language, then the CDB cache for that
823 * specific language will take precedence over the root database page ([[MW:msg]]).
824 * * Fallbacks will be just that: fallbacks. A fallback language will never be reached if
825 * the message is available *anywhere* in the language for which it is a fallback.
826 *
827 * @param string $key The message key
828 * @param bool $useDB If true, look for the message in the DB, false
829 * to use only the compiled l10n cache.
830 * @param bool|string|object $langcode Code of the language to get the message for.
831 * - If string and a valid code, will create a standard language object
832 * - If string but not a valid code, will create a basic language object
833 * - If boolean and false, create object from the current users language
834 * - If boolean and true, create object from the wikis content language
835 * - If language object, use it as given
836 *
837 * @throws MWException When given an invalid key
838 * @return string|bool False if the message doesn't exist, otherwise the
839 * message (which can be empty)
840 */
841 function get( $key, $useDB = true, $langcode = true ) {
842 if ( is_int( $key ) ) {
843 // Fix numerical strings that somehow become ints
844 // on their way here
845 $key = (string)$key;
846 } elseif ( !is_string( $key ) ) {
847 throw new MWException( 'Non-string key given' );
848 } elseif ( $key === '' ) {
849 // Shortcut: the empty key is always missing
850 return false;
851 }
852
853 // Normalise title-case input (with some inlining)
854 $lckey = self::normalizeKey( $key );
855
856 Hooks::run( 'MessageCache::get', [ &$lckey ] );
857
858 // Loop through each language in the fallback list until we find something useful
859 $message = $this->getMessageFromFallbackChain(
860 wfGetLangObj( $langcode ),
861 $lckey,
862 !$this->mDisable && $useDB
863 );
864
865 // If we still have no message, maybe the key was in fact a full key so try that
866 if ( $message === false ) {
867 $parts = explode( '/', $lckey );
868 // We may get calls for things that are http-urls from sidebar
869 // Let's not load nonexistent languages for those
870 // They usually have more than one slash.
871 if ( count( $parts ) == 2 && $parts[1] !== '' ) {
872 $message = Language::getMessageFor( $parts[0], $parts[1] );
873 if ( $message === null ) {
874 $message = false;
875 }
876 }
877 }
878
879 // Post-processing if the message exists
880 if ( $message !== false ) {
881 // Fix whitespace
882 $message = str_replace(
883 [
884 # Fix for trailing whitespace, removed by textarea
885 '&#32;',
886 # Fix for NBSP, converted to space by firefox
887 '&nbsp;',
888 '&#160;',
889 '&shy;'
890 ],
891 [
892 ' ',
893 "\u{00A0}",
894 "\u{00A0}",
895 "\u{00AD}"
896 ],
897 $message
898 );
899 }
900
901 return $message;
902 }
903
904 /**
905 * Given a language, try and fetch messages from that language.
906 *
907 * Will also consider fallbacks of that language, the site language, and fallbacks for
908 * the site language.
909 *
910 * @see MessageCache::get
911 * @param Language|StubObject $lang Preferred language
912 * @param string $lckey Lowercase key for the message (as for localisation cache)
913 * @param bool $useDB Whether to include messages from the wiki database
914 * @return string|bool The message, or false if not found
915 */
916 protected function getMessageFromFallbackChain( $lang, $lckey, $useDB ) {
917 $alreadyTried = [];
918
919 // First try the requested language.
920 $message = $this->getMessageForLang( $lang, $lckey, $useDB, $alreadyTried );
921 if ( $message !== false ) {
922 return $message;
923 }
924
925 // Now try checking the site language.
926 $message = $this->getMessageForLang( $this->contLang, $lckey, $useDB, $alreadyTried );
927 return $message;
928 }
929
930 /**
931 * Given a language, try and fetch messages from that language and its fallbacks.
932 *
933 * @see MessageCache::get
934 * @param Language|StubObject $lang Preferred language
935 * @param string $lckey Lowercase key for the message (as for localisation cache)
936 * @param bool $useDB Whether to include messages from the wiki database
937 * @param bool[] $alreadyTried Contains true for each language that has been tried already
938 * @return string|bool The message, or false if not found
939 */
940 private function getMessageForLang( $lang, $lckey, $useDB, &$alreadyTried ) {
941 $langcode = $lang->getCode();
942
943 // Try checking the database for the requested language
944 if ( $useDB ) {
945 $uckey = $this->contLang->ucfirst( $lckey );
946
947 if ( !isset( $alreadyTried[$langcode] ) ) {
948 $message = $this->getMsgFromNamespace(
949 $this->getMessagePageName( $langcode, $uckey ),
950 $langcode
951 );
952 if ( $message !== false ) {
953 return $message;
954 }
955 $alreadyTried[$langcode] = true;
956 }
957 } else {
958 $uckey = null;
959 }
960
961 // Check the CDB cache
962 $message = $lang->getMessage( $lckey );
963 if ( $message !== null ) {
964 return $message;
965 }
966
967 // Try checking the database for all of the fallback languages
968 if ( $useDB ) {
969 $fallbackChain = Language::getFallbacksFor( $langcode );
970
971 foreach ( $fallbackChain as $code ) {
972 if ( isset( $alreadyTried[$code] ) ) {
973 continue;
974 }
975
976 $message = $this->getMsgFromNamespace(
977 $this->getMessagePageName( $code, $uckey ), $code );
978
979 if ( $message !== false ) {
980 return $message;
981 }
982 $alreadyTried[$code] = true;
983 }
984 }
985
986 return false;
987 }
988
989 /**
990 * Get the message page name for a given language
991 *
992 * @param string $langcode
993 * @param string $uckey Uppercase key for the message
994 * @return string The page name
995 */
996 private function getMessagePageName( $langcode, $uckey ) {
997 global $wgLanguageCode;
998
999 if ( $langcode === $wgLanguageCode ) {
1000 // Messages created in the content language will not have the /lang extension
1001 return $uckey;
1002 } else {
1003 return "$uckey/$langcode";
1004 }
1005 }
1006
1007 /**
1008 * Get a message from the MediaWiki namespace, with caching. The key must
1009 * first be converted to two-part lang/msg form if necessary.
1010 *
1011 * Unlike self::get(), this function doesn't resolve fallback chains, and
1012 * some callers require this behavior. LanguageConverter::parseCachedTable()
1013 * and self::get() are some examples in core.
1014 *
1015 * @param string $title Message cache key with initial uppercase letter
1016 * @param string $code Code denoting the language to try
1017 * @return string|bool The message, or false if it does not exist or on error
1018 */
1019 public function getMsgFromNamespace( $title, $code ) {
1020 // Load all MediaWiki page definitions into cache. Note that individual keys
1021 // already loaded into cache during this request remain in the cache, which
1022 // includes the value of hook-defined messages.
1023 $this->load( $code );
1024
1025 $entry = $this->cache->getField( $code, $title );
1026
1027 if ( $entry !== null ) {
1028 // Message page exists as an override of a software messages
1029 if ( substr( $entry, 0, 1 ) === ' ' ) {
1030 // The message exists and is not '!TOO BIG'
1031 return (string)substr( $entry, 1 );
1032 } elseif ( $entry === '!NONEXISTENT' ) {
1033 // The text might be '-' or missing due to some data loss
1034 return false;
1035 }
1036 // Load the message page, utilizing the individual message cache.
1037 // If the page does not exist, there will be no hook handler fallbacks.
1038 $entry = $this->loadCachedMessagePageEntry(
1039 $title,
1040 $code,
1041 $this->cache->getField( $code, 'HASH' )
1042 );
1043 } else {
1044 // Message page either does not exist or does not override a software message
1045 if ( !isset( $this->overridable[$this->contLang->lcfirst( $title )] ) ) {
1046 // Message page does not override any software-defined message. A custom
1047 // message might be defined to have content or settings specific to the wiki.
1048 // Load the message page, utilizing the individual message cache as needed.
1049 $entry = $this->loadCachedMessagePageEntry(
1050 $title,
1051 $code,
1052 $this->cache->getField( $code, 'HASH' )
1053 );
1054 }
1055 if ( $entry === null || substr( $entry, 0, 1 ) !== ' ' ) {
1056 // Message does not have a MediaWiki page definition; try hook handlers
1057 $message = false;
1058 Hooks::run( 'MessagesPreLoad', [ $title, &$message, $code ] );
1059 if ( $message !== false ) {
1060 $this->cache->setField( $code, $title, ' ' . $message );
1061 } else {
1062 $this->cache->setField( $code, $title, '!NONEXISTENT' );
1063 }
1064
1065 return $message;
1066 }
1067 }
1068
1069 if ( $entry !== false && substr( $entry, 0, 1 ) === ' ' ) {
1070 if ( $this->cacheVolatile[$code] ) {
1071 // Make sure that individual keys respect the WAN cache holdoff period too
1072 LoggerFactory::getInstance( 'MessageCache' )->debug(
1073 __METHOD__ . ': loading volatile key \'{titleKey}\'',
1074 [ 'titleKey' => $title, 'code' => $code ] );
1075 } else {
1076 $this->cache->setField( $code, $title, $entry );
1077 }
1078 // The message exists, so make sure a string is returned
1079 return (string)substr( $entry, 1 );
1080 }
1081
1082 $this->cache->setField( $code, $title, '!NONEXISTENT' );
1083
1084 return false;
1085 }
1086
1087 /**
1088 * @param string $dbKey
1089 * @param string $code
1090 * @param string $hash
1091 * @return string Either " <MESSAGE>" or "!NONEXISTANT"
1092 */
1093 private function loadCachedMessagePageEntry( $dbKey, $code, $hash ) {
1094 $fname = __METHOD__;
1095 return $this->srvCache->getWithSetCallback(
1096 $this->srvCache->makeKey( 'messages-big', $hash, $dbKey ),
1097 IExpiringStore::TTL_MINUTE,
1098 function () use ( $code, $dbKey, $hash, $fname ) {
1099 return $this->wanCache->getWithSetCallback(
1100 $this->bigMessageCacheKey( $hash, $dbKey ),
1101 $this->mExpiry,
1102 function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code, $fname ) {
1103 // Try loading the message from the database
1104 $dbr = wfGetDB( DB_REPLICA );
1105 $setOpts += Database::getCacheSetOptions( $dbr );
1106 // Use newKnownCurrent() to avoid querying revision/user tables
1107 $title = Title::makeTitle( NS_MEDIAWIKI, $dbKey );
1108 $revision = Revision::newKnownCurrent( $dbr, $title );
1109 if ( !$revision ) {
1110 // The wiki doesn't have a local override page. Cache absence with normal TTL.
1111 // When overrides are created, self::replace() takes care of the cache.
1112 return '!NONEXISTENT';
1113 }
1114 $content = $revision->getContent();
1115 if ( $content ) {
1116 $message = $this->getMessageTextFromContent( $content );
1117 } else {
1118 LoggerFactory::getInstance( 'MessageCache' )->warning(
1119 $fname . ': failed to load page text for \'{titleKey}\'',
1120 [ 'titleKey' => $dbKey, 'code' => $code ]
1121 );
1122 $message = null;
1123 }
1124
1125 if ( !is_string( $message ) ) {
1126 // Revision failed to load Content, or Content is incompatible with wikitext.
1127 // Possibly a temporary loading failure.
1128 $ttl = 5;
1129
1130 return '!NONEXISTENT';
1131 }
1132
1133 return ' ' . $message;
1134 }
1135 );
1136 }
1137 );
1138 }
1139
1140 /**
1141 * @param string $message
1142 * @param bool $interface
1143 * @param Language|null $language
1144 * @param Title|null $title
1145 * @return string
1146 */
1147 public function transform( $message, $interface = false, $language = null, $title = null ) {
1148 // Avoid creating parser if nothing to transform
1149 if ( strpos( $message, '{{' ) === false ) {
1150 return $message;
1151 }
1152
1153 if ( $this->mInParser ) {
1154 return $message;
1155 }
1156
1157 $parser = $this->getParser();
1158 if ( $parser ) {
1159 $popts = $this->getParserOptions();
1160 $popts->setInterfaceMessage( $interface );
1161 $popts->setTargetLanguage( $language );
1162
1163 $userlang = $popts->setUserLang( $language );
1164 $this->mInParser = true;
1165 $message = $parser->transformMsg( $message, $popts, $title );
1166 $this->mInParser = false;
1167 $popts->setUserLang( $userlang );
1168 }
1169
1170 return $message;
1171 }
1172
1173 /**
1174 * @return Parser
1175 */
1176 public function getParser() {
1177 global $wgParser, $wgParserConf;
1178
1179 if ( !$this->mParser && isset( $wgParser ) ) {
1180 # Do some initialisation so that we don't have to do it twice
1181 $wgParser->firstCallInit();
1182 # Clone it and store it
1183 $class = $wgParserConf['class'];
1184 if ( $class == ParserDiffTest::class ) {
1185 # Uncloneable
1186 $this->mParser = new $class( $wgParserConf );
1187 } else {
1188 $this->mParser = clone $wgParser;
1189 }
1190 }
1191
1192 return $this->mParser;
1193 }
1194
1195 /**
1196 * @param string $text
1197 * @param Title|null $title
1198 * @param bool $linestart Whether or not this is at the start of a line
1199 * @param bool $interface Whether this is an interface message
1200 * @param Language|string|null $language Language code
1201 * @return ParserOutput|string
1202 */
1203 public function parse( $text, $title = null, $linestart = true,
1204 $interface = false, $language = null
1205 ) {
1206 global $wgTitle;
1207
1208 if ( $this->mInParser ) {
1209 return htmlspecialchars( $text );
1210 }
1211
1212 $parser = $this->getParser();
1213 $popts = $this->getParserOptions();
1214 $popts->setInterfaceMessage( $interface );
1215
1216 if ( is_string( $language ) ) {
1217 $language = Language::factory( $language );
1218 }
1219 $popts->setTargetLanguage( $language );
1220
1221 if ( !$title || !$title instanceof Title ) {
1222 wfDebugLog( 'GlobalTitleFail', __METHOD__ . ' called by ' .
1223 wfGetAllCallers( 6 ) . ' with no title set.' );
1224 $title = $wgTitle;
1225 }
1226 // Sometimes $wgTitle isn't set either...
1227 if ( !$title ) {
1228 # It's not uncommon having a null $wgTitle in scripts. See r80898
1229 # Create a ghost title in such case
1230 $title = Title::makeTitle( NS_SPECIAL, 'Badtitle/title not set in ' . __METHOD__ );
1231 }
1232
1233 $this->mInParser = true;
1234 $res = $parser->parse( $text, $title, $popts, $linestart );
1235 $this->mInParser = false;
1236
1237 return $res;
1238 }
1239
1240 public function disable() {
1241 $this->mDisable = true;
1242 }
1243
1244 public function enable() {
1245 $this->mDisable = false;
1246 }
1247
1248 /**
1249 * Whether DB/cache usage is disabled for determining messages
1250 *
1251 * If so, this typically indicates either:
1252 * - a) load() failed to find a cached copy nor query the DB
1253 * - b) we are in a special context or error mode that cannot use the DB
1254 * If the DB is ignored, any derived HTML output or cached objects may be wrong.
1255 * To avoid long-term cache pollution, TTLs can be adjusted accordingly.
1256 *
1257 * @return bool
1258 * @since 1.27
1259 */
1260 public function isDisabled() {
1261 return $this->mDisable;
1262 }
1263
1264 /**
1265 * Clear all stored messages in global and local cache
1266 *
1267 * Mainly used after a mass rebuild
1268 */
1269 public function clear() {
1270 $langs = Language::fetchLanguageNames( null, 'mw' );
1271 foreach ( array_keys( $langs ) as $code ) {
1272 $this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
1273 }
1274 $this->cache->clear();
1275 }
1276
1277 /**
1278 * @param string $key
1279 * @return array
1280 */
1281 public function figureMessage( $key ) {
1282 global $wgLanguageCode;
1283
1284 $pieces = explode( '/', $key );
1285 if ( count( $pieces ) < 2 ) {
1286 return [ $key, $wgLanguageCode ];
1287 }
1288
1289 $lang = array_pop( $pieces );
1290 if ( !Language::fetchLanguageName( $lang, null, 'mw' ) ) {
1291 return [ $key, $wgLanguageCode ];
1292 }
1293
1294 $message = implode( '/', $pieces );
1295
1296 return [ $message, $lang ];
1297 }
1298
1299 /**
1300 * Get all message keys stored in the message cache for a given language.
1301 * If $code is the content language code, this will return all message keys
1302 * for which MediaWiki:msgkey exists. If $code is another language code, this
1303 * will ONLY return message keys for which MediaWiki:msgkey/$code exists.
1304 * @param string $code Language code
1305 * @return array Array of message keys (strings)
1306 */
1307 public function getAllMessageKeys( $code ) {
1308 $this->load( $code );
1309 if ( !$this->cache->has( $code ) ) {
1310 // Apparently load() failed
1311 return null;
1312 }
1313 // Remove administrative keys
1314 $cache = $this->cache->get( $code );
1315 unset( $cache['VERSION'] );
1316 unset( $cache['EXPIRY'] );
1317 unset( $cache['EXCESSIVE'] );
1318 // Remove any !NONEXISTENT keys
1319 $cache = array_diff( $cache, [ '!NONEXISTENT' ] );
1320
1321 // Keys may appear with a capital first letter. lcfirst them.
1322 return array_map( [ $this->contLang, 'lcfirst' ], array_keys( $cache ) );
1323 }
1324
1325 /**
1326 * Purge message caches when a MediaWiki: page is created, updated, or deleted
1327 *
1328 * @param Title $title Message page title
1329 * @param Content|null $content New content for edit/create, null on deletion
1330 * @since 1.29
1331 */
1332 public function updateMessageOverride( Title $title, Content $content = null ) {
1333 $msgText = $this->getMessageTextFromContent( $content );
1334 if ( $msgText === null ) {
1335 $msgText = false; // treat as not existing
1336 }
1337
1338 $this->replace( $title->getDBkey(), $msgText );
1339
1340 if ( $this->contLang->hasVariants() ) {
1341 $this->contLang->updateConversionTable( $title );
1342 }
1343 }
1344
1345 /**
1346 * @param string $code Language code
1347 * @return string WAN cache key usable as a "check key" against language page edits
1348 */
1349 public function getCheckKey( $code ) {
1350 return $this->wanCache->makeKey( 'messages', $code );
1351 }
1352
1353 /**
1354 * @param Content|null $content Content or null if the message page does not exist
1355 * @return string|bool|null Returns false if $content is null and null on error
1356 */
1357 private function getMessageTextFromContent( Content $content = null ) {
1358 // @TODO: could skip pseudo-messages like js/css here, based on content model
1359 if ( $content ) {
1360 // Message page exists...
1361 // XXX: Is this the right way to turn a Content object into a message?
1362 // NOTE: $content is typically either WikitextContent, JavaScriptContent or
1363 // CssContent. MessageContent is *not* used for storing messages, it's
1364 // only used for wrapping them when needed.
1365 $msgText = $content->getWikitextForTransclusion();
1366 if ( $msgText === false || $msgText === null ) {
1367 // This might be due to some kind of misconfiguration...
1368 $msgText = null;
1369 LoggerFactory::getInstance( 'MessageCache' )->warning(
1370 __METHOD__ . ": message content doesn't provide wikitext "
1371 . "(content model: " . $content->getModel() . ")" );
1372 }
1373 } else {
1374 // Message page does not exist...
1375 $msgText = false;
1376 }
1377
1378 return $msgText;
1379 }
1380
1381 /**
1382 * @param string $hash Hash for this version of the entire key/value overrides map
1383 * @param string $title Message cache key with initial uppercase letter
1384 * @return string
1385 */
1386 private function bigMessageCacheKey( $hash, $title ) {
1387 return $this->wanCache->makeKey( 'messages-big', $hash, $title );
1388 }
1389 }