Follow-up r82853: Filter out create restriction from SpecialProtectedPages and Api...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 26 Feb 2011 16:29:48 +0000 (16:29 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 26 Feb 2011 16:29:48 +0000 (16:29 +0000)
includes/Title.php
includes/api/ApiQueryAllpages.php
includes/specials/SpecialProtectedpages.php

index c6c225a..d69610f 100644 (file)
@@ -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
index b396f37..a804fd5 100644 (file)
@@ -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(
index e664c20..c676aa0 100644 (file)
@@ -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;
                }