From 2133770f23aef7cc7c6daada3670adad141950d1 Mon Sep 17 00:00:00 2001 From: John Du Hart Date: Tue, 15 Nov 2011 00:37:38 +0000 Subject: [PATCH] Added function to SpecialPage to simplify permissions checking in SpecialPage classes. --- includes/SpecialPage.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index a95046c5c4..7d51021677 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -510,6 +510,17 @@ class SpecialPage { 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(); + } + } + /** * Sets headers - this should be called from the execute() method of all derived classes! */ @@ -530,18 +541,15 @@ class SpecialPage { */ 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 ); } /** -- 2.20.1