From 308f7c6895187d9ab7c8cc144f4a3307ef15d5e2 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 17 Oct 2011 14:33:04 +0000 Subject: [PATCH] Added a User parameter to SpecialPageFactory::getUsablePages() so that it does not need to depend on $wgUser; updated the only call to it --- includes/SpecialPage.php | 6 ++++-- includes/SpecialPageFactory.php | 11 ++++++++--- includes/specials/SpecialSpecialpages.php | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index fca8c060d5..7548200baa 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -189,11 +189,13 @@ class SpecialPage { * Return categorised listable special pages which are available * for the current user, and everyone. * + * @param $user User object to check permissions, $wgUser will be used + * if not provided * @return Associative array mapping page's name to its SpecialPage object * @deprecated since 1.18 call SpecialPageFactory method directly */ - static function getUsablePages() { - return SpecialPageFactory::getUsablePages(); + static function getUsablePages( User $user = null ) { + return SpecialPageFactory::getUsablePages( $user ); } /** diff --git a/includes/SpecialPageFactory.php b/includes/SpecialPageFactory.php index 22aaa753e5..27cdc3eb35 100644 --- a/includes/SpecialPageFactory.php +++ b/includes/SpecialPageFactory.php @@ -339,16 +339,21 @@ class SpecialPageFactory { * Return categorised listable special pages which are available * for the current user, and everyone. * + * @param $user User object to check permissions, $wgUser will be used + * if not provided * @return Array( String => Specialpage ) */ - public static function getUsablePages() { - global $wgUser; + public static function getUsablePages( User $user = null ) { $pages = array(); + if ( $user === null ) { + global $wgUser; + $user = $wgUser; + } foreach ( self::getList() as $name => $rec ) { $page = self::getPage( $name ); if ( $page // not null && $page->isListed() - && ( !$page->isRestricted() || $page->userCanExecute( $wgUser ) ) + && ( !$page->isRestricted() || $page->userCanExecute( $user ) ) ) { $pages[$name] = $page; } diff --git a/includes/specials/SpecialSpecialpages.php b/includes/specials/SpecialSpecialpages.php index 13bc4c2b39..e973ddc89d 100644 --- a/includes/specials/SpecialSpecialpages.php +++ b/includes/specials/SpecialSpecialpages.php @@ -51,7 +51,7 @@ class SpecialSpecialpages extends UnlistedSpecialPage { private function getPageGroups() { global $wgSortSpecialPages; - $pages = SpecialPageFactory::getUsablePages(); + $pages = SpecialPageFactory::getUsablePages( $this->getUser() ); if( !count( $pages ) ) { # Yeah, that was pointless. Thanks for coming. -- 2.20.1