r100032 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100031‎ | r100032 | r100033 >
Date:14:33, 17 October 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
Added a User parameter to SpecialPageFactory::getUsablePages() so that it does not need to depend on $wgUser; updated the only call to it
Modified paths:
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPageFactory.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSpecialpages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialPageFactory.php
@@ -339,16 +339,21 @@
340340 * Return categorised listable special pages which are available
341341 * for the current user, and everyone.
342342 *
 343+ * @param $user User object to check permissions, $wgUser will be used
 344+ * if not provided
343345 * @return Array( String => Specialpage )
344346 */
345 - public static function getUsablePages() {
346 - global $wgUser;
 347+ public static function getUsablePages( User $user = null ) {
347348 $pages = array();
 349+ if ( $user === null ) {
 350+ global $wgUser;
 351+ $user = $wgUser;
 352+ }
348353 foreach ( self::getList() as $name => $rec ) {
349354 $page = self::getPage( $name );
350355 if ( $page // not null
351356 && $page->isListed()
352 - && ( !$page->isRestricted() || $page->userCanExecute( $wgUser ) )
 357+ && ( !$page->isRestricted() || $page->userCanExecute( $user ) )
353358 ) {
354359 $pages[$name] = $page;
355360 }
Index: trunk/phase3/includes/specials/SpecialSpecialpages.php
@@ -51,7 +51,7 @@
5252 private function getPageGroups() {
5353 global $wgSortSpecialPages;
5454
55 - $pages = SpecialPageFactory::getUsablePages();
 55+ $pages = SpecialPageFactory::getUsablePages( $this->getUser() );
5656
5757 if( !count( $pages ) ) {
5858 # Yeah, that was pointless. Thanks for coming.
Index: trunk/phase3/includes/SpecialPage.php
@@ -189,11 +189,13 @@
190190 * Return categorised listable special pages which are available
191191 * for the current user, and everyone.
192192 *
 193+ * @param $user User object to check permissions, $wgUser will be used
 194+ * if not provided
193195 * @return Associative array mapping page's name to its SpecialPage object
194196 * @deprecated since 1.18 call SpecialPageFactory method directly
195197 */
196 - static function getUsablePages() {
197 - return SpecialPageFactory::getUsablePages();
 198+ static function getUsablePages( User $user = null ) {
 199+ return SpecialPageFactory::getUsablePages( $user );
198200 }
199201
200202 /**

Comments

#Comment by 😂 (talk | contribs)   21:25, 28 November 2011

I don't see any users in extensions either, I'd just require the user parameter and remove the $wgUser fallback.

#Comment by Hashar (talk | contribs)   09:48, 12 December 2011

Maybe a null user object should be considered just like an anonymous user?

Status & tagging log