Added function to SpecialPage to simplify permissions checking in SpecialPage classes.
authorJohn Du Hart <johnduhart@users.mediawiki.org>
Tue, 15 Nov 2011 00:37:38 +0000 (00:37 +0000)
committerJohn Du Hart <johnduhart@users.mediawiki.org>
Tue, 15 Nov 2011 00:37:38 +0000 (00:37 +0000)
includes/SpecialPage.php

index a95046c..7d51021 100644 (file)
@@ -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 );
        }
 
        /**