From 6e4a46c315eff8b2dd3b03033ab9988b223c4c41 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 18 Oct 2013 10:54:58 -0400 Subject: [PATCH] Add $wgSemiprotectedRestrictionLevels 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 | 14 ++++++++++++++ includes/Title.php | 36 ++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index cc694a346d..6b76b038d7 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/Title.php b/includes/Title.php index 0d11821d84..21872e45b6 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 ); } /** -- 2.20.1