From e6f7965b7f78a63ac4290aec22779c394f6d0217 Mon Sep 17 00:00:00 2001 From: Rotem Liss Date: Wed, 23 Aug 2006 13:24:16 +0000 Subject: [PATCH] Check the permissions of the special page lists in the SpecialPage class, and use separated functions to get the regular and the restricted special pages, instead of using one function and a complex array. --- includes/Skin.php | 18 ++++-------------- includes/SpecialPage.php | 32 +++++++++++++++++++++++++++----- includes/SpecialSpecialpages.php | 13 ++----------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index 69804dced0..ce7f1986ee 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1078,24 +1078,14 @@ END; /** * show a drop-down box of special pages - * @TODO crash bug913. Need to be rewrote completly. */ function specialPagesList() { global $wgUser, $wgContLang, $wgServer, $wgRedirectScript; require_once('SpecialPage.php'); $a = array(); - $pages = SpecialPage::getPages(); - - // special pages without access restriction - foreach ( $pages[''] as $name => $page ) { - $a[$name] = $page->getDescription(); - } - - // Other special pages that are restricted. - foreach ( $pages['restricted'] as $name => $page ) { - if( $wgUser->isAllowed( $page->getRestriction() ) ) { - $a[$name] = $page->getDescription(); - } + $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() ); + foreach ( $pages as $name => $page ) { + $pages[$name] = $page->getDescription(); } $go = wfMsg( 'go' ); @@ -1108,7 +1098,7 @@ END; $s .= "\n"; - foreach ( $a as $name => $desc ) { + foreach ( $pages as $name => $desc ) { $p = $wgContLang->specialPage( $name ); $s .= "\n"; } diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index b5ba9d78eb..294c05ef6f 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -279,11 +279,31 @@ class SpecialPage } /** - * Return categorised listable special pages - * Returns a 2d array where the first index is the restriction name + * Return categorised listable special pages for all users * @static */ - static function getPages() { + static function getRegularPages() { + if ( !self::$mListInitialised ) { + self::initList(); + } + $pages = array(); + + foreach ( self::$mList as $name => $rec ) { + $page = self::getPage( $name ); + if ( $page->isListed() && $page->getRestriction() == '' ) { + $pages[$name] = $page; + } + } + return $pages; + } + + /** + * Return categorised listable special pages which are available + * for the current user, but not for everyone + * @static + */ + static function getRestrictedPages() { + global $wgUser; if ( !self::$mListInitialised ) { self::initList(); } @@ -292,8 +312,10 @@ class SpecialPage foreach ( self::$mList as $name => $rec ) { $page = self::getPage( $name ); if ( $page->isListed() ) { - $restricted = $page->getRestriction() == '' ? '' : 'restricted'; - $pages[$restricted][$page->getName()] = $page; + $restriction = $page->getRestriction(); + if ( $restriction != '' && $wgUser->isAllowed( $restriction ) ) { + $pages[$name] = $page; + } } } return $pages; diff --git a/includes/SpecialSpecialpages.php b/includes/SpecialSpecialpages.php index ea7cedae2e..6a01cd0829 100644 --- a/includes/SpecialSpecialpages.php +++ b/includes/SpecialSpecialpages.php @@ -14,20 +14,11 @@ function wfSpecialSpecialpages() { $wgOut->setRobotpolicy( 'index,nofollow' ); $sk = $wgUser->getSkin(); - # Get listable pages, in a 2-d array with the first dimension being user right - $pages = SpecialPage::getPages(); - /** Pages available to all */ - wfSpecialSpecialpages_gen($pages[''],'spheading',$sk); + wfSpecialSpecialpages_gen( SpecialPage::getRegularPages(), 'spheading', $sk ); /** Restricted special pages */ - $rpages = array(); - foreach ( $pages['restricted'] as $name => $page ) { - if( $wgUser->isAllowed( $page->getRestriction() ) ) { - $rpages[$name] = $page; - } - } - wfSpecialSpecialpages_gen( $rpages, 'restrictedpheading', $sk ); + wfSpecialSpecialpages_gen( SpecialPage::getRestrictedPages(), 'restrictedpheading', $sk ); } /** -- 2.20.1