Introduce MessageCache::getAllMessageKeys(), which returns all message keys stored...
authorRoan Kattouw <catrope@users.mediawiki.org>
Wed, 14 Sep 2011 19:59:50 +0000 (19:59 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Wed, 14 Sep 2011 19:59:50 +0000 (19:59 +0000)
includes/api/ApiQueryAllmessages.php
includes/cache/MessageCache.php

index d900d54..ddd8491 100644 (file)
@@ -66,6 +66,17 @@ class ApiQueryAllmessages extends ApiQueryBase {
                // Determine which messages should we print
                if ( in_array( '*', $params['messages'] ) ) {
                        $message_names = Language::getMessageKeysFor( $langObj->getCode() );
+                       if ( $params['includelocal'] ) {
+                               global $wgLanguageCode;
+                               $message_names = array_unique( array_merge(
+                                       $message_names,
+                                       // Pass in the content language code so we get local messages that have a
+                                       // MediaWiki:msgkey page. We might theoretically miss messages that have no
+                                       // MediaWiki:msgkey page but do have a MediaWiki:msgkey/lang page, but that's
+                                       // just a stupid case.
+                                       MessageCache::singleton()->getAllMessageKeys( $wgLanguageCode )
+                               ) );
+                       }
                        sort( $message_names );
                        $messages_target = $message_names;
                } else {
@@ -207,6 +218,7 @@ class ApiQueryAllmessages extends ApiQueryBase {
                        ),
                        'enableparser' => false,
                        'nocontent' => false,
+                       'includelocal' => false,
                        'args' => array(
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_ALLOW_DUPLICATES => true,
@@ -235,6 +247,9 @@ class ApiQueryAllmessages extends ApiQueryBase {
                        'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
                                                        'Will substitute magic words, handle templates etc.' ),
                        'nocontent' => 'If set, do not include the content of the messages in the output.', 
+                       'includelocal' => array( "Also include local messages, i.e. messages that don't exist in the software but do exist as a MediaWiki: page.",
+                                                       "This lists all MediaWiki: pages, so it will also list those that aren't 'really' messages such as Common.js",
+                       ),
                        'title' => 'Page name to use as context when parsing message (for enableparser option)',
                        'args' => 'Arguments to be substituted into message',
                        'prefix' => 'Return messages with this prefix',
index d16f63e..6964479 100644 (file)
@@ -961,4 +961,25 @@ class MessageCache {
                return array_keys( $list );
        }
 
+       /**
+        * Get all message keys stored in the message cache for a given language.
+        * If $code is the content language code, this will return all message keys
+        * for which MediaWiki:msgkey exists. If $code is another language code, this
+        * will ONLY return message keys for which MediaWiki:msgkey/$code exists.
+        * @param $code string
+        * @return array of message keys (strings)
+        */
+       public function getAllMessageKeys( $code ) {
+               global $wgContLang;
+               $this->load( $code );
+               if ( !isset( $this->mCache[$code] ) ) {
+                       // Apparently load() failed
+                       return null;
+               }
+               $cache = $this->mCache[$code]; // Copy the cache
+               unset( $cache['VERSION'] ); // Remove the VERSION key
+               $cache = array_diff( $cache, array( '!NONEXISTENT' ) ); // Remove any !NONEXISTENT keys
+               // Keys may appear with a capital first letter. lcfirst them.
+               return array_map( array( $wgContLang, 'lcfirst' ), array_keys( $cache ) );
+       }
 }