throw new PermissionsError( $this->mRestriction );
}
+ /**
+ * Checks if userCanExecute, and if not throws a PermissionsError
+ *
+ * @since 1.19
+ */
+ public function checkPermissions() {
+ if ( !$this->userCanExecute( $this->getUser() ) ) {
+ $this->displayRestrictionError();
+ }
+ }
+
+ /**
+ * If the wiki is currently in readonly mode, throws a ReadOnlyError
+ *
+ * @since 1.19
+ * @throws ReadOnlyError
+ */
+ public function checkReadOnly() {
+ if ( wfReadOnly() ) {
+ throw new ReadOnlyError;
+ }
+ }
+
/**
* Sets headers - this should be called from the execute() method of all derived classes!
*/
*/
function execute( $par ) {
$this->setHeaders();
+ $this->checkPermissions();
- if ( $this->userCanExecute( $this->getUser() ) ) {
- $func = $this->mFunction;
- // only load file if the function does not exist
- if( !is_callable($func) && $this->mFile ) {
- require_once( $this->mFile );
- }
- $this->outputHeader();
- call_user_func( $func, $par, $this );
- } else {
- $this->displayRestrictionError();
+ $func = $this->mFunction;
+ // only load file if the function does not exist
+ if( !is_callable($func) && $this->mFile ) {
+ require_once( $this->mFile );
}
+ $this->outputHeader();
+ call_user_func( $func, $par, $this );
}
/**
$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() ) {
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 ) {
- if ( $this->requiresWrite() && wfReadOnly() ) {
- throw new ReadOnlyError();
- }
-
- if ( $this->getRestriction() !== null && !$user->isAllowed( $this->getRestriction() ) ) {
- throw new PermissionsError( $this->getRestriction() );
- }
+ protected function checkExecutePermissions( User $user ) {
+ $this->checkPermissions();
if ( $this->requiresUnblock() && $user->isBlocked() ) {
$block = $user->mBlock;
throw new UserBlockedError( $block );
}
+ if ( $this->requiresWrite() ) {
+ $this->checkReadOnly();
+ }
+
return true;
}
}
/**
- * ListAdmins --> ListUsers/admin
+ * ListAdmins --> ListUsers/sysop
*/
class SpecialListAdmins extends SpecialRedirectToSpecial {
function __construct(){
- parent::__construct( 'ListAdmins', 'ListUsers', 'sysop' );
+ parent::__construct( 'Listadmins', 'Listusers', 'sysop' );
}
}
/**
- * ListBots --> ListUsers/admin
+ * ListBots --> ListUsers/bot
*/
class SpecialListBots extends SpecialRedirectToSpecial {
function __construct(){
- parent::__construct( 'ListAdmins', 'ListUsers', 'bot' );
+ parent::__construct( 'Listbots', 'Listusers', 'bot' );
}
}
function getRedirect( $subpage ) {
$subpage = intval( $subpage );
+ if( $subpage === 0 ) {
+ # throw an error page when no subpage was given
+ throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
+ }
$this->mAddedRedirectParams['oldid'] = $subpage;
return true;
}