| Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php |
| — | — | @@ -33,6 +33,7 @@ |
| 34 | 34 | $this->neededNames = isset( $params['names'] ) |
| 35 | 35 | ? array_flip( $params['names'] ) |
| 36 | 36 | : false; |
| | 37 | + $this->language = $params['language']; |
| 37 | 38 | |
| 38 | 39 | $this->getMain()->setCacheMode( 'public' ); |
| 39 | 40 | |
| — | — | @@ -58,13 +59,19 @@ |
| 59 | 60 | if ( isset( $this->props['name'] ) ) { |
| 60 | 61 | $row['name'] = $category; |
| 61 | 62 | } |
| 62 | | - if ( $category !== "" ) { |
| 63 | | - if ( isset( $this->props['desc'] ) ) { |
| 64 | | - // TODO: Put message into the repo too, with fallback behavior |
| 65 | | - $row['desc'] = wfMessage( "gadgetcategory-$category" )->parse(); |
| | 63 | + if ( isset( $this->props['title'] ) ) { |
| | 64 | + // TODO: Put all this logic in the repo class |
| | 65 | + $message = $category === '' ? 'gadgetmanager-uncategorized' : "gadgetcategory-$category"; |
| | 66 | + $message = wfMessage( $message ); |
| | 67 | + if ( $this->language !== null ) { |
| | 68 | + $message = $message->inLanguage( $this->language ); |
| 66 | 69 | } |
| 67 | | - if ( isset( $this->props['desc-raw'] ) ) { |
| 68 | | - $row['desc-raw'] = wfMessage( "gadgetcategory-$category" )->plain(); |
| | 70 | + if ( !$message->exists() ) { |
| | 71 | + global $wgLang; |
| | 72 | + $lang = $this->language === null ? $wgLang : Language::factory( $lang ); |
| | 73 | + $row['title'] = $lang->ucfirst( $category ); |
| | 74 | + } else { |
| | 75 | + $row['title'] = $message->plain(); |
| 69 | 76 | } |
| 70 | 77 | } |
| 71 | 78 | if ( isset( $this->props['members'] ) ) { |
| — | — | @@ -84,8 +91,7 @@ |
| 85 | 92 | ApiBase::PARAM_ISMULTI => true, |
| 86 | 93 | ApiBase::PARAM_TYPE => array( |
| 87 | 94 | 'name', |
| 88 | | - 'desc', |
| 89 | | - 'desc-raw', |
| | 95 | + 'title', |
| 90 | 96 | 'members', |
| 91 | 97 | ), |
| 92 | 98 | ), |
| — | — | @@ -93,6 +99,7 @@ |
| 94 | 100 | ApiBase::PARAM_TYPE => 'string', |
| 95 | 101 | ApiBase::PARAM_ISMULTI => true, |
| 96 | 102 | ), |
| | 103 | + 'language' => null, |
| 97 | 104 | ); |
| 98 | 105 | } |
| 99 | 106 | |
| — | — | @@ -101,15 +108,16 @@ |
| 102 | 109 | } |
| 103 | 110 | |
| 104 | 111 | public function getParamDescription() { |
| | 112 | + $p = $this->getModulePrefix(); |
| 105 | 113 | return array( |
| 106 | 114 | 'prop' => array( |
| 107 | 115 | 'What gadget category information to get:', |
| 108 | 116 | ' name - Internal category name', |
| 109 | | - ' desc - Category description transformed into HTML (can be slow, use only if really needed)', |
| 110 | | - ' desc-raw - Category description in raw wikitext', |
| | 117 | + ' title - Category title, translated in the given language', |
| 111 | 118 | ' members - Number of gadgets in category', |
| 112 | 119 | ), |
| 113 | 120 | 'names' => 'Name(s) of gadgets to retrieve', |
| | 121 | + 'language' => "Language to use for {$p}prop=title", |
| 114 | 122 | ); |
| 115 | 123 | } |
| 116 | 124 | |