r111790 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111789‎ | r111790 | r111791 >
Date:21:23, 17 February 2012
Author:reedy
Status:ok
Tags:
Comment:
Documentation, code updates, removal of direct member variable access
Modified paths:
  • /trunk/extensions/Gadgets/ApiQueryGadgets.php (modified) (history)
  • /trunk/extensions/Gadgets/Gadgets_body.php (modified) (history)
  • /trunk/extensions/Gadgets/SpecialGadgets.php (modified) (history)
  • /trunk/extensions/GlobalBlocking/SpecialGlobalBlockStatus.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlockStatus.php
@@ -131,7 +131,7 @@
132132 $out->addWikiMsg( 'globalblocking-whitelist-dewhitelisted', $ip, $id );
133133 }
134134
135 - $link = $wgUser->getSkin()->makeKnownLinkObj( SpecialPage::getTitleFor( 'GlobalBlockList' ), wfMsg( 'globalblocking-return' ) );
 135+ $link = Linker::makeKnownLinkObj( SpecialPage::getTitleFor( 'GlobalBlockList' ), wfMsg( 'globalblocking-return' ) );
136136 $out->addHTML( $link );
137137
138138 $out->setSubtitle(wfMsg('globalblocking-whitelist-successsub'));
Index: trunk/extensions/Gadgets/Gadgets_body.php
@@ -18,10 +18,11 @@
1919 * @param $article Article
2020 * @param $user User
2121 * @param $text String: New page text
 22+ * @return bool
