r97055 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97054‎ | r97055 | r97056 >
Date:13:19, 14 September 2011
Author:catrope
Status:ok
Tags:
Comment:
RL2: Per CR on r96863, moved getCategoryTitle() to LocalGadgetRepo. Also turned it from a static method into an object method. Even though it could be static right now (it doesn't use $this), it seems more future-proof to do it this way. All current callers have a $repo object at hand, so making it non-static now doesn't break anything, and it's easier to make a non-static method static (from the callers' perspective) than to make a static method non-static.
Modified paths:
  • /branches/RL2/extensions/Gadgets/GadgetHooks.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/SpecialGadgetManager.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/GadgetRepo.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/GadgetHooks.php
@@ -226,7 +226,7 @@
227227 $options = array(); // array( desc1 => gadget1, category1 => array( desc2 => gadget2 ) )
228228 foreach ( $categories as $category => $gadgets ) {
229229 if ( $category !== '' ) {
230 - $categoryMsg = htmlspecialchars( GadgetRepo::getCategoryTitle( $category ) );
 230+ $categoryMsg = htmlspecialchars( $repo->getCategoryTitle( $category ) );
231231 $options[$categoryMsg] = $gadgets;
232232 } else {
233233 $options += $gadgets;
Index: branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php
@@ -158,7 +158,32 @@
159159 return wfGetDB( DB_SLAVE );
160160 }
161161
 162+ /*** Public methods ***/
162163
 164+ /**
 165+ * Get the localized title for a given category in a given language.
 166+ *
 167+ * The "gadgetcategory-$category" message is used, if it exists.
 168+ * If it doesn't exist, ucfirst( $category ) is returned.
 169+ *
 170+ * @param $category string Category ID
 171+ * @param $lang string Language code. If null, $wgLang is used
 172+ * @return string Localized category title
 173+ */
 174+ public function getCategoryTitle( $category, $lang = null ) {
 175+ $msg = wfMessage( "gadgetcategory-$category" );
 176+ if ( $lang !== null ) {
 177+ $msg = $msg->inLanguage( $lang );
 178+ }
 179+ if ( !$msg->exists() ) {
 180+ global $wgLang;
 181+ $langObj = $lang === null ? $wgLang : Language::factory( $lang );
 182+ return $langObj->ucfirst( $category );
 183+ }
 184+ return $msg->plain();
 185+ }
 186+
 187+
163188 /*** Protected methods ***/
164189
165190 /**
Index: branches/RL2/extensions/Gadgets/backend/GadgetRepo.php
@@ -90,29 +90,6 @@
9191 /*** Public static methods ***/
9292
9393 /**
94 - * Get the localized title for a given category in a given language.
95 - *
96 - * The "gadgetcategory-$category" message is used, if it exists.
97 - * If it doesn't exist, ucfirst( $category ) is returned.
98 - *
99 - * @param $category string Category ID
100 - * @param $lang string Language code. If null, $wgLang is used
101 - * @return string Localized category title
102 - */
103 - public static function getCategoryTitle( $category, $lang = null ) {
104 - $msg = wfMessage( "gadgetcategory-$category" );
105 - if ( $lang !== null ) {
106 - $msg = $msg->inLanguage( $lang );
107 - }
108 - if ( !$msg->exists() ) {
109 - global $wgLang;
110 - $langObj = $lang === null ? $wgLang : Language::factory( $lang );
111 - return $langObj->ucfirst( $category );
112 - }
113 - return $msg->plain();
114 - }
115 -
116 - /**
11794 * Get all gadget repositories. Returns the LocalGadgetRepo singleton and any
11895 * repositories configured in $wgGadgetRepositories
11996 * @return array of GadgetRepo objects
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php
@@ -56,7 +56,7 @@
5757 if ( $category === '' ) {
5858 $row['title'] = wfMessage( 'gadgetmanager-uncategorized' )->plain();
5959 } else {
60 - $row['title'] = GadgetRepo::getCategoryTitle( $category, $this->language );
 60+ $row['title'] = $repo->getCategoryTitle( $category, $this->language );
6161 }
6262 }
6363 if ( isset( $this->props['members'] ) ) {
Index: branches/RL2/extensions/Gadgets/SpecialGadgetManager.php
@@ -68,7 +68,7 @@
6969 // Avoid broken or empty headings. Fallback to a special message
7070 // for uncategorized gadgets (e.g. gadgets with category '' ).
7171 if ( $category !== '' ) {
72 - $categoryTitle = GadgetRepo::getCategoryTitle( $category );
 72+ $categoryTitle = $repo->getCategoryTitle( $category );
7373 } else {
7474 $categoryTitle = wfMessage( 'gadgetmanager-uncategorized' )->plain();
7575 }

Sign-offs

UserFlagDate
Nikerabbitinspected13:39, 14 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96863RL2: Move category title message logic to GadgetRepo::getCategoryTitle(). Thi...catrope16:45, 12 September 2011

Status & tagging log