Index: trunk/phase3/includes/api/ApiQueryAllmessages.php |
— | — | @@ -66,6 +66,17 @@ |
67 | 67 | // Determine which messages should we print |
68 | 68 | if ( in_array( '*', $params['messages'] ) ) { |
69 | 69 | $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 | + } |
70 | 81 | sort( $message_names ); |
71 | 82 | $messages_target = $message_names; |
72 | 83 | } else { |
— | — | @@ -207,6 +218,7 @@ |
208 | 219 | ), |
209 | 220 | 'enableparser' => false, |
210 | 221 | 'nocontent' => false, |
| 222 | + 'includelocal' => false, |
211 | 223 | 'args' => array( |
212 | 224 | ApiBase::PARAM_ISMULTI => true, |
213 | 225 | ApiBase::PARAM_ALLOW_DUPLICATES => true, |
— | — | @@ -235,6 +247,9 @@ |
236 | 248 | 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message', |
237 | 249 | 'Will substitute magic words, handle templates etc.' ), |
238 | 250 | '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 | + ), |
239 | 254 | 'title' => 'Page name to use as context when parsing message (for enableparser option)', |
240 | 255 | 'args' => 'Arguments to be substituted into message', |
241 | 256 | 'prefix' => 'Return messages with this prefix', |
Index: trunk/phase3/includes/cache/MessageCache.php |
— | — | @@ -961,4 +961,25 @@ |
962 | 962 | return array_keys( $list ); |
963 | 963 | } |
964 | 964 | |
| 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 | + } |
965 | 986 | } |