Add $wgSemiprotectedRestrictionLevels
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 18 Oct 2013 14:54:58 +0000 (10:54 -0400)
committerTim Starling <tstarling@wikimedia.org>
Wed, 23 Oct 2013 23:19:25 +0000 (23:19 +0000)
It's possible that a wiki could introduce new protection levels that
should be considered "semiprotected". For example, if an
"emailconfirmed" protection level were added and an appropriate entry
were made in $wgAutopromote, that might be considered semi-protection
since anyone can automatically gain the ability to edit those pages
merely by setting and confirming their email address.

The most straightforward way to take care of this is to add a config
variable to specify which protection levels are considered
"semiprotected". So let's do that.

Also, let's take the opportunity to make
$title->isSemiProtected( 'create' ) works correctly.

Bug: 43462
Change-Id: Ic9db6ff6cbd84bd9734be09efbea5a5891197fa0

includes/DefaultSettings.php
includes/Title.php

index cc694a3..6b76b03 100644 (file)
@@ -4365,6 +4365,20 @@ $wgRestrictionLevels = array( '', 'autoconfirmed', 'sysop' );
  */
 $wgCascadingRestrictionLevels = array( 'sysop' );
 
+/**
+ * Restriction levels that should be considered "semiprotected"
+ *
+ * Certain places in the interface recognize a dichotomy between "protected"
+ * and "semiprotected", without further distinguishing the specific levels. In
+ * general, if anyone can be eligible to edit a protection level merely by
+ * reaching some condition in $wgAutopromote, it should probably be considered
+ * "semiprotected".
+ *
+ * 'autoconfirmed' is quietly rewritten to 'editsemiprotected' for backwards compatibility.
+ * 'sysop' is not changed, since it really shouldn't be here.
+ */
+$wgSemiprotectedRestrictionLevels = array( 'autoconfirmed' );
+
 /**
  * Set the minimum permissions required to edit pages in each
  * namespace.  If you list more than one permission, a user must
index 0d11821..21872e4 100644 (file)
@@ -2458,31 +2458,31 @@ class Title {
        }
 
        /**
-        * Is this page "semi-protected" - the *only* protection is autoconfirm?
+        * Is this page "semi-protected" - the *only* protection levels are listed
+        * in $wgSemiprotectedRestrictionLevels?
         *
         * @param string $action Action to check (default: edit)
         * @return Bool
         */
        public function isSemiProtected( $action = 'edit' ) {
-               if ( $this->exists() ) {
-                       $restrictions = $this->getRestrictions( $action );
-                       if ( count( $restrictions ) > 0 ) {
-                               foreach ( $restrictions as $restriction ) {
-                                       if ( strtolower( $restriction ) != 'editsemiprotected' &&
-                                               strtolower( $restriction ) != 'autoconfirmed' // BC
-                                       ) {
-                                               return false;
-                                       }
-                               }
-                       } else {
-                               # Not protected
-                               return false;
-                       }
-                       return true;
-               } else {
-                       # If it doesn't exist, it can't be protected
+               global $wgSemiprotectedRestrictionLevels;
+
+               $restrictions = $this->getRestrictions( $action );
+               $semi = $wgSemiprotectedRestrictionLevels;
+               if ( !$restrictions || !$semi ) {
+                       // Not protected, or all protection is full protection
                        return false;
                }
+
+               // Remap autoconfirmed to editsemiprotected for BC
+               foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
+                       $semi[$key] = 'editsemiprotected';
+               }
+               foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
+                       $restrictions[$key] = 'editsemiprotected';
+               }
+
+               return !array_diff( $restrictions, $semi );
        }
 
        /**