From 48b63f4bb092cc244a65c8fea388a5fef5a1be2c Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 26 Feb 2011 16:29:48 +0000 Subject: [PATCH] Follow-up r82853: Filter out create restriction from SpecialProtectedPages and Api. Added Title::getFilteredRestrictionTypes() for this purpose. --- includes/Title.php | 27 +++++++++++++++------ includes/api/ApiQueryAllpages.php | 4 +-- includes/specials/SpecialProtectedpages.php | 4 +-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index c6c225ab21..d69610f4f4 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4116,14 +4116,8 @@ class Title { * @return array applicable restriction types */ public function getRestrictionTypes() { - global $wgRestrictionTypes; - - $types = $wgRestrictionTypes; + $types = self::getFilteredRestrictionTypes( $this->exists() ); - if ( !$this->exists() ) { - # Only the create and upload types are applicable for non-existing titles - $types = array_intersect( $types, array( 'create', 'upload' ) ); - } if ( $this->getNamespace() != NS_FILE ) { # Remove the upload restriction for non-file titles $types = array_diff( $types, array( 'upload' ) ); @@ -4136,6 +4130,25 @@ class Title { return $types; } + /** + * Get a filtered list of all restriction types supported by this wiki. + * @param bool $exists True to get all restriction types that apply to + * titles that do exist, False for all restriction types that apply to + * titles that do not exist + * @return array + */ + public static function getFilteredRestrictionTypes( $exists = true ) { + global $wgRestrictionTypes; + $types = $wgRestrictionTypes; + if ( $exists ) { + # Remove the create restriction for existing titles + $types = array_diff( $types, array( 'create' ) ); + } else { + # Only the create and upload restrictions apply to non-existing titles + $types = array_intersect( $types, array( 'create', 'upload' ) ); + } + return $types; + } /** * Returns the raw sort key to be used for categories, with the specified diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index b396f37e87..a804fd5812 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -195,7 +195,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } public function getAllowedParams() { - global $wgRestrictionTypes, $wgRestrictionLevels; + global $wgRestrictionLevels; return array( 'from' => null, @@ -220,7 +220,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { ApiBase::PARAM_TYPE => 'integer', ), 'prtype' => array( - ApiBase::PARAM_TYPE => $wgRestrictionTypes, + ApiBase::PARAM_TYPE => Title::getFilteredRestrictionTypes( true ), ApiBase::PARAM_ISMULTI => true ), 'prlevel' => array( diff --git a/includes/specials/SpecialProtectedpages.php b/includes/specials/SpecialProtectedpages.php index e664c20d48..c676aa001d 100644 --- a/includes/specials/SpecialProtectedpages.php +++ b/includes/specials/SpecialProtectedpages.php @@ -224,13 +224,11 @@ class SpecialProtectedpages extends SpecialPage { * @return string Formatted HTML */ protected function getTypeMenu( $pr_type ) { - global $wgRestrictionTypes; - $m = array(); // Temporary array $options = array(); // First pass to load the log names - foreach( $wgRestrictionTypes as $type ) { + foreach( Title::getFilteredRestrictionTypes( true ) as $type ) { $text = wfMsg("restriction-$type"); $m[$text] = $type; } -- 2.20.1