r97092 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97091‎ | r97092 | r97093 >
Date:19:59, 14 September 2011
Author:catrope
Status:ok
Tags:
Comment:
Introduce MessageCache::getAllMessageKeys(), which returns all message keys stored in the MessageCache, and use this to power the amincludelocal parameter in meta=allmessages which adds messages that don't exist in PHP but exist as MediaWiki: pages only.
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryAllmessages.php (modified) (history)
  • /trunk/phase3/includes/cache/MessageCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllmessages.php
@@ -66,6 +66,17 @@
6767 // Determine which messages should we print
6868 if ( in_array( '*', $params['messages'] ) ) {
6969 $message_names = Language::getMessageKeysFor( $langObj->getCode() );
 70+ if ( $params['includelocal'] ) {
 71+ global $wgLanguageCode;
 72+ $message_names = array_unique( array_merge(
 73+ $message_names,
 74+ // Pass in the content language code so we get local messages that have a
 75+ // MediaWiki:msgkey page. We might theoretically miss messages that have no
 76+ // MediaWiki:msgkey page but do have a MediaWiki:msgkey/lang page, but that's
 77+ // just a stupid case.
 78+ MessageCache::singleton()->getAllMessageKeys( $wgLanguageCode )
 79+ ) );
 80+ }
7081 sort( $message_names );
7182 $messages_target = $message_names;
7283 } else {
@@ -207,6 +218,7 @@
208219 ),
209220 'enableparser' => false,
210221 'nocontent' => false,
 222+ 'includelocal' => false,
211223 'args' => array(
212224 ApiBase::PARAM_ISMULTI => true,
213225 ApiBase::PARAM_ALLOW_DUPLICATES => true,
@@ -235,6 +247,9 @@
236248 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
237249 'Will substitute magic words, handle templates etc.' ),
238250 'nocontent' => 'If set, do not include the content of the messages in the output.',
 251+ 'includelocal' => array( "Also include local messages, i.e. messages that don't exist in the software but do exist as a MediaWiki: page.",
 252+ "This lists all MediaWiki: pages, so it will also list those that aren't 'really' messages such as Common.js",
 253+ ),
239254 'title' => 'Page name to use as context when parsing message (for enableparser option)',
240255 'args' => 'Arguments to be substituted into message',
241256 'prefix' => 'Return messages with this prefix',
Index: trunk/phase3/includes/cache/MessageCache.php
@@ -961,4 +961,25 @@
962962 return array_keys( $list );
963963 }
964964
 965+ /**
 966+ * Get all message keys stored in the message cache for a given language.
 967+ * If $code is the content language code, this will return all message keys
 968+ * for which MediaWiki:msgkey exists. If $code is another language code, this
 969+ * will ONLY return message keys for which MediaWiki:msgkey/$code exists.
 970+ * @param $code string
 971+ * @return array of message keys (strings)
 972+ */
 973+ public function getAllMessageKeys( $code ) {
 974+ global $wgContLang;
 975+ $this->load( $code );
 976+ if ( !isset( $this->mCache[$code] ) ) {
 977+ // Apparently load() failed
 978+ return null;
 979+ }
 980+ $cache = $this->mCache[$code]; // Copy the cache
 981+ unset( $cache['VERSION'] ); // Remove the VERSION key
 982+ $cache = array_diff( $cache, array( '!NONEXISTENT' ) ); // Remove any !NONEXISTENT keys
 983+ // Keys may appear with a capital first letter. lcfirst them.
 984+ return array_map( array( $wgContLang, 'lcfirst' ), array_keys( $cache ) );
 985+ }
965986 }

Sign-offs

UserFlagDate
Nikerabbitinspected05:17, 15 September 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r97173Merged revisions 97087,97091-97092,97094,97096-97098,97100-97101,97103,97136,...dantman16:19, 15 September 2011

Status & tagging log