Merge "Make tableNamesWithUseIndexOrJOIN() and makeUpdateOptions() protected"
[lhc/web/wiklou.git] / includes / ProtectionForm.php
index 94ebc61..d6cc8a3 100644 (file)
@@ -83,8 +83,8 @@ class ProtectionForm {
         */
        function loadData() {
                global $wgRequest, $wgUser;
-               global $wgRestrictionLevels;
 
+               $levels = MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace(), $wgUser );
                $this->mCascade = $this->mTitle->areRestrictionsCascading();
 
                $this->mReason = $wgRequest->getText( 'mwProtect-reason' );
@@ -132,21 +132,7 @@ class ProtectionForm {
                        }
 
                        $val = $wgRequest->getVal( "mwProtect-level-$action" );
-                       if ( isset( $val ) && in_array( $val, $wgRestrictionLevels ) ) {
-                               // Prevent users from setting levels that they cannot later unset
-                               if ( $val == 'sysop' ) {
-                                       // Special case, rewrite sysop to editprotected
-                                       if ( !$wgUser->isAllowed( 'editprotected' ) ) {
-                                               continue;
-                                       }
-                               } elseif ( $val == 'autoconfirmed' ) {
-                                       // Special case, rewrite autoconfirmed to editsemiprotected
-                                       if ( !$wgUser->isAllowed( 'editsemiprotected' ) ) {
-                                               continue;
-                                       }
-                               } elseif ( !$wgUser->isAllowed( $val ) ) {
-                                       continue;
-                               }
+                       if ( isset( $val ) && in_array( $val, $levels ) ) {
                                $this->mRestrictions[$action] = $val;
                        }
                }
@@ -189,7 +175,7 @@ class ProtectionForm {
        function execute() {
                global $wgRequest, $wgOut;
 
-               if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+               if ( MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) === array( '' ) ) {
                        throw new ErrorPageError( 'protect-badnamespace-title', 'protect-badnamespace-text' );
                }
 
@@ -318,7 +304,7 @@ class ProtectionForm {
                 *             you can also return an array of message name and its parameters
                 */
                $errorMsg = '';
-               if ( !wfRunHooks( 'ProtectionForm::save', array( $this->mArticle, &$errorMsg ) ) ) {
+               if ( !wfRunHooks( 'ProtectionForm::save', array( $this->mArticle, &$errorMsg, $reasonstr ) ) ) {
                        if ( $errorMsg == '' ) {
                                $errorMsg = array( 'hookaborted' );
                        }
@@ -363,9 +349,9 @@ class ProtectionForm {
                        Xml::openElement( 'table', array( 'id' => 'mwProtectSet' ) ) .
                        Xml::openElement( 'tbody' );
 
+               // Not all languages have V_x <-> N_x relation
                foreach ( $this->mRestrictions as $action => $selected ) {
-                       /* Not all languages have V_x <-> N_x relation */
-                       // Give grep a chance to find the usages:
+                       // Messages:
                        // restriction-edit, restriction-move, restriction-create, restriction-upload
                        $msg = wfMessage( 'restriction-' . $action );
                        $out .= "<tr><td>" .
@@ -556,28 +542,13 @@ class ProtectionForm {
         * @return String: HTML fragment
         */
        function buildSelector( $action, $selected ) {
-               global $wgRestrictionLevels, $wgUser;
-
-               $levels = array();
-               foreach ( $wgRestrictionLevels as $key ) {
-                       //don't let them choose levels above their own (aka so they can still unprotect and edit the page). but only when the form isn't disabled
-                       if ( $key == 'sysop' ) {
-                               //special case, rewrite sysop to editprotected
-                               if ( !$wgUser->isAllowed( 'editprotected' ) && !$this->disabled ) {
-                                       continue;
-                               }
-                       } elseif ( $key == 'autoconfirmed' ) {
-                               //special case, rewrite autoconfirmed to editsemiprotected
-                               if ( !$wgUser->isAllowed( 'editsemiprotected' ) && !$this->disabled ) {
-                                       continue;
-                               }
-                       } else {
-                               if ( !$wgUser->isAllowed( $key ) && !$this->disabled ) {
-                                       continue;
-                               }
-                       }
-                       $levels[] = $key;
-               }
+               global $wgUser;
+
+               // If the form is disabled, display all relevant levels. Otherwise,
+               // just show the ones this user can use.
+               $levels = MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace(),
+                       $this->disabled ? null : $wgUser
+               );
 
                $id = 'mwProtect-level-' . $action;
                $attribs = array(
@@ -605,6 +576,7 @@ class ProtectionForm {
                if ( $permission == '' ) {
                        return wfMessage( 'protect-default' )->text();
                } else {
+                       // Messages: protect-level-autoconfirmed, protect-level-sysop
                        $msg = wfMessage( "protect-level-{$permission}" );
                        if ( $msg->exists() ) {
                                return $msg->text();