r95970 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95969‎ | r95970 | r95971 >
Date:12:19, 1 September 2011
Author:catrope
Status:resolved
Tags:
Comment:
RL2: Rename getTitleMsg() to getTitleMessageKey(), and introduce getTitleMessage() which returns the contents of the title message or the name of the gadget if the message doesn't exist. Did a similar thing for getDescriptionMsg()
Modified paths:
  • /branches/RL2/extensions/Gadgets/GadgetHooks.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/Gadget.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/GadgetHooks.php
@@ -207,7 +207,7 @@
208208 $category = $gadget->getCategory();
209209
210210 // Add the Gadget to the right category
211 - $description = wfMessage( $gadget->getDescriptionMsg() )->parse();
 211+ $description = $gadget->getDescriptionMessage();
212212 $categories[$category][$description] = $name;
213213 // Add the Gadget to the default list if enabled
214214 if ( $gadget->isEnabledForUser( $user ) ) {
Index: branches/RL2/extensions/Gadgets/backend/Gadget.php
@@ -111,23 +111,59 @@
112112 }
113113
114114 /**
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.
117117 * @return string Message key
118118 */
119 - public function getTitleMsg() {
 119+ public function getTitleMessageKey() {
120120 return "gadget-{$this->name}-title";
121121 }
122122
123123 /**
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.
125144 * @return string Message key
126145 */
127 - public function getDescriptionMsg() {
 146+ public function getDescriptionMessageKey() {
128147 return "gadget-{$this->name}-desc";
129148 }
130149
131150 /**
 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+ /**
132168 * Get the name of the category this gadget is in.
133169 * @return string Category key or empty string if not in any category
134170 */
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php
@@ -90,10 +90,10 @@
9191 $row['definitiontimestamp'] = wfTimestamp( TS_ISO_8601, $g->getTimestamp() );
9292 }
9393 if ( isset( $this->props['desc'] ) ) {
94 - $row['desc'] = wfMessage( $g->getDescriptionMsg() )->parse();
 94+ $row['desc'] = $g->getDescriptionMessage();
9595 }
9696 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();
9898 }
9999 if ( isset( $this->props['category'] ) ) {
100100 $row['category'] = $g->getCategory();

Follow-up revisions

RevisionCommit summaryAuthorDate
r95972RL2: Fix stupid mistake in r95970 that broke translated titles and descriptionscatrope12:41, 1 September 2011
r95973Followup r95970, r95972: fix translations for real this time. Calling Message...catrope12:48, 1 September 2011
r96309[ResourceLoader2] Gadget manager (start of ajax editor)...krinkle22:28, 5 September 2011

Status & tagging log