10 define( 'MSG_LOAD_TIMEOUT', 60 );
11 define( 'MSG_LOCK_TIMEOUT', 10 );
12 define( 'MSG_WAIT_TIMEOUT', 10 );
13 define( 'MSG_CACHE_VERSION', 1 );
17 * Performs various MediaWiki namespace-related functions
22 * Process local cache of loaded messages that are defined in
23 * MediaWiki namespace. First array level is a language code,
24 * second level is message key and the values are either message
25 * content prefixed with space, or !NONEXISTENT for negative
30 // Should mean that database cannot be used, but check
33 /// Lifetime for cache, used by object caching
37 * Message cache has it's own parser which it uses to transform
40 protected $mParserOptions, $mParser;
42 /// Variable for tracking which variables are already loaded
43 protected $mLoadedLanguages = array();
46 * Used for automatic detection of most used messages.
48 protected $mRequestedMessages = array();
51 * How long the message request counts are stored. Longer period gives
52 * better sample, but also takes longer to adapt changes. The counts
53 * are aggregrated per day, regardless of the value of this variable.
55 protected static $mAdaptiveDataAge = 604800; // Is 7*24*3600
58 * Filter the tail of less used messages that are requested more seldom
59 * than this factor times the number of request of most requested message.
60 * These messages are not loaded in the default set, but are still cached
61 * individually on demand with the normal cache expiry time.
63 protected static $mAdaptiveInclusionThreshold = 0.05;
68 private static $instance;
73 protected $mInParser = false;
76 * Get the signleton instance of this class
79 * @return MessageCache object
81 public static function singleton() {
82 if ( is_null( self
::$instance ) ) {
83 global $wgUseDatabaseMessages, $wgMsgCacheExpiry;
84 self
::$instance = new self( wfGetMessageCacheStorage(), $wgUseDatabaseMessages, $wgMsgCacheExpiry );
86 return self
::$instance;
90 * Destroy the singleton instance
94 public static function destroyInstance() {
95 self
::$instance = null;
98 function __construct( $memCached, $useDB, $expiry ) {
100 $memCached = wfGetCache( CACHE_NONE
);
103 $this->mMemc
= $memCached;
104 $this->mDisable
= !$useDB;
105 $this->mExpiry
= $expiry;
109 * ParserOptions is lazy initialised.
111 * @return ParserOptions
113 function getParserOptions() {
114 if ( !$this->mParserOptions
) {
115 $this->mParserOptions
= new ParserOptions
;
117 return $this->mParserOptions
;
121 * Try to load the cache from a local file.
122 * Actual format of the file depends on the $wgLocalMessageCacheSerialized
125 * @param $hash String: the hash of contents, to check validity.
126 * @param $code Mixed: Optional language code, see documenation of load().
127 * @return false on failure.
129 function loadFromLocal( $hash, $code ) {
130 global $wgCacheDirectory, $wgLocalMessageCacheSerialized;
132 $filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
134 # Check file existence
135 wfSuppressWarnings();
136 $file = fopen( $filename, 'r' );
139 return false; // No cache file
142 if ( $wgLocalMessageCacheSerialized ) {
143 // Check to see if the file has the hash specified
144 $localHash = fread( $file, 32 );
145 if ( $hash === $localHash ) {
146 // All good, get the rest of it
148 while ( !feof( $file ) ) {
149 $serialized .= fread( $file, 100000 );
152 return $this->setCache( unserialize( $serialized ), $code );
155 return false; // Wrong hash
158 $localHash = substr( fread( $file, 40 ), 8 );
160 if ( $hash != $localHash ) {
161 return false; // Wrong hash
164 # Require overwrites the member variable or just shadows it?
165 require( $filename );
166 return $this->setCache( $this->mCache
, $code );
171 * Save the cache to a local file.
173 function saveToLocal( $serialized, $hash, $code ) {
174 global $wgCacheDirectory;
176 $filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
177 wfMkdirParents( $wgCacheDirectory ); // might fail
179 wfSuppressWarnings();
180 $file = fopen( $filename, 'w' );
184 wfDebug( "Unable to open local cache file for writing\n" );
188 fwrite( $file, $hash . $serialized );
190 @chmod
( $filename, 0666 );
193 function saveToScript( $array, $hash, $code ) {
194 global $wgCacheDirectory;
196 $filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
197 $tempFilename = $filename . '.tmp';
198 wfMkdirParents( $wgCacheDirectory ); // might fail
200 wfSuppressWarnings();
201 $file = fopen( $tempFilename, 'w' );
205 wfDebug( "Unable to open local cache file for writing\n" );
209 fwrite( $file, "<?php\n//$hash\n\n \$this->mCache = array(" );
211 foreach ( $array as $key => $message ) {
212 $key = $this->escapeForScript( $key );
213 $message = $this->escapeForScript( $message );
214 fwrite( $file, "'$key' => '$message',\n" );
217 fwrite( $file, ");\n?>" );
219 rename( $tempFilename, $filename );
222 function escapeForScript( $string ) {
223 $string = str_replace( '\\', '\\\\', $string );
224 $string = str_replace( '\'', '\\\'', $string );
229 * Set the cache to $cache, if it is valid. Otherwise set the cache to false.
233 function setCache( $cache, $code ) {
234 if ( isset( $cache['VERSION'] ) && $cache['VERSION'] == MSG_CACHE_VERSION
) {
235 $this->mCache
[$code] = $cache;
243 * Loads messages from caches or from database in this order:
244 * (1) local message cache (if $wgUseLocalMessageCache is enabled)
246 * (3) from the database.
248 * When succesfully loading from (2) or (3), all higher level caches are
249 * updated for the newest version.
251 * Nothing is loaded if member variable mDisable is true, either manually
252 * set by calling code or if message loading fails (is this possible?).
254 * Returns true if cache is already populated or it was succesfully populated,
255 * or false if populating empty cache fails. Also returns true if MessageCache
258 * @param $code String: language to which load messages
260 function load( $code = false ) {
261 global $wgUseLocalMessageCache;
263 if( !is_string( $code ) ) {
264 # This isn't really nice, so at least make a note about it and try to
266 wfDebug( __METHOD__
. " called without providing a language code\n" );
270 # Don't do double loading...
271 if ( isset( $this->mLoadedLanguages
[$code] ) ) {
275 # 8 lines of code just to say (once) that message cache is disabled
276 if ( $this->mDisable
) {
277 static $shownDisabled = false;
278 if ( !$shownDisabled ) {
279 wfDebug( __METHOD__
. ": disabled\n" );
280 $shownDisabled = true;
285 # Loading code starts
286 wfProfileIn( __METHOD__
);
287 $success = false; # Keep track of success
288 $where = array(); # Debug info, delayed to avoid spamming debug log too much
289 $cacheKey = wfMemcKey( 'messages', $code ); # Key in memc for messages
292 # Hash of the contents is stored in memcache, to detect if local cache goes
293 # out of date (due to update in other thread?)
294 if ( $wgUseLocalMessageCache ) {
295 wfProfileIn( __METHOD__
. '-fromlocal' );
297 $hash = $this->mMemc
->get( wfMemcKey( 'messages', $code, 'hash' ) );
299 $success = $this->loadFromLocal( $hash, $code );
300 if ( $success ) $where[] = 'got from local cache';
302 wfProfileOut( __METHOD__
. '-fromlocal' );
306 # Fails if nothing in cache, or in the wrong version.
308 wfProfileIn( __METHOD__
. '-fromcache' );
309 $cache = $this->mMemc
->get( $cacheKey );
310 $success = $this->setCache( $cache, $code );
312 $where[] = 'got from global cache';
313 $this->saveToCaches( $cache, false, $code );
315 wfProfileOut( __METHOD__
. '-fromcache' );
319 # Nothing in caches... so we need create one and store it in caches
321 $where[] = 'cache is empty';
322 $where[] = 'loading from database';
324 $this->lock( $cacheKey );
326 # Limit the concurrency of loadFromDB to a single process
327 # This prevents the site from going down when the cache expires
328 $statusKey = wfMemcKey( 'messages', $code, 'status' );
329 $success = $this->mMemc
->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT
);
331 $cache = $this->loadFromDB( $code );
332 $success = $this->setCache( $cache, $code );
335 $success = $this->saveToCaches( $cache, true, $code );
337 $this->mMemc
->delete( $statusKey );
339 $this->mMemc
->set( $statusKey, 'error', 60 * 5 );
340 wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
343 $this->unlock($cacheKey);
347 # Bad luck... this should not happen
348 $where[] = 'loading FAILED - cache is disabled';
349 $info = implode( ', ', $where );
350 wfDebug( __METHOD__
. ": Loading $code... $info\n" );
351 $this->mDisable
= true;
352 $this->mCache
= false;
354 # All good, just record the success
355 $info = implode( ', ', $where );
356 wfDebug( __METHOD__
. ": Loading $code... $info\n" );
357 $this->mLoadedLanguages
[$code] = true;
359 wfProfileOut( __METHOD__
);
364 * Loads cacheable messages from the database. Messages bigger than
365 * $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded
366 * on-demand from the database later.
368 * @param $code String: language code.
369 * @return Array: loaded messages for storing in caches.
371 function loadFromDB( $code ) {
372 wfProfileIn( __METHOD__
);
373 global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache;
374 $dbr = wfGetDB( DB_SLAVE
);
379 'page_is_redirect' => 0,
380 'page_namespace' => NS_MEDIAWIKI
,
384 if ( $wgAdaptiveMessageCache ) {
385 $mostused = $this->getMostUsedMessages();
386 if ( $code !== $wgLanguageCode ) {
387 foreach ( $mostused as $key => $value ) {
388 $mostused[$key] = "$value/$code";
393 if ( count( $mostused ) ) {
394 $conds['page_title'] = $mostused;
395 } elseif ( $code !== $wgLanguageCode ) {
396 $conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), "/$code" );
398 # Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
399 # other than language code.
400 $conds[] = 'page_title NOT' . $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
403 # Conditions to fetch oversized pages to ignore them
405 $bigConds[] = 'page_len > ' . intval( $wgMaxMsgCacheEntrySize );
407 # Load titles for all oversized pages in the MediaWiki namespace
408 $res = $dbr->select( 'page', 'page_title', $bigConds, __METHOD__
. "($code)-big" );
409 foreach ( $res as $row ) {
410 $cache[$row->page_title
] = '!TOO BIG';
413 # Conditions to load the remaining pages with their contents
414 $smallConds = $conds;
415 $smallConds[] = 'page_latest=rev_id';
416 $smallConds[] = 'rev_text_id=old_id';
417 $smallConds[] = 'page_len <= ' . intval( $wgMaxMsgCacheEntrySize );
420 array( 'page', 'revision', 'text' ),
421 array( 'page_title', 'old_text', 'old_flags' ),
423 __METHOD__
. "($code)-small"
426 foreach ( $res as $row ) {
427 $cache[$row->page_title
] = ' ' . Revision
::getRevisionText( $row );
430 foreach ( $mostused as $key ) {
431 if ( !isset( $cache[$key] ) ) {
432 $cache[$key] = '!NONEXISTENT';
436 $cache['VERSION'] = MSG_CACHE_VERSION
;
437 wfProfileOut( __METHOD__
);
442 * Updates cache as necessary when message page is changed
444 * @param $title String: name of the page changed.
445 * @param $text Mixed: new contents of the page.
447 public function replace( $title, $text ) {
448 global $wgMaxMsgCacheEntrySize;
449 wfProfileIn( __METHOD__
);
451 if ( $this->mDisable
) {
452 wfProfileOut( __METHOD__
);
456 list( $msg, $code ) = $this->figureMessage( $title );
458 $cacheKey = wfMemcKey( 'messages', $code );
459 $this->load( $code );
460 $this->lock( $cacheKey );
462 $titleKey = wfMemcKey( 'messages', 'individual', $title );
464 if ( $text === false ) {
465 # Article was deleted
466 $this->mCache
[$code][$title] = '!NONEXISTENT';
467 $this->mMemc
->delete( $titleKey );
468 } elseif ( strlen( $text ) > $wgMaxMsgCacheEntrySize ) {
470 $this->mCache
[$code][$title] = '!TOO BIG';
471 $this->mMemc
->set( $titleKey, ' ' . $text, $this->mExpiry
);
473 $this->mCache
[$code][$title] = ' ' . $text;
474 $this->mMemc
->delete( $titleKey );
478 $this->saveToCaches( $this->mCache
[$code], true, $code );
479 $this->unlock( $cacheKey );
481 // Also delete cached sidebar... just in case it is affected
482 $codes = array( $code );
483 if ( $code === 'en' ) {
484 // Delete all sidebars, like for example on action=purge on the
486 $codes = array_keys( Language
::getLanguageNames() );
490 foreach ( $codes as $code ) {
491 $sidebarKey = wfMemcKey( 'sidebar', $code );
492 $parserMemc->delete( $sidebarKey );
495 // Update the message in the message blob store
497 MessageBlobStore
::updateMessage( $wgContLang->lcfirst( $msg ) );
499 wfRunHooks( 'MessageCacheReplace', array( $title, $text ) );
501 wfProfileOut( __METHOD__
);
505 * Shortcut to update caches.
507 * @param $cache Array: cached messages with a version.
508 * @param $memc Bool: Wether to update or not memcache.
509 * @param $code String: Language code.
510 * @return False on somekind of error.
512 protected function saveToCaches( $cache, $memc = true, $code = false ) {
513 wfProfileIn( __METHOD__
);
514 global $wgUseLocalMessageCache, $wgLocalMessageCacheSerialized;
516 $cacheKey = wfMemcKey( 'messages', $code );
519 $success = $this->mMemc
->set( $cacheKey, $cache, $this->mExpiry
);
524 # Save to local cache
525 if ( $wgUseLocalMessageCache ) {
526 $serialized = serialize( $cache );
527 $hash = md5( $serialized );
528 $this->mMemc
->set( wfMemcKey( 'messages', $code, 'hash' ), $hash, $this->mExpiry
);
529 if ($wgLocalMessageCacheSerialized) {
530 $this->saveToLocal( $serialized, $hash, $code );
532 $this->saveToScript( $cache, $hash, $code );
536 wfProfileOut( __METHOD__
);
541 * Represents a write lock on the messages key
543 * @return Boolean: success
545 function lock( $key ) {
546 $lockKey = $key . ':lock';
547 for ( $i = 0; $i < MSG_WAIT_TIMEOUT
&& !$this->mMemc
->add( $lockKey, 1, MSG_LOCK_TIMEOUT
); $i++
) {
551 return $i >= MSG_WAIT_TIMEOUT
;
554 function unlock( $key ) {
555 $lockKey = $key . ':lock';
556 $this->mMemc
->delete( $lockKey );
560 * Get a message from either the content language or the user language.
562 * @param $key String: the message cache key
563 * @param $useDB Boolean: get the message from the DB, false to use only
565 * @param $langcode String: code of the language to get the message for, if
566 * it is a valid code create a language for that language,
567 * if it is a string but not a valid code then make a basic
568 * language object, if it is a false boolean then use the
569 * current users language (as a fallback for the old
570 * parameter functionality), or if it is a true boolean
571 * then use the wikis content language (also as a
573 * @param $isFullKey Boolean: specifies whether $key is a two part key
576 function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) {
577 global $wgLanguageCode, $wgContLang;
579 if ( !is_string( $key ) ) {
580 throw new MWException( 'Non-string key given' );
583 if ( strval( $key ) === '' ) {
584 # Shortcut: the empty key is always missing
588 $lang = wfGetLangObj( $langcode );
590 throw new MWException( "Bad lang code $langcode given" );
593 $langcode = $lang->getCode();
597 # Normalise title-case input (with some inlining)
598 $lckey = str_replace( ' ', '_', $key );
599 if ( ord( $key ) < 128 ) {
600 $lckey[0] = strtolower( $lckey[0] );
601 $uckey = ucfirst( $lckey );
603 $lckey = $wgContLang->lcfirst( $lckey );
604 $uckey = $wgContLang->ucfirst( $lckey );
608 * Record each message request, but only once per request.
609 * This information is not used unless $wgAdaptiveMessageCache
612 $this->mRequestedMessages
[$uckey] = true;
614 # Try the MediaWiki namespace
615 if( !$this->mDisable
&& $useDB ) {
617 if( !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
618 $title .= '/' . $langcode;
620 $message = $this->getMsgFromNamespace( $title, $langcode );
623 # Try the array in the language object
624 if ( $message === false ) {
625 $message = $lang->getMessage( $lckey );
626 if ( is_null( $message ) ) {
631 # Try the array of another language
632 if( $message === false ) {
633 $parts = explode( '/', $lckey );
634 # We may get calls for things that are http-urls from sidebar
635 # Let's not load nonexistent languages for those
636 # They usually have more than one slash.
637 if ( count( $parts ) == 2 && $parts[1] !== '' ) {
638 $message = Language
::getMessageFor( $parts[0], $parts[1] );
639 if ( is_null( $message ) ) {
645 # Is this a custom message? Try the default language in the db...
646 if( ( $message === false ||
$message === '-' ) &&
647 !$this->mDisable
&& $useDB &&
648 !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
649 $message = $this->getMsgFromNamespace( $uckey, $wgLanguageCode );
653 if( $message === false ) {
658 $message = strtr( $message,
660 # Fix for trailing whitespace, removed by textarea
662 # Fix for NBSP, converted to space by firefox
663 ' ' => "\xc2\xa0",
664 ' ' => "\xc2\xa0",
671 * Get a message from the MediaWiki namespace, with caching. The key must
672 * first be converted to two-part lang/msg form if necessary.
674 * @param $title String: Message cache key with initial uppercase letter.
675 * @param $code String: code denoting the language to try.
677 function getMsgFromNamespace( $title, $code ) {
678 global $wgAdaptiveMessageCache;
680 $this->load( $code );
681 if ( isset( $this->mCache
[$code][$title] ) ) {
682 $entry = $this->mCache
[$code][$title];
683 if ( substr( $entry, 0, 1 ) === ' ' ) {
684 return substr( $entry, 1 );
685 } elseif ( $entry === '!NONEXISTENT' ) {
687 } elseif( $entry === '!TOO BIG' ) {
688 // Fall through and try invididual message cache below
691 // XXX: This is not cached in process cache, should it?
693 wfRunHooks( 'MessagesPreLoad', array( $title, &$message ) );
694 if ( $message !== false ) {
699 * If message cache is in normal mode, it is guaranteed
700 * (except bugs) that there is always entry (or placeholder)
701 * in the cache if message exists. Thus we can do minor
702 * performance improvement and return false early.
704 if ( !$wgAdaptiveMessageCache ) {
709 # Try the individual message cache
710 $titleKey = wfMemcKey( 'messages', 'individual', $title );
711 $entry = $this->mMemc
->get( $titleKey );
713 if ( substr( $entry, 0, 1 ) === ' ' ) {
714 $this->mCache
[$code][$title] = $entry;
715 return substr( $entry, 1 );
716 } elseif ( $entry === '!NONEXISTENT' ) {
717 $this->mCache
[$code][$title] = '!NONEXISTENT';
720 # Corrupt/obsolete entry, delete it
721 $this->mMemc
->delete( $titleKey );
725 # Try loading it from the database
726 $revision = Revision
::newFromTitle( Title
::makeTitle( NS_MEDIAWIKI
, $title ) );
728 $message = $revision->getText();
729 $this->mCache
[$code][$title] = ' ' . $message;
730 $this->mMemc
->set( $titleKey, ' ' . $message, $this->mExpiry
);
733 $this->mCache
[$code][$title] = '!NONEXISTENT';
734 $this->mMemc
->set( $titleKey, '!NONEXISTENT', $this->mExpiry
);
741 * @param $message string
742 * @param $interface bool
744 * @param $title Title
747 function transform( $message, $interface = false, $language = null, $title = null ) {
748 // Avoid creating parser if nothing to transform
749 if( strpos( $message, '{{' ) === false ) {
753 if ( $this->mInParser
) {
757 $parser = $this->getParser();
759 $popts = $this->getParserOptions();
760 $popts->setInterfaceMessage( $interface );
761 $popts->setTargetLanguage( $language );
762 $popts->setUserLang( $language );
764 $this->mInParser
= true;
765 $message = $parser->transformMsg( $message, $popts, $title );
766 $this->mInParser
= false;
774 function getParser() {
775 global $wgParser, $wgParserConf;
776 if ( !$this->mParser
&& isset( $wgParser ) ) {
777 # Do some initialisation so that we don't have to do it twice
778 $wgParser->firstCallInit();
779 # Clone it and store it
780 $class = $wgParserConf['class'];
781 if ( $class == 'Parser_DiffTest' ) {
783 $this->mParser
= new $class( $wgParserConf );
785 $this->mParser
= clone $wgParser;
788 return $this->mParser
;
792 * @param $text string
793 * @param $string Title|string
794 * @param $interface bool
795 * @param $linestart bool
797 * @return ParserOutput
799 public function parse( $text, $key, $linestart = true, $interface = false, $language = null ) {
800 if ( $this->mInParser
) {
801 return htmlspecialchars( $text );
804 $parser = $this->getParser();
805 $popts = $this->getParserOptions();
808 $popts->setInterfaceMessage( true );
810 if ( $language !== null ) {
811 $popts->setTargetLanguage( $language );
814 if ( !($key instanceof Title
) ) {
815 $title = Title
::newFromText( $key, NS_MEDIAWIKI
);
817 $this->mInParser
= true;
818 $res = $parser->parse( $text, $title, $popts, $linestart );
819 $this->mInParser
= false;
825 $this->mDisable
= true;
829 $this->mDisable
= false;
833 * Clear all stored messages. Mainly used after a mass rebuild.
836 $langs = Language
::getLanguageNames( false );
837 foreach ( array_keys($langs) as $code ) {
839 $this->mMemc
->delete( wfMemcKey( 'messages', $code ) );
840 # Invalidate all local caches
841 $this->mMemc
->delete( wfMemcKey( 'messages', $code, 'hash' ) );
843 $this->mLoadedLanguages
= array();
846 public function figureMessage( $key ) {
847 global $wgLanguageCode;
848 $pieces = explode( '/', $key );
849 if( count( $pieces ) < 2 ) {
850 return array( $key, $wgLanguageCode );
853 $lang = array_pop( $pieces );
854 $validCodes = Language
::getLanguageNames();
855 if( !array_key_exists( $lang, $validCodes ) ) {
856 return array( $key, $wgLanguageCode );
859 $message = implode( '/', $pieces );
860 return array( $message, $lang );
863 public static function logMessages() {
864 wfProfileIn( __METHOD__
);
865 global $wgAdaptiveMessageCache;
866 if ( !$wgAdaptiveMessageCache ||
!self
::$instance instanceof MessageCache
) {
867 wfProfileOut( __METHOD__
);
871 $cachekey = wfMemckey( 'message-profiling' );
872 $cache = wfGetCache( CACHE_DB
);
873 $data = $cache->get( $cachekey );
879 $age = self
::$mAdaptiveDataAge;
880 $filterDate = substr( wfTimestamp( TS_MW
, time() - $age ), 0, 8 );
881 foreach ( array_keys( $data ) as $key ) {
882 if ( $key < $filterDate ) {
883 unset( $data[$key] );
887 $index = substr( wfTimestampNow(), 0, 8 );
888 if ( !isset( $data[$index] ) ) {
889 $data[$index] = array();
892 foreach ( self
::$instance->mRequestedMessages
as $message => $_ ) {
893 if ( !isset( $data[$index][$message] ) ) {
894 $data[$index][$message] = 0;
896 $data[$index][$message]++
;
899 $cache->set( $cachekey, $data );
900 wfProfileOut( __METHOD__
);
903 public function getMostUsedMessages() {
904 wfProfileIn( __METHOD__
);
905 $cachekey = wfMemcKey( 'message-profiling' );
906 $cache = wfGetCache( CACHE_DB
);
907 $data = $cache->get( $cachekey );
909 wfProfileOut( __METHOD__
);
915 foreach( $data as $messages ) {
916 foreach( $messages as $message => $count ) {
918 if ( !isset( $list[$key] ) ) {
921 $list[$key] +
= $count;
926 foreach ( $list as $message => $count ) {
927 if ( $count < intval( $max * self
::$mAdaptiveInclusionThreshold ) ) {
928 unset( $list[$message] );
932 wfProfileOut( __METHOD__
);
933 return array_keys( $list );