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.

This commit is contained in:
Rotem Liss 2006-08-23 13:24:16 +00:00
parent 4a1ef1878a
commit e6f7965b7f
3 changed files with 33 additions and 30 deletions

View file

@ -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 .= "<option value=\"{$spp}\">{$sp}</option>\n";
foreach ( $a as $name => $desc ) {
foreach ( $pages as $name => $desc ) {
$p = $wgContLang->specialPage( $name );
$s .= "<option value=\"{$p}\">{$desc}</option>\n";
}

View file

@ -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;

View file

@ -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 );
}
/**