2223 */
2324 public static function articleSaveComplete( $article, $user, $text ) {
2425 // update cache if MediaWiki:Gadgets-definition was edited
25 - $title = $article->mTitle;
 26+ $title = $article->getTitle();
2627 if ( $title->getNamespace() == NS_MEDIAWIKI && $title->getText() == 'Gadgets-definition' ) {
2728 Gadget::loadStructuredList( $text );
2829 }
@@ -31,12 +32,18 @@
3233 /**
3334 * UserGetDefaultOptions hook handler
3435 * @param $defaultOptions Array of default preference keys and values
 36+ * @return bool
3537 */
3638 public static function userGetDefaultOptions( &$defaultOptions ) {
3739 $gadgets = Gadget::loadStructuredList();
38 - if ( !$gadgets ) return true;
 40+ if ( !$gadgets ) {
 41+ return true;
 42+ }
3943
40 - foreach ( $gadgets as $section => $thisSection ) {
 44+ /**
 45+ * @var $gadget Gadget
 46+ */
 47+ foreach ( $gadgets as $thisSection ) {
4148 foreach ( $thisSection as $gadgetId => $gadget ) {
4249 if ( $gadget->isOnByDefault() ) {
4350 $defaultOptions['gadget-' . $gadgetId] = 1;
@@ -51,10 +58,10 @@
5259 * GetPreferences hook handler.
5360 * @param $user User
5461 * @param $preferences Array: Preference descriptions
 62+ * @return bool
5563 */
5664 public static function getPreferences( $user, &$preferences ) {
5765 $gadgets = Gadget::loadStructuredList();
58 -
5966 if ( !$gadgets ) {
6067 return true;
6168 }
@@ -64,6 +71,9 @@
6572 foreach ( $gadgets as $section => $thisSection ) {
6673 $available = array();
6774
 75+ /**
 76+ * @var $gadget Gadget
 77+ */
6878 foreach ( $thisSection as $gadget ) {
6979 if ( $gadget->isAllowed( $user ) ) {
7080 $gname = $gadget->getName();
@@ -115,14 +125,17 @@
116126 /**
117127 * ResourceLoaderRegisterModules hook handler.
118128 * @param $resourceLoader ResourceLoader
 129+ * @return bool
119130 */
120131 public static function registerModules( &$resourceLoader ) {
121132 $gadgets = Gadget::loadList();
122 -
123133 if ( !$gadgets ) {
124134 return true;
125135 }
126136
 137+ /**
 138+ * @var $g Gadget
 139+ */
127140 foreach ( $gadgets as $g ) {
128141 $module = $g->getModule();
129142 if ( $module ) {
@@ -136,6 +149,7 @@
137150 /**
138151 * BeforePageDisplay hook handler.
139152 * @param $out OutputPage
 153+ * @return bool
140154 */
141155 public static function beforePageDisplay( $out ) {
142156 global $wgUser;
@@ -152,6 +166,9 @@
153167 $lb->setCaller( __METHOD__ );
154168 $pages = array();
155169
 170+ /**
 171+ * @var $gadget Gadget
 172+ */
156173 foreach ( $gadgets as $gadget ) {
157174 if ( $gadget->isEnabled( $wgUser ) && $gadget->isAllowed( $wgUser ) ) {
158175 if ( $gadget->hasModule() ) {
@@ -212,6 +229,7 @@
213230 /**
214231 * UnitTestsList hook handler
215232 * @param $files Array: List of extension test files
 233+ * @return bool
216234 */
217235 public static function unitTestsList( $files ) {
218236 $files[] = dirname( __FILE__ ) . '/Gadgets_tests.php';
@@ -244,7 +262,7 @@
245263 /**
246264 * Creates an instance of this class from definition in MediaWiki:Gadgets-definition
247265 * @param $definition String: Gadget definition
248 - * @return Mixed: Instance of Gadget class or false if $definition is invalid
 266+ * @return Gadget|bool Instance of Gadget class or false if $definition is invalid
249267 */
250268 public static function newFromDefinition( $definition ) {
251269 $m = array();
@@ -497,7 +515,7 @@
498516 }
499517
500518 $gadgets = array();
501 - foreach ( $struct as $section => $entries ) {
 519+ foreach ( $struct as $entries ) {
502520 $gadgets = array_merge( $gadgets, $entries );
503521 }
504522 wfProfileOut( __METHOD__ );
@@ -507,13 +525,19 @@
508526
509527 /**
510528 * Checks whether gadget list from cache can be used.
 529+ * @param $gadgets array
511530 * @return Boolean
512531 */
513532 private static function isValidList( $gadgets ) {
514 - if ( !is_array( $gadgets ) ) return false;
 533+ if ( !is_array( $gadgets ) ) {
 534+ return false;
 535+ }
515536 // Check if we have 1) array of gadgets 2) the gadgets are up to date
516537 // One check is enough
517 - foreach ( $gadgets as $section => $list ) {
 538+ /**
 539+ * @var $g Gadget
 540+ */
 541+ foreach ( $gadgets as $list ) {
518542 foreach ( $list as $g ) {
519543 if ( !( $g instanceof Gadget ) || $g->isOutdated() ) {
520544 return false;
@@ -574,8 +598,7 @@
575599 $m = array();
576600 if ( preg_match( '/^==+ *([^*:\s|]+?)\s*==+\s*$/', $line, $m ) ) {
577601 $section = $m[1];
578 - }
579 - else {
 602+ } else {
580603 $gadget = self::newFromDefinition( $line );
581604 if ( $gadget ) {
582605 $gadgets[$section][$gadget->getName()] = $gadget;
@@ -617,6 +640,7 @@
618641
619642 /**
620643 * Overrides the abstract function from ResourceLoaderWikiModule class
 644+ * @param $context ResourceLoaderContext
621645 * @return Array: $pages passed to __construct()
622646 */
623647 protected function getPages( ResourceLoaderContext $context ) {
Index: trunk/extensions/Gadgets/ApiQueryGadgets.php
@@ -76,6 +76,9 @@
7777 $data = array();
7878 $result = $this->getResult();
7979
 80+ /**
 81+ * @var $g Gadget
 82+ */
8083 foreach ( $gadgets as $g ) {
8184 $row = array();
8285 if ( isset( $this->props['id'] ) ) {
Index: trunk/extensions/Gadgets/SpecialGadgets.php
@@ -20,7 +20,7 @@
2121
2222 /**
2323 * Main execution function
24 - * @param $par Parameters passed to the page
 24+ * @param $par array Parameters passed to the page
2525 */
2626 function execute( $par ) {
2727 $parts = explode( '/', $par );
@@ -38,8 +38,6 @@
3939 public function showMainForm() {
4040 global $wgOut, $wgUser, $wgLang, $wgContLang;
4141
42 - $skin = $wgUser->getSkin();
43 -
4442 $this->setHeaders();
4543 $wgOut->setPagetitle( wfMsg( "gadgets-title" ) );
4644 $wgOut->addWikiMsg( 'gadgets-pagetext' );
@@ -62,7 +60,7 @@
6361 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$lang" );
6462 if ( $editInterfaceAllowed ) {
6563 $lnkTarget = $t
66 - ? $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) )
 64+ ? Linker::link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) )
6765 : htmlspecialchars( $section );
6866 $lnk = "    [$lnkTarget]";
6967 } else {
@@ -79,6 +77,9 @@
8078 $wgOut->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" );
8179 }
8280
 81+ /**
 82+ * @var $gadget Gadget
 83+ */
8384 foreach ( $entries as $gadget ) {
8485 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getName()}$lang" );
8586
@@ -88,10 +89,10 @@
8990
9091 $links = array();
9192 if ( $editInterfaceAllowed ) {
92 - $links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
 93+ $links[] = Linker::link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
9394 }
9495
95 - $links[] = $skin->link( $this->getTitle( "export/{$gadget->getName()}" ), wfMsgHtml( 'gadgets-export' ) );
 96+ $links[] = Linker::link( $this->getTitle( "export/{$gadget->getName()}" ), wfMsgHtml( 'gadgets-export' ) );
9697
9798 $ttext = wfMsgExt( "gadget-{$gadget->getName()}", $msgOpt );
9899
@@ -114,7 +115,7 @@
115116 continue;
116117 }
117118
118 - $lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) );
 119+ $lnk[] = Linker::link( $t, htmlspecialchars( $t->getText() ) );
119120 }
120121 $wgOut->addHTML( $wgLang->commaList( $lnk ) );
121122
@@ -169,6 +170,9 @@
170171 return;
171172 }
172173
 174+ /**
 175+ * @var $g Gadget
 176+ */
173177 $g = $gadgets[$gadget];
174178 $this->setHeaders();
175179 $wgOut->setPagetitle( wfMsg( "gadgets-export-title" ) );

Status & tagging log