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 bool|String $code String: language to which load messages
261 * @throws MWException
264 function load( $code = false ) {
265 global $wgUseLocalMessageCache;
267 if( !is_string( $code ) ) {
268 # This isn't really nice, so at least make a note about it and try to
270 wfDebug( __METHOD__
. " called without providing a language code\n" );
274 # Don't do double loading...
275 if ( isset( $this->mLoadedLanguages
[$code] ) ) {
279 # 8 lines of code just to say (once) that message cache is disabled
280 if ( $this->mDisable
) {
281 static $shownDisabled = false;
282 if ( !$shownDisabled ) {
283 wfDebug( __METHOD__
. ": disabled\n" );
284 $shownDisabled = true;
289 # Loading code starts
290 wfProfileIn( __METHOD__
);
291 $success = false; # Keep track of success
292 $where = array(); # Debug info, delayed to avoid spamming debug log too much
293 $cacheKey = wfMemcKey( 'messages', $code ); # Key in memc for messages
296 # Hash of the contents is stored in memcache, to detect if local cache goes
297 # out of date (due to update in other thread?)
298 if ( $wgUseLocalMessageCache ) {
299 wfProfileIn( __METHOD__
. '-fromlocal' );
301 $hash = $this->mMemc
->get( wfMemcKey( 'messages', $code, 'hash' ) );
303 $success = $this->loadFromLocal( $hash, $code );
304 if ( $success ) $where[] = 'got from local cache';
306 wfProfileOut( __METHOD__
. '-fromlocal' );
310 # Fails if nothing in cache, or in the wrong version.
312 wfProfileIn( __METHOD__
. '-fromcache' );
313 $cache = $this->mMemc
->get( $cacheKey );
314 $success = $this->setCache( $cache, $code );
316 $where[] = 'got from global cache';
317 $this->saveToCaches( $cache, false, $code );
319 wfProfileOut( __METHOD__
. '-fromcache' );
323 # Nothing in caches... so we need create one and store it in caches
325 $where[] = 'cache is empty';
326 $where[] = 'loading from database';
328 $this->lock( $cacheKey );
330 # Limit the concurrency of loadFromDB to a single process
331 # This prevents the site from going down when the cache expires
332 $statusKey = wfMemcKey( 'messages', $code, 'status' );
333 $success = $this->mMemc
->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT
);
335 $cache = $this->loadFromDB( $code );
336 $success = $this->setCache( $cache, $code );
339 $success = $this->saveToCaches( $cache, true, $code );
341 $this->mMemc
->delete( $statusKey );
343 $this->mMemc
->set( $statusKey, 'error', 60 * 5 );
344 wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
347 $this->unlock($cacheKey);
351 $this->mDisable
= true;
352 $this->mCache
= false;
353 // This used to go on, but that led to lots of nasty side
354 // effects like gadgets and sidebar getting cached with their
356 throw new MWException( "MessageCache failed to load messages" );
358 # All good, just record the success
359 $info = implode( ', ', $where );
360 wfDebug( __METHOD__
. ": Loading $code... $info\n" );
361 $this->mLoadedLanguages
[$code] = true;
363 wfProfileOut( __METHOD__
);
368 * Loads cacheable messages from the database. Messages bigger than
369 * $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded
370 * on-demand from the database later.
372 * @param $code String: language code.
373 * @return Array: loaded messages for storing in caches.
375 function loadFromDB( $code ) {
376 wfProfileIn( __METHOD__
);
377 global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache;
378 $dbr = wfGetDB( DB_SLAVE
);
383 'page_is_redirect' => 0,
384 'page_namespace' => NS_MEDIAWIKI
,
388 if ( $wgAdaptiveMessageCache && $code !== $wgLanguageCode ) {
389 if ( !isset( $this->mCache
[$wgLanguageCode] ) ) {
390 $this->load( $wgLanguageCode );
392 $mostused = array_keys( $this->mCache
[$wgLanguageCode] );
393 foreach ( $mostused as $key => $value ) {
394 $mostused[$key] = "$value/$code";
398 if ( count( $mostused ) ) {
399 $conds['page_title'] = $mostused;
400 } elseif ( $code !== $wgLanguageCode ) {
401 $conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), '/', $code );
403 # Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
404 # other than language code.
405 $conds[] = 'page_title NOT' . $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
408 # Conditions to fetch oversized pages to ignore them
410 $bigConds[] = 'page_len > ' . intval( $wgMaxMsgCacheEntrySize );
412 # Load titles for all oversized pages in the MediaWiki namespace
413 $res = $dbr->select( 'page', 'page_title', $bigConds, __METHOD__
. "($code)-big" );
414 foreach ( $res as $row ) {
415 $cache[$row->page_title
] = '!TOO BIG';
418 # Conditions to load the remaining pages with their contents
419 $smallConds = $conds;
420 $smallConds[] = 'page_latest=rev_id';
421 $smallConds[] = 'rev_text_id=old_id';
422 $smallConds[] = 'page_len <= ' . intval( $wgMaxMsgCacheEntrySize );
425 array( 'page', 'revision', 'text' ),
426 array( 'page_title', 'old_text', 'old_flags' ),
428 __METHOD__
. "($code)-small"
431 foreach ( $res as $row ) {
432 $text = Revision
::getRevisionText( $row );
433 if( $text === false ) {
434 // Failed to fetch data; possible ES errors?
435 // Store a marker to fetch on-demand as a workaround...
437 wfDebugLog( 'MessageCache', __METHOD__
. ": failed to load message page text for {$row->page_title} ($code)" );
439 $entry = ' ' . $text;
441 $cache[$row->page_title
] = $entry;
444 $cache['VERSION'] = MSG_CACHE_VERSION
;
445 wfProfileOut( __METHOD__
);
450 * Updates cache as necessary when message page is changed
452 * @param $title String: name of the page changed.
453 * @param $text Mixed: new contents of the page.
455 public function replace( $title, $text ) {
456 global $wgMaxMsgCacheEntrySize;
457 wfProfileIn( __METHOD__
);
459 if ( $this->mDisable
) {
460 wfProfileOut( __METHOD__
);
464 list( $msg, $code ) = $this->figureMessage( $title );
466 $cacheKey = wfMemcKey( 'messages', $code );
467 $this->load( $code );
468 $this->lock( $cacheKey );
470 $titleKey = wfMemcKey( 'messages', 'individual', $title );
472 if ( $text === false ) {
473 # Article was deleted
474 $this->mCache
[$code][$title] = '!NONEXISTENT';
475 $this->mMemc
->delete( $titleKey );
476 } elseif ( strlen( $text ) > $wgMaxMsgCacheEntrySize ) {
478 $this->mCache
[$code][$title] = '!TOO BIG';
479 $this->mMemc
->set( $titleKey, ' ' . $text, $this->mExpiry
);
481 $this->mCache
[$code][$title] = ' ' . $text;
482 $this->mMemc
->delete( $titleKey );
486 $this->saveToCaches( $this->mCache
[$code], true, $code );
487 $this->unlock( $cacheKey );
489 // Also delete cached sidebar... just in case it is affected
490 $codes = array( $code );
491 if ( $code === 'en' ) {
492 // Delete all sidebars, like for example on action=purge on the
494 $codes = array_keys( Language
::fetchLanguageNames() );
498 foreach ( $codes as $code ) {
499 $sidebarKey = wfMemcKey( 'sidebar', $code );
500 $wgMemc->delete( $sidebarKey );
503 // Update the message in the message blob store
505 MessageBlobStore
::updateMessage( $wgContLang->lcfirst( $msg ) );
507 wfRunHooks( 'MessageCacheReplace', array( $title, $text ) );
509 wfProfileOut( __METHOD__
);
513 * Shortcut to update caches.
515 * @param $cache Array: cached messages with a version.
516 * @param $memc Bool: Wether to update or not memcache.
517 * @param $code String: Language code.
518 * @return bool on somekind of error.
520 protected function saveToCaches( $cache, $memc = true, $code = false ) {
521 wfProfileIn( __METHOD__
);
522 global $wgUseLocalMessageCache, $wgLocalMessageCacheSerialized;
524 $cacheKey = wfMemcKey( 'messages', $code );
527 $success = $this->mMemc
->set( $cacheKey, $cache, $this->mExpiry
);
532 # Save to local cache
533 if ( $wgUseLocalMessageCache ) {
534 $serialized = serialize( $cache );
535 $hash = md5( $serialized );
536 $this->mMemc
->set( wfMemcKey( 'messages', $code, 'hash' ), $hash, $this->mExpiry
);
537 if ($wgLocalMessageCacheSerialized) {
538 $this->saveToLocal( $serialized, $hash, $code );
540 $this->saveToScript( $cache, $hash, $code );
544 wfProfileOut( __METHOD__
);
549 * Represents a write lock on the messages key
553 * @return Boolean: success
555 function lock( $key ) {
556 $lockKey = $key . ':lock';
557 for ( $i = 0; $i < MSG_WAIT_TIMEOUT
&& !$this->mMemc
->add( $lockKey, 1, MSG_LOCK_TIMEOUT
); $i++
) {
561 return $i >= MSG_WAIT_TIMEOUT
;
564 function unlock( $key ) {
565 $lockKey = $key . ':lock';
566 $this->mMemc
->delete( $lockKey );
570 * Get a message from either the content language or the user language.
572 * @param $key String: the message cache key
573 * @param $useDB Boolean: get the message from the DB, false to use only
575 * @param bool|string $langcode Code of the language to get the message for, if
576 * it is a valid code create a language for that language,
577 * if it is a string but not a valid code then make a basic
578 * language object, if it is a false boolean then use the
579 * current users language (as a fallback for the old
580 * parameter functionality), or if it is a true boolean
581 * then use the wikis content language (also as a
583 * @param $isFullKey Boolean: specifies whether $key is a two part key
586 * @throws MWException
587 * @return string|bool
589 function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) {
590 global $wgLanguageCode, $wgContLang;
592 if ( is_int( $key ) ) {
593 // "Non-string key given" exception sometimes happens for numerical strings that become ints somewhere on their way here
594 $key = strval( $key );
597 if ( !is_string( $key ) ) {
598 throw new MWException( 'Non-string key given' );
601 if ( strval( $key ) === '' ) {
602 # Shortcut: the empty key is always missing
606 $lang = wfGetLangObj( $langcode );
608 throw new MWException( "Bad lang code $langcode given" );
611 $langcode = $lang->getCode();
615 # Normalise title-case input (with some inlining)
616 $lckey = str_replace( ' ', '_', $key );
617 if ( ord( $key ) < 128 ) {
618 $lckey[0] = strtolower( $lckey[0] );
619 $uckey = ucfirst( $lckey );
621 $lckey = $wgContLang->lcfirst( $lckey );
622 $uckey = $wgContLang->ucfirst( $lckey );
625 # Try the MediaWiki namespace
626 if( !$this->mDisable
&& $useDB ) {
628 if( !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
629 $title .= '/' . $langcode;
631 $message = $this->getMsgFromNamespace( $title, $langcode );
634 # Try the array in the language object
635 if ( $message === false ) {
636 $message = $lang->getMessage( $lckey );
637 if ( is_null( $message ) ) {
642 # Try the array of another language
643 if( $message === false ) {
644 $parts = explode( '/', $lckey );
645 # We may get calls for things that are http-urls from sidebar
646 # Let's not load nonexistent languages for those
647 # They usually have more than one slash.
648 if ( count( $parts ) == 2 && $parts[1] !== '' ) {
649 $message = Language
::getMessageFor( $parts[0], $parts[1] );
650 if ( is_null( $message ) ) {
656 # Is this a custom message? Try the default language in the db...
657 if( ( $message === false ||
$message === '-' ) &&
658 !$this->mDisable
&& $useDB &&
659 !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
660 $message = $this->getMsgFromNamespace( $uckey, $wgLanguageCode );
664 if( $message === false ) {
669 $message = strtr( $message,
671 # Fix for trailing whitespace, removed by textarea
673 # Fix for NBSP, converted to space by firefox
674 ' ' => "\xc2\xa0",
675 ' ' => "\xc2\xa0",
682 * Get a message from the MediaWiki namespace, with caching. The key must
683 * first be converted to two-part lang/msg form if necessary.
685 * @param $title String: Message cache key with initial uppercase letter.
686 * @param $code String: code denoting the language to try.
688 * @return string|bool False on failure
690 function getMsgFromNamespace( $title, $code ) {
691 $this->load( $code );
692 if ( isset( $this->mCache
[$code][$title] ) ) {
693 $entry = $this->mCache
[$code][$title];
694 if ( substr( $entry, 0, 1 ) === ' ' ) {
695 return substr( $entry, 1 );
696 } elseif ( $entry === '!NONEXISTENT' ) {
698 } elseif( $entry === '!TOO BIG' ) {
699 // Fall through and try invididual message cache below
702 // XXX: This is not cached in process cache, should it?
704 wfRunHooks( 'MessagesPreLoad', array( $title, &$message ) );
705 if ( $message !== false ) {
712 # Try the individual message cache
713 $titleKey = wfMemcKey( 'messages', 'individual', $title );
714 $entry = $this->mMemc
->get( $titleKey );
716 if ( substr( $entry, 0, 1 ) === ' ' ) {
717 $this->mCache
[$code][$title] = $entry;
718 return substr( $entry, 1 );
719 } elseif ( $entry === '!NONEXISTENT' ) {
720 $this->mCache
[$code][$title] = '!NONEXISTENT';
723 # Corrupt/obsolete entry, delete it
724 $this->mMemc
->delete( $titleKey );
728 # Try loading it from the database
729 $revision = Revision
::newFromTitle(
730 Title
::makeTitle( NS_MEDIAWIKI
, $title ), false, Revision
::READ_LATEST
733 $content = $revision->getContent();
735 // A possibly temporary loading failure.
736 wfDebugLog( 'MessageCache', __METHOD__
. ": failed to load message page text for {$title} ($code)" );
737 $message = null; // no negative caching
739 // XXX: Is this the right way to turn a Content object into a message?
740 // NOTE: $content is typically either WikitextContent, JavaScriptContent or CssContent.
741 // MessageContent is *not* used for storing messages, it's only used for wrapping them when needed.
742 $message = $content->getWikitextForTransclusion();
744 if ( $message === false ||
$message === null ) {
745 wfDebugLog( 'MessageCache', __METHOD__
. ": message content doesn't provide wikitext "
746 . "(content model: " . $content->getContentHandler() . ")" );
748 $message = false; // negative caching
750 $this->mCache
[$code][$title] = ' ' . $message;
751 $this->mMemc
->set( $titleKey, ' ' . $message, $this->mExpiry
);
755 $message = false; // negative caching
758 if ( $message === false ) { // negative caching
759 $this->mCache
[$code][$title] = '!NONEXISTENT';
760 $this->mMemc
->set( $titleKey, '!NONEXISTENT', $this->mExpiry
);
767 * @param $message string
768 * @param $interface bool
770 * @param $title Title
773 function transform( $message, $interface = false, $language = null, $title = null ) {
774 // Avoid creating parser if nothing to transform
775 if( strpos( $message, '{{' ) === false ) {
779 if ( $this->mInParser
) {
783 $parser = $this->getParser();
785 $popts = $this->getParserOptions();
786 $popts->setInterfaceMessage( $interface );
787 $popts->setTargetLanguage( $language );
789 $userlang = $popts->setUserLang( $language );
790 $this->mInParser
= true;
791 $message = $parser->transformMsg( $message, $popts, $title );
792 $this->mInParser
= false;
793 $popts->setUserLang( $userlang );
801 function getParser() {
802 global $wgParser, $wgParserConf;
803 if ( !$this->mParser
&& isset( $wgParser ) ) {
804 # Do some initialisation so that we don't have to do it twice
805 $wgParser->firstCallInit();
806 # Clone it and store it
807 $class = $wgParserConf['class'];
808 if ( $class == 'Parser_DiffTest' ) {
810 $this->mParser
= new $class( $wgParserConf );
812 $this->mParser
= clone $wgParser;
815 return $this->mParser
;
819 * @param $text string
820 * @param $title Title
821 * @param $linestart bool
822 * @param $interface bool
824 * @return ParserOutput|string
826 public function parse( $text, $title = null, $linestart = true, $interface = false, $language = null ) {
827 if ( $this->mInParser
) {
828 return htmlspecialchars( $text );
831 $parser = $this->getParser();
832 $popts = $this->getParserOptions();
833 $popts->setInterfaceMessage( $interface );
834 $popts->setTargetLanguage( $language );
836 wfProfileIn( __METHOD__
);
837 if ( !$title ||
!$title instanceof Title
) {
841 // Sometimes $wgTitle isn't set either...
843 # It's not uncommon having a null $wgTitle in scripts. See r80898
844 # Create a ghost title in such case
845 $title = Title
::newFromText( 'Dwimmerlaik' );
848 $this->mInParser
= true;
849 $res = $parser->parse( $text, $title, $popts, $linestart );
850 $this->mInParser
= false;
852 wfProfileOut( __METHOD__
);
857 $this->mDisable
= true;
861 $this->mDisable
= false;
865 * Clear all stored messages. Mainly used after a mass rebuild.
868 $langs = Language
::fetchLanguageNames( null, 'mw' );
869 foreach ( array_keys( $langs ) as $code ) {
871 $this->mMemc
->delete( wfMemcKey( 'messages', $code ) );
872 # Invalidate all local caches
873 $this->mMemc
->delete( wfMemcKey( 'messages', $code, 'hash' ) );
875 $this->mLoadedLanguages
= array();
882 public function figureMessage( $key ) {
883 global $wgLanguageCode;
884 $pieces = explode( '/', $key );
885 if( count( $pieces ) < 2 ) {
886 return array( $key, $wgLanguageCode );
889 $lang = array_pop( $pieces );
890 if( !Language
::fetchLanguageName( $lang, null, 'mw' ) ) {
891 return array( $key, $wgLanguageCode );
894 $message = implode( '/', $pieces );
895 return array( $message, $lang );
899 * Get all message keys stored in the message cache for a given language.
900 * If $code is the content language code, this will return all message keys
901 * for which MediaWiki:msgkey exists. If $code is another language code, this
902 * will ONLY return message keys for which MediaWiki:msgkey/$code exists.
903 * @param $code string
904 * @return array of message keys (strings)
906 public function getAllMessageKeys( $code ) {
908 $this->load( $code );
909 if ( !isset( $this->mCache
[$code] ) ) {
910 // Apparently load() failed
913 $cache = $this->mCache
[$code]; // Copy the cache
914 unset( $cache['VERSION'] ); // Remove the VERSION key
915 $cache = array_diff( $cache, array( '!NONEXISTENT' ) ); // Remove any !NONEXISTENT keys
916 // Keys may appear with a capital first letter. lcfirst them.
917 return array_map( array( $wgContLang, 'lcfirst' ), array_keys( $cache ) );