3 * Localisation messages cache.
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.
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.
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
27 define( 'MSG_LOAD_TIMEOUT', 60 );
28 define( 'MSG_LOCK_TIMEOUT', 10 );
29 define( 'MSG_WAIT_TIMEOUT', 10 );
30 define( 'MSG_CACHE_VERSION', 1 );
34 * Performs various MediaWiki namespace-related functions
39 * Process local cache of loaded messages that are defined in
40 * MediaWiki namespace. First array level is a language code,
41 * second level is message key and the values are either message
42 * content prefixed with space, or !NONEXISTENT for negative
47 // Should mean that database cannot be used, but check
50 /// Lifetime for cache, used by object caching
54 * Message cache has it's own parser which it uses to transform
57 protected $mParserOptions, $mParser;
59 /// Variable for tracking which variables are already loaded
60 protected $mLoadedLanguages = array();
67 private static $instance;
72 protected $mInParser = false;
75 * Get the signleton instance of this class
78 * @return MessageCache object
80 public static function singleton() {
81 if ( is_null( self
::$instance ) ) {
82 global $wgUseDatabaseMessages, $wgMsgCacheExpiry;
83 self
::$instance = new self( wfGetMessageCacheStorage(), $wgUseDatabaseMessages, $wgMsgCacheExpiry );
85 return self
::$instance;
89 * Destroy the singleton instance
93 public static function destroyInstance() {
94 self
::$instance = null;
97 function __construct( $memCached, $useDB, $expiry ) {
99 $memCached = wfGetCache( CACHE_NONE
);
102 $this->mMemc
= $memCached;
103 $this->mDisable
= !$useDB;
104 $this->mExpiry
= $expiry;
108 * ParserOptions is lazy initialised.
110 * @return ParserOptions
112 function getParserOptions() {
113 if ( !$this->mParserOptions
) {
114 $this->mParserOptions
= new ParserOptions
;
115 $this->mParserOptions
->setEditSection( false );
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 bool 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, null, __METHOD__
); // 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 wfSuppressWarnings();
191 chmod( $filename, 0666 );
195 function saveToScript( $array, $hash, $code ) {
196 global $wgCacheDirectory;
198 $filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
199 $tempFilename = $filename . '.tmp';
200 wfMkdirParents( $wgCacheDirectory, null, __METHOD__
); // might fail
202 wfSuppressWarnings();
203 $file = fopen( $tempFilename, 'w' );
207 wfDebug( "Unable to open local cache file for writing\n" );
211 fwrite( $file, "<?php\n//$hash\n\n \$this->mCache = array(" );
213 foreach ( $array as $key => $message ) {
214 $key = $this->escapeForScript( $key );
215 $message = $this->escapeForScript( $message );
216 fwrite( $file, "'$key' => '$message',\n" );
219 fwrite( $file, ");\n?>" );
221 rename( $tempFilename, $filename );
224 function escapeForScript( $string ) {
225 $string = str_replace( '\\', '\\\\', $string );
226 $string = str_replace( '\'', '\\\'', $string );
231 * Set the cache to $cache, if it is valid. Otherwise set the cache to false.
235 function setCache( $cache, $code ) {
236 if ( isset( $cache['VERSION'] ) && $cache['VERSION'] == MSG_CACHE_VERSION
) {
237 $this->mCache
[$code] = $cache;
245 * Loads messages from caches or from database in this order:
246 * (1) local message cache (if $wgUseLocalMessageCache is enabled)
248 * (3) from the database.
250 * When succesfully loading from (2) or (3), all higher level caches are
251 * updated for the newest version.
253 * Nothing is loaded if member variable mDisable is true, either manually
254 * set by calling code or if message loading fails (is this possible?).
256 * Returns true if cache is already populated or it was succesfully populated,
257 * or false if populating empty cache fails. Also returns true if MessageCache
260 * @param $code String: language to which load messages
263 function load( $code = false ) {
264 global $wgUseLocalMessageCache;
266 if( !is_string( $code ) ) {
267 # This isn't really nice, so at least make a note about it and try to
269 wfDebug( __METHOD__
. " called without providing a language code\n" );
273 # Don't do double loading...
274 if ( isset( $this->mLoadedLanguages
[$code] ) ) {
278 # 8 lines of code just to say (once) that message cache is disabled
279 if ( $this->mDisable
) {
280 static $shownDisabled = false;
281 if ( !$shownDisabled ) {
282 wfDebug( __METHOD__
. ": disabled\n" );
283 $shownDisabled = true;
288 # Loading code starts
289 wfProfileIn( __METHOD__
);
290 $success = false; # Keep track of success
291 $where = array(); # Debug info, delayed to avoid spamming debug log too much
292 $cacheKey = wfMemcKey( 'messages', $code ); # Key in memc for messages
295 # Hash of the contents is stored in memcache, to detect if local cache goes
296 # out of date (due to update in other thread?)
297 if ( $wgUseLocalMessageCache ) {
298 wfProfileIn( __METHOD__
. '-fromlocal' );
300 $hash = $this->mMemc
->get( wfMemcKey( 'messages', $code, 'hash' ) );
302 $success = $this->loadFromLocal( $hash, $code );
303 if ( $success ) $where[] = 'got from local cache';
305 wfProfileOut( __METHOD__
. '-fromlocal' );
309 # Fails if nothing in cache, or in the wrong version.
311 wfProfileIn( __METHOD__
. '-fromcache' );
312 $cache = $this->mMemc
->get( $cacheKey );
313 $success = $this->setCache( $cache, $code );
315 $where[] = 'got from global cache';
316 $this->saveToCaches( $cache, false, $code );
318 wfProfileOut( __METHOD__
. '-fromcache' );
322 # Nothing in caches... so we need create one and store it in caches
324 $where[] = 'cache is empty';
325 $where[] = 'loading from database';
327 $this->lock( $cacheKey );
329 # Limit the concurrency of loadFromDB to a single process
330 # This prevents the site from going down when the cache expires
331 $statusKey = wfMemcKey( 'messages', $code, 'status' );
332 $success = $this->mMemc
->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT
);
334 $cache = $this->loadFromDB( $code );
335 $success = $this->setCache( $cache, $code );
338 $success = $this->saveToCaches( $cache, true, $code );
340 $this->mMemc
->delete( $statusKey );
342 $this->mMemc
->set( $statusKey, 'error', 60 * 5 );
343 wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
346 $this->unlock($cacheKey);
350 # Bad luck... this should not happen
351 $where[] = 'loading FAILED - cache is disabled';
352 $info = implode( ', ', $where );
353 wfDebug( __METHOD__
. ": Loading $code... $info\n" );
354 $this->mDisable
= true;
355 $this->mCache
= false;
357 # All good, just record the success
358 $info = implode( ', ', $where );
359 wfDebug( __METHOD__
. ": Loading $code... $info\n" );
360 $this->mLoadedLanguages
[$code] = true;
362 wfProfileOut( __METHOD__
);
367 * Loads cacheable messages from the database. Messages bigger than
368 * $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded
369 * on-demand from the database later.
371 * @param $code String: language code.
372 * @return Array: loaded messages for storing in caches.
374 function loadFromDB( $code ) {
375 wfProfileIn( __METHOD__
);
376 global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache;
377 $dbr = wfGetDB( DB_SLAVE
);
382 'page_is_redirect' => 0,
383 'page_namespace' => NS_MEDIAWIKI
,
387 if ( $wgAdaptiveMessageCache && $code !== $wgLanguageCode ) {
388 if ( !isset( $this->mCache
[$wgLanguageCode] ) ) {
389 $this->load( $wgLanguageCode );
391 $mostused = array_keys( $this->mCache
[$wgLanguageCode] );
392 foreach ( $mostused as $key => $value ) {
393 $mostused[$key] = "$value/$code";
397 if ( count( $mostused ) ) {
398 $conds['page_title'] = $mostused;
399 } elseif ( $code !== $wgLanguageCode ) {
400 $conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), '/', $code );
402 # Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
403 # other than language code.
404 $conds[] = 'page_title NOT' . $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
407 # Conditions to fetch oversized pages to ignore them
409 $bigConds[] = 'page_len > ' . intval( $wgMaxMsgCacheEntrySize );
411 # Load titles for all oversized pages in the MediaWiki namespace
412 $res = $dbr->select( 'page', 'page_title', $bigConds, __METHOD__
. "($code)-big" );
413 foreach ( $res as $row ) {
414 $cache[$row->page_title
] = '!TOO BIG';
417 # Conditions to load the remaining pages with their contents
418 $smallConds = $conds;
419 $smallConds[] = 'page_latest=rev_id';
420 $smallConds[] = 'rev_text_id=old_id';
421 $smallConds[] = 'page_len <= ' . intval( $wgMaxMsgCacheEntrySize );
424 array( 'page', 'revision', 'text' ),
425 array( 'page_title', 'old_text', 'old_flags' ),
427 __METHOD__
. "($code)-small"
430 foreach ( $res as $row ) {
431 $text = Revision
::getRevisionText( $row );
432 if( $text === false ) {
433 // Failed to fetch data; possible ES errors?
434 // Store a marker to fetch on-demand as a workaround...
436 wfDebugLog( 'MessageCache', __METHOD__
. ": failed to load message page text for {$row->page_title} ($code)" );
438 $entry = ' ' . $text;
440 $cache[$row->page_title
] = $entry;
443 $cache['VERSION'] = MSG_CACHE_VERSION
;
444 wfProfileOut( __METHOD__
);
449 * Updates cache as necessary when message page is changed
451 * @param $title String: name of the page changed.
452 * @param $text Mixed: new contents of the page.
454 public function replace( $title, $text ) {
455 global $wgMaxMsgCacheEntrySize;
456 wfProfileIn( __METHOD__
);
458 if ( $this->mDisable
) {
459 wfProfileOut( __METHOD__
);
463 list( $msg, $code ) = $this->figureMessage( $title );
465 $cacheKey = wfMemcKey( 'messages', $code );
466 $this->load( $code );
467 $this->lock( $cacheKey );
469 $titleKey = wfMemcKey( 'messages', 'individual', $title );
471 if ( $text === false ) {
472 # Article was deleted
473 $this->mCache
[$code][$title] = '!NONEXISTENT';
474 $this->mMemc
->delete( $titleKey );
475 } elseif ( strlen( $text ) > $wgMaxMsgCacheEntrySize ) {
477 $this->mCache
[$code][$title] = '!TOO BIG';
478 $this->mMemc
->set( $titleKey, ' ' . $text, $this->mExpiry
);
480 $this->mCache
[$code][$title] = ' ' . $text;
481 $this->mMemc
->delete( $titleKey );
485 $this->saveToCaches( $this->mCache
[$code], true, $code );
486 $this->unlock( $cacheKey );
488 // Also delete cached sidebar... just in case it is affected
489 $codes = array( $code );
490 if ( $code === 'en' ) {
491 // Delete all sidebars, like for example on action=purge on the
493 $codes = array_keys( Language
::fetchLanguageNames() );
497 foreach ( $codes as $code ) {
498 $sidebarKey = wfMemcKey( 'sidebar', $code );
499 $wgMemc->delete( $sidebarKey );
502 // Update the message in the message blob store
504 MessageBlobStore
::updateMessage( $wgContLang->lcfirst( $msg ) );
506 wfRunHooks( 'MessageCacheReplace', array( $title, $text ) );
508 wfProfileOut( __METHOD__
);
512 * Shortcut to update caches.
514 * @param $cache Array: cached messages with a version.
515 * @param $memc Bool: Wether to update or not memcache.
516 * @param $code String: Language code.
517 * @return bool on somekind of error.
519 protected function saveToCaches( $cache, $memc = true, $code = false ) {
520 wfProfileIn( __METHOD__
);
521 global $wgUseLocalMessageCache, $wgLocalMessageCacheSerialized;
523 $cacheKey = wfMemcKey( 'messages', $code );
526 $success = $this->mMemc
->set( $cacheKey, $cache, $this->mExpiry
);
531 # Save to local cache
532 if ( $wgUseLocalMessageCache ) {
533 $serialized = serialize( $cache );
534 $hash = md5( $serialized );
535 $this->mMemc
->set( wfMemcKey( 'messages', $code, 'hash' ), $hash, $this->mExpiry
);
536 if ($wgLocalMessageCacheSerialized) {
537 $this->saveToLocal( $serialized, $hash, $code );
539 $this->saveToScript( $cache, $hash, $code );
543 wfProfileOut( __METHOD__
);
548 * Represents a write lock on the messages key
552 * @return Boolean: success
554 function lock( $key ) {
555 $lockKey = $key . ':lock';
556 for ( $i = 0; $i < MSG_WAIT_TIMEOUT
&& !$this->mMemc
->add( $lockKey, 1, MSG_LOCK_TIMEOUT
); $i++
) {
560 return $i >= MSG_WAIT_TIMEOUT
;
563 function unlock( $key ) {
564 $lockKey = $key . ':lock';
565 $this->mMemc
->delete( $lockKey );
569 * Get a message from either the content language or the user language.
571 * @param $key String: the message cache key
572 * @param $useDB Boolean: get the message from the DB, false to use only
574 * @param bool|string $langcode Code of the language to get the message for, if
575 * it is a valid code create a language for that language,
576 * if it is a string but not a valid code then make a basic
577 * language object, if it is a false boolean then use the
578 * current users language (as a fallback for the old
579 * parameter functionality), or if it is a true boolean
580 * then use the wikis content language (also as a
582 * @param $isFullKey Boolean: specifies whether $key is a two part key
585 * @throws MWException
586 * @return string|bool
588 function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) {
589 global $wgLanguageCode, $wgContLang;
591 if ( is_int( $key ) ) {
592 // "Non-string key given" exception sometimes happens for numerical strings that become ints somewhere on their way here
593 $key = strval( $key );
596 if ( !is_string( $key ) ) {
597 throw new MWException( 'Non-string key given' );
600 if ( strval( $key ) === '' ) {
601 # Shortcut: the empty key is always missing
605 $lang = wfGetLangObj( $langcode );
607 throw new MWException( "Bad lang code $langcode given" );
610 $langcode = $lang->getCode();
614 # Normalise title-case input (with some inlining)
615 $lckey = str_replace( ' ', '_', $key );
616 if ( ord( $key ) < 128 ) {
617 $lckey[0] = strtolower( $lckey[0] );
618 $uckey = ucfirst( $lckey );
620 $lckey = $wgContLang->lcfirst( $lckey );
621 $uckey = $wgContLang->ucfirst( $lckey );
624 # Try the MediaWiki namespace
625 if( !$this->mDisable
&& $useDB ) {
627 if( !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
628 $title .= '/' . $langcode;
630 $message = $this->getMsgFromNamespace( $title, $langcode );
633 # Try the array in the language object
634 if ( $message === false ) {
635 $message = $lang->getMessage( $lckey );
636 if ( is_null( $message ) ) {
641 # Try the array of another language
642 if( $message === false ) {
643 $parts = explode( '/', $lckey );
644 # We may get calls for things that are http-urls from sidebar
645 # Let's not load nonexistent languages for those
646 # They usually have more than one slash.
647 if ( count( $parts ) == 2 && $parts[1] !== '' ) {
648 $message = Language
::getMessageFor( $parts[0], $parts[1] );
649 if ( is_null( $message ) ) {
655 # Is this a custom message? Try the default language in the db...
656 if( ( $message === false ||
$message === '-' ) &&
657 !$this->mDisable
&& $useDB &&
658 !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
659 $message = $this->getMsgFromNamespace( $uckey, $wgLanguageCode );
663 if( $message === false ) {
668 $message = strtr( $message,
670 # Fix for trailing whitespace, removed by textarea
672 # Fix for NBSP, converted to space by firefox
673 ' ' => "\xc2\xa0",
674 ' ' => "\xc2\xa0",
681 * Get a message from the MediaWiki namespace, with caching. The key must
682 * first be converted to two-part lang/msg form if necessary.
684 * @param $title String: Message cache key with initial uppercase letter.
685 * @param $code String: code denoting the language to try.
687 * @return string|bool False on failure
689 function getMsgFromNamespace( $title, $code ) {
690 $this->load( $code );
691 if ( isset( $this->mCache
[$code][$title] ) ) {
692 $entry = $this->mCache
[$code][$title];
693 if ( substr( $entry, 0, 1 ) === ' ' ) {
694 return substr( $entry, 1 );
695 } elseif ( $entry === '!NONEXISTENT' ) {
697 } elseif( $entry === '!TOO BIG' ) {
698 // Fall through and try invididual message cache below
701 // XXX: This is not cached in process cache, should it?
703 wfRunHooks( 'MessagesPreLoad', array( $title, &$message ) );
704 if ( $message !== false ) {
711 # Try the individual message cache
712 $titleKey = wfMemcKey( 'messages', 'individual', $title );
713 $entry = $this->mMemc
->get( $titleKey );
715 if ( substr( $entry, 0, 1 ) === ' ' ) {
716 $this->mCache
[$code][$title] = $entry;
717 return substr( $entry, 1 );
718 } elseif ( $entry === '!NONEXISTENT' ) {
719 $this->mCache
[$code][$title] = '!NONEXISTENT';
722 # Corrupt/obsolete entry, delete it
723 $this->mMemc
->delete( $titleKey );
727 # Try loading it from the database
728 $revision = Revision
::newFromTitle(
729 Title
::makeTitle( NS_MEDIAWIKI
, $title ), false, Revision
::READ_LATEST
732 $content = $revision->getContent();
734 // A possibly temporary loading failure.
735 wfDebugLog( 'MessageCache', __METHOD__
. ": failed to load message page text for {$title} ($code)" );
736 $message = null; // no negative caching
738 // XXX: Is this the right way to turn a Content object into a message?
739 // NOTE: $content is typically either WikitextContent, JavaScriptContent or CssContent.
740 // MessageContent is *not* used for storing messages, it's only used for wrapping them when needed.
741 $message = $content->getWikitextForTransclusion();
743 if ( $message === false ||
$message === null ) {
744 wfDebugLog( 'MessageCache', __METHOD__
. ": message content doesn't provide wikitext "
745 . "(content model: " . $content->getContentHandler() . ")" );
747 $message = false; // negative caching
749 $this->mCache
[$code][$title] = ' ' . $message;
750 $this->mMemc
->set( $titleKey, ' ' . $message, $this->mExpiry
);
754 $message = false; // negative caching
757 if ( $message === false ) { // negative caching
758 $this->mCache
[$code][$title] = '!NONEXISTENT';
759 $this->mMemc
->set( $titleKey, '!NONEXISTENT', $this->mExpiry
);
766 * @param $message string
767 * @param $interface bool
769 * @param $title Title
772 function transform( $message, $interface = false, $language = null, $title = null ) {
773 // Avoid creating parser if nothing to transform
774 if( strpos( $message, '{{' ) === false ) {
778 if ( $this->mInParser
) {
782 $parser = $this->getParser();
784 $popts = $this->getParserOptions();
785 $popts->setInterfaceMessage( $interface );
786 $popts->setTargetLanguage( $language );
788 $userlang = $popts->setUserLang( $language );
789 $this->mInParser
= true;
790 $message = $parser->transformMsg( $message, $popts, $title );
791 $this->mInParser
= false;
792 $popts->setUserLang( $userlang );
800 function getParser() {
801 global $wgParser, $wgParserConf;
802 if ( !$this->mParser
&& isset( $wgParser ) ) {
803 # Do some initialisation so that we don't have to do it twice
804 $wgParser->firstCallInit();
805 # Clone it and store it
806 $class = $wgParserConf['class'];
807 if ( $class == 'Parser_DiffTest' ) {
809 $this->mParser
= new $class( $wgParserConf );
811 $this->mParser
= clone $wgParser;
814 return $this->mParser
;
818 * @param $text string
819 * @param $title Title
820 * @param $linestart bool
821 * @param $interface bool
823 * @return ParserOutput
825 public function parse( $text, $title = null, $linestart = true, $interface = false, $language = null ) {
826 if ( $this->mInParser
) {
827 return htmlspecialchars( $text );
830 $parser = $this->getParser();
831 $popts = $this->getParserOptions();
832 $popts->setInterfaceMessage( $interface );
833 $popts->setTargetLanguage( $language );
835 wfProfileIn( __METHOD__
);
836 if ( !$title ||
!$title instanceof Title
) {
840 // Sometimes $wgTitle isn't set either...
842 # It's not uncommon having a null $wgTitle in scripts. See r80898
843 # Create a ghost title in such case
844 $title = Title
::newFromText( 'Dwimmerlaik' );
847 $this->mInParser
= true;
848 $res = $parser->parse( $text, $title, $popts, $linestart );
849 $this->mInParser
= false;
851 wfProfileOut( __METHOD__
);
856 $this->mDisable
= true;
860 $this->mDisable
= false;
864 * Clear all stored messages. Mainly used after a mass rebuild.
867 $langs = Language
::fetchLanguageNames( null, 'mw' );
868 foreach ( array_keys( $langs ) as $code ) {
870 $this->mMemc
->delete( wfMemcKey( 'messages', $code ) );
871 # Invalidate all local caches
872 $this->mMemc
->delete( wfMemcKey( 'messages', $code, 'hash' ) );
874 $this->mLoadedLanguages
= array();
881 public function figureMessage( $key ) {
882 global $wgLanguageCode;
883 $pieces = explode( '/', $key );
884 if( count( $pieces ) < 2 ) {
885 return array( $key, $wgLanguageCode );
888 $lang = array_pop( $pieces );
889 if( !Language
::fetchLanguageName( $lang, null, 'mw' ) ) {
890 return array( $key, $wgLanguageCode );
893 $message = implode( '/', $pieces );
894 return array( $message, $lang );
898 * Get all message keys stored in the message cache for a given language.
899 * If $code is the content language code, this will return all message keys
900 * for which MediaWiki:msgkey exists. If $code is another language code, this
901 * will ONLY return message keys for which MediaWiki:msgkey/$code exists.
902 * @param $code string
903 * @return array of message keys (strings)
905 public function getAllMessageKeys( $code ) {
907 $this->load( $code );
908 if ( !isset( $this->mCache
[$code] ) ) {
909 // Apparently load() failed
912 $cache = $this->mCache
[$code]; // Copy the cache
913 unset( $cache['VERSION'] ); // Remove the VERSION key
914 $cache = array_diff( $cache, array( '!NONEXISTENT' ) ); // Remove any !NONEXISTENT keys
915 // Keys may appear with a capital first letter. lcfirst them.
916 return array_map( array( $wgContLang, 'lcfirst' ), array_keys( $cache ) );