From 4eed909bfdd6a0eec2132779342b09b197b1eb5f Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 14 Sep 2011 16:48:29 +0000 Subject: [PATCH] Introduce Language::getMessageKeysFor() and use it in ApiQueryAllmessages --- includes/api/ApiQueryAllmessages.php | 2 +- includes/specials/SpecialAllmessages.php | 1 + languages/Language.php | 13 ++++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index bf1137079e..d900d542de 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -65,7 +65,7 @@ class ApiQueryAllmessages extends ApiQueryBase { // Determine which messages should we print if ( in_array( '*', $params['messages'] ) ) { - $message_names = array_keys( Language::getMessagesFor( 'en' ) ); + $message_names = Language::getMessageKeysFor( $langObj->getCode() ); sort( $message_names ); $messages_target = $message_names; } else { diff --git a/includes/specials/SpecialAllmessages.php b/includes/specials/SpecialAllmessages.php index 4a8db66dc5..7b7ed42276 100644 --- a/includes/specials/SpecialAllmessages.php +++ b/includes/specials/SpecialAllmessages.php @@ -249,6 +249,7 @@ class AllmessagesTablePager extends TablePager { * @param bool $foreign Whether the $langcode is not the content language */ public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) { + // FIXME: This function should be moved to Language:: or something. wfProfileIn( __METHOD__ . '-db' ); $dbr = wfGetDB( DB_SLAVE ); diff --git a/languages/Language.php b/languages/Language.php index 15f3329d81..8723a97a6e 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3371,7 +3371,8 @@ class Language { /** * Get all messages for a given language - * WARNING: this may take a long time + * WARNING: this may take a long time. If you just need all message *keys* + * but need the *contents* of only a few messages, consider using getMessageKeysFor(). * * @param $code string * @@ -3392,6 +3393,16 @@ class Language { static function getMessageFor( $key, $code ) { return self::getLocalisationCache()->getSubitem( $code, 'messages', $key ); } + + /** + * Get all message keys for a given language. This is a faster alternative to + * array_keys( Language::getMessagesFor( $code ) ) + * @param $code string Language code + * @return array of message keys (strings) + */ + static function getMessageKeysFor( $code ) { + return self::getLocalisationCache()->getSubItemList( $code, 'messages' ); + } /** * @param $talk -- 2.20.1