Split out checkExecutePermissions() function from userCanExecute() in FormSpecialPage...
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 26 Oct 2011 06:22:25 +0000 (06:22 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 26 Oct 2011 06:22:25 +0000 (06:22 +0000)
includes/SpecialPage.php
includes/specials/SpecialLockdb.php
includes/specials/SpecialPasswordReset.php
includes/specials/SpecialUnlockdb.php

index 7548200..badbcf7 100644 (file)
@@ -786,7 +786,7 @@ abstract class FormSpecialPage extends SpecialPage {
                $this->setHeaders();
 
                // This will throw exceptions if there's a problem
-               $this->userCanExecute( $this->getUser() );
+               $this->checkExecutePermissions( $this->getUser() );
 
                $form = $this->getForm();
                if ( $form->show() ) {
@@ -801,20 +801,18 @@ abstract class FormSpecialPage extends SpecialPage {
        protected function setParameter( $par ){}
 
        /**
-        * Checks if the given user (identified by an object) can perform this action.  Can be
-        * overridden by sub-classes with more complicated permissions schemes.  Failures here
-        * must throw subclasses of ErrorPageError
-        *
-        * @param $user User: the user to check, or null to use the context user
+        * Called from execute() to check if the given user can perform this action.
+        * Failures here must throw subclasses of ErrorPageError.
+        * @param $user User
         * @return Bool true
         * @throws ErrorPageError
         */
-       public function userCanExecute( User $user ) {
+       protected function checkExecutePermissions( User $user ) {
                if ( $this->requiresWrite() && wfReadOnly() ) {
                        throw new ReadOnlyError();
                }
 
-               if ( $this->getRestriction() !== null && !$user->isAllowed( $this->getRestriction() ) ) {
+               if ( !$this->userCanExecute( $this->getUser() ) ) {
                        throw new PermissionsError( $this->getRestriction() );
                }
 
index 9dec018..53fddc4 100644 (file)
@@ -37,11 +37,11 @@ class SpecialLockdb extends FormSpecialPage {
                return false;
        }
 
-       public function userCanExecute( User $user ) {
-               parent::userCanExecute( $user );
+       public function checkExecutePermissions( User $user ) {
+               global $wgReadOnlyFile;
 
+               parent::checkExecutePermissions( $user );
                # If the lock file isn't writable, we can do sweet bugger all
-               global $wgReadOnlyFile;
                if ( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
                        throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' );
                }
index b07ef80..40cb956 100644 (file)
@@ -43,6 +43,10 @@ class SpecialPasswordReset extends FormSpecialPage {
        }
 
        public function userCanExecute( User $user ) {
+               return $this->canChangePassword( $user ) === true && parent::userCanExecute( $user );
+       }
+
+       public function checkExecutePermissions( User $user ) {
                $error = $this->canChangePassword( $user );
                if ( is_string( $error ) ) {
                        throw new ErrorPageError( 'internalerror', $error );
@@ -50,7 +54,7 @@ class SpecialPasswordReset extends FormSpecialPage {
                        throw new ErrorPageError( 'internalerror', 'resetpass_forbidden' );
                }
 
-               return parent::userCanExecute( $user );
+               return parent::checkExecutePermissions( $user );
        }
 
        protected function getFormFields() {
index 115e617..d3da785 100644 (file)
@@ -36,11 +36,11 @@ class SpecialUnlockdb extends FormSpecialPage {
                return false;
        }
 
-       public function userCanExecute( User $user ) {
-               parent::userCanExecute( $user );
+       public function checkExecutePermissions( User $user ) {
+               global $wgReadOnlyFile;
 
+               parent::checkExecutePermissions( $user );
                # If the lock file isn't writable, we can do sweet bugger all
-               global $wgReadOnlyFile;
                if ( !file_exists( $wgReadOnlyFile ) ) {
                        throw new ErrorPageError( 'lockdb', 'databasenotlocked' );
                }