Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
— | — | @@ -207,7 +207,7 @@ |
208 | 208 | $category = $gadget->getCategory(); |
209 | 209 | |
210 | 210 | // Add the Gadget to the right category |
211 | | - $description = wfMessage( $gadget->getDescriptionMsg() )->parse(); |
| 211 | + $description = $gadget->getDescriptionMessage(); |
212 | 212 | $categories[$category][$description] = $name; |
213 | 213 | // Add the Gadget to the default list if enabled |
214 | 214 | if ( $gadget->isEnabledForUser( $user ) ) { |
Index: branches/RL2/extensions/Gadgets/backend/Gadget.php |
— | — | @@ -111,23 +111,59 @@ |
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | | - * Get the title message for this gadget. This is the interface message that controls the name of the |
116 | | - * gadget as shown to the user. |
| 115 | + * Get the key of the title message for this gadget. This is the interface message that |
| 116 | + * controls the name of the gadget as shown to the user. |
117 | 117 | * @return string Message key |
118 | 118 | */ |
119 | | - public function getTitleMsg() { |
| 119 | + public function getTitleMessageKey() { |
120 | 120 | return "gadget-{$this->name}-title"; |
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | | - * Get the description message for this gadget. |
| 124 | + * Get the title message for this gadget |
| 125 | + * @param $langcode string Language code. If null, user language is used |
| 126 | + * @return The title message in the given language, or the name of the gadget if the message doesn't exist |
| 127 | + */ |
| 128 | + public function getTitleMessage( $langcode = null ) { |
| 129 | + $msg = wfMessage( $this->getTitleMessageKey() ); |
| 130 | + if ( !$msg->exists() ) { |
| 131 | + // Fallback: return the name of the gadget |
| 132 | + $lang = Language::factory( $langcode ); |
| 133 | + return $lang->ucfirst( $this->name ); |
| 134 | + } |
| 135 | + if ( $langcode !== null ) { |
| 136 | + $msg->inLanguage( $langcode ); |
| 137 | + } |
| 138 | + return $msg->plain(); |
| 139 | + |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * Get the key of the description message for this gadget. |
125 | 144 | * @return string Message key |
126 | 145 | */ |
127 | | - public function getDescriptionMsg() { |
| 146 | + public function getDescriptionMessageKey() { |
128 | 147 | return "gadget-{$this->name}-desc"; |
129 | 148 | } |
130 | 149 | |
131 | 150 | /** |
| 151 | + * Get the description message for this gadget |
| 152 | + * @param $langcode string Language code. If null, user language is used |
| 153 | + * @return The description message HTML in the given language, or an empty string if the message doesn't exist |
| 154 | + */ |
| 155 | + public function getDescriptionMessage( $langcode = null ) { |
| 156 | + $msg = wfMessage( $this->getDescriptionMessageKey() ); |
| 157 | + if ( !$msg->exists() ) { |
| 158 | + // Fallback: return empty string |
| 159 | + return ''; |
| 160 | + } |
| 161 | + if ( $langcode !== null ) { |
| 162 | + $msg->inLanguage( $langcode ); |
| 163 | + } |
| 164 | + return $msg->parse(); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
132 | 168 | * Get the name of the category this gadget is in. |
133 | 169 | * @return string Category key or empty string if not in any category |
134 | 170 | */ |
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php |
— | — | @@ -90,10 +90,10 @@ |
91 | 91 | $row['definitiontimestamp'] = wfTimestamp( TS_ISO_8601, $g->getTimestamp() ); |
92 | 92 | } |
93 | 93 | if ( isset( $this->props['desc'] ) ) { |
94 | | - $row['desc'] = wfMessage( $g->getDescriptionMsg() )->parse(); |
| 94 | + $row['desc'] = $g->getDescriptionMessage(); |
95 | 95 | } |
96 | 96 | if ( isset( $this->props['desc-raw'] ) ) { |
97 | | - $row['desc-raw'] = $row['desc'] = wfMessage( $g->getDescriptionMsg() )->plain(); |
| 97 | + $row['desc-raw'] = $row['desc'] = wfMessage( $g->getDescriptionMessageKey() )->plain(); |
98 | 98 | } |
99 | 99 | if ( isset( $this->props['category'] ) ) { |
100 | 100 | $row['category'] = $g->getCategory(); |