Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
— | — | @@ -219,7 +219,7 @@ |
220 | 220 | $options = array(); // array( desc1 => gadget1, category1 => array( desc2 => gadget2 ) ) |
221 | 221 | foreach ( $categories as $category => $gadgets ) { |
222 | 222 | if ( $category !== '' ) { |
223 | | - $categoryMsg = wfMsgExt( "gadgetcategory-$category", 'parseinline' ); |
| 223 | + $categoryMsg = htmlspecialchars( GadgetRepo::getCategoryTitle( $category ) ); |
224 | 224 | $options[$categoryMsg] = $gadgets; |
225 | 225 | } else { |
226 | 226 | $options += $gadgets; |
Index: branches/RL2/extensions/Gadgets/backend/GadgetRepo.php |
— | — | @@ -12,6 +12,8 @@ |
13 | 13 | // TODO: Common config stuff for all repos? |
14 | 14 | } |
15 | 15 | |
| 16 | + /**** Abstract functions ****/ |
| 17 | + |
16 | 18 | /** |
17 | 19 | * Get the name of the ResourceLoader source of the modules |
18 | 20 | * returned by this repository. |
— | — | @@ -74,5 +76,29 @@ |
75 | 77 | */ |
76 | 78 | abstract public function deleteGadget( $id ); |
77 | 79 | |
78 | | - // TODO: cache purging |
| 80 | + /**** Public functions ****/ |
| 81 | + |
| 82 | + /** |
| 83 | + * Get the localized title for a given category in a given language. |
| 84 | + * |
| 85 | + * The "gadgetcategory-$category" message is used, if it exists. |
| 86 | + * If it doesn't exist, ucfirst( $category ) is returned. |
| 87 | + * |
| 88 | + * @param $category string Category ID |
| 89 | + * @param $lang string Language code. If null, $wgLang is used |
| 90 | + * @return string Localized category title |
| 91 | + */ |
| 92 | + public static function getCategoryTitle( $category, $lang = null ) { |
| 93 | + $msg = wfMessage( "gadgetcategory-$category" ); |
| 94 | + if ( $lang !== null ) { |
| 95 | + $msg = $msg->inLanguage( $lang ); |
| 96 | + } |
| 97 | + if ( !$msg->exists() ) { |
| 98 | + global $wgLang; |
| 99 | + $langObj = $lang === null ? $wgLang : Language::factory( $lang ); |
| 100 | + return $lang->ucfirst( $category ); |
| 101 | + } |
| 102 | + return $msg->plain(); |
| 103 | + } |
| 104 | + |
79 | 105 | } |
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php |
— | — | @@ -60,18 +60,10 @@ |
61 | 61 | $row['name'] = $category; |
62 | 62 | } |
63 | 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 ); |
69 | | - } |
70 | | - if ( !$message->exists() ) { |
71 | | - global $wgLang; |
72 | | - $lang = $this->language === null ? $wgLang : Language::factory( $this->language ); |
73 | | - $row['title'] = $lang->ucfirst( $category ); |
| 64 | + if ( $category === '' ) { |
| 65 | + $row['title'] = wfMessage( 'gadgetmanager-uncategorized' )->plain(); |
74 | 66 | } else { |
75 | | - $row['title'] = $message->plain(); |
| 67 | + $row['title'] = GadgetRepo::getCategoryTitle( $category, $this->language ); |
76 | 68 | } |
77 | 69 | } |
78 | 70 | if ( isset( $this->props['members'] ) ) { |
Index: branches/RL2/extensions/Gadgets/SpecialGadgetManager.php |
— | — | @@ -75,15 +75,15 @@ |
76 | 76 | // Avoid broken or empty headings. Fallback to a special message |
77 | 77 | // for uncategorized gadgets (e.g. gadgets with category '' ). |
78 | 78 | if ( $category !== '' ) { |
79 | | - $categoryMsg = wfMessage( "gadgetcategory-$category" ); |
| 79 | + $categoryTitle = GadgetRepo::getCategoryTitle( $category ); |
80 | 80 | } else { |
81 | | - $categoryMsg = wfMessage( 'gadgetmanager-uncategorized' ); |
| 81 | + $categoryTitle = wfMessage( 'gadgetmanager-uncategorized' )->plain(); |
82 | 82 | } |
83 | 83 | |
84 | 84 | // Category header |
85 | 85 | $html .= Html::element( 'h2', |
86 | 86 | array( 'class' => 'mw-gadgetmanager-category' ), |
87 | | - $categoryMsg->exists() ? $categoryMsg->plain() : $this->getLang()->ucfirst( $category ) |
| 87 | + $categoryTitle |
88 | 88 | ); |
89 | 89 | |
90 | 90 | // Start per-category gadgets table |