(bug 32412) TOC links on [[Special:EditWatchlist]] now points to the fieldset
[lhc/web/wiklou.git] / includes / Action.php
index 9958be9..fd4a0a6 100644 (file)
@@ -23,7 +23,7 @@
  *
  * @file
  */
-abstract class Action {
+abstract class Action extends ContextSource {
 
        /**
         * Page on which we're performing the action
@@ -95,81 +95,6 @@ abstract class Action {
                return self::getClass( $name, array() ) !== null;
        }
 
-       /**
-        * Get the IContextSource in use here
-        * @return IContextSource
-        */
-       public final function getContext() {
-               if ( $this->context instanceof IContextSource ) {
-                       return $this->context;
-               }
-               return $this->page->getContext();
-       }
-
-       /**
-        * Get the WebRequest being used for this instance
-        *
-        * @return WebRequest
-        */
-       public final function getRequest() {
-               return $this->getContext()->getRequest();
-       }
-
-       /**
-        * Get the OutputPage being used for this instance
-        *
-        * @return OutputPage
-        */
-       public final function getOutput() {
-               return $this->getContext()->getOutput();
-       }
-
-       /**
-        * Shortcut to get the User being used for this instance
-        *
-        * @return User
-        */
-       public final function getUser() {
-               return $this->getContext()->getUser();
-       }
-
-       /**
-        * Shortcut to get the Skin being used for this instance
-        *
-        * @return Skin
-        */
-       public final function getSkin() {
-               return $this->getContext()->getSkin();
-       }
-
-       /**
-        * Shortcut to get the user Language being used for this instance
-        *
-        * @return Skin
-        */
-       public final function getLang() {
-               return $this->getContext()->getLang();
-       }
-
-       /**
-        * Shortcut to get the Title object from the page
-        * @return Title
-        */
-       public final function getTitle() {
-               return $this->page->getTitle();
-       }
-
-       /**
-        * Get a Message object with context set
-        * Parameters are the same as wfMessage()
-        *
-        * @return Message object
-        */
-       public final function msg() {
-               $params = func_get_args();
-               return call_user_func_array( array( $this->getContext(), 'msg' ), $params );
-       }
-
        /**
         * Protected constructor: use Action::factory( $action, $page ) to actually build
         * these things in the real world
@@ -200,18 +125,25 @@ abstract class Action {
         * @throws ErrorPageError
         */
        protected function checkCanExecute( User $user ) {
-               if ( $this->requiresWrite() && wfReadOnly() ) {
-                       throw new ReadOnlyError();
-               }
-
-               if ( $this->getRestriction() !== null && !$user->isAllowed( $this->getRestriction() ) ) {
-                       throw new PermissionsError( $this->getRestriction() );
+               $right = $this->getRestriction();
+               if ( $right !== null ) {
+                       $errors = $this->getTitle()->getUserPermissionsErrors( $right, $user );
+                       if ( count( $errors ) ) {
+                               throw new PermissionsError( $right, $errors );
+                       }
                }
 
                if ( $this->requiresUnblock() && $user->isBlocked() ) {
                        $block = $user->mBlock;
                        throw new UserBlockedError( $block );
                }
+
+               // This should be checked at the end so that the user won't think the
+               // error is only temporary when he also don't have the rights to execute
+               // this action
+               if ( $this->requiresWrite() && wfReadOnly() ) {
+                       throw new ReadOnlyError();
+               }
        }
 
        /**
@@ -290,6 +222,10 @@ abstract class FormAction extends Action {
         * @return String HTML which will be sent to $form->addPreText()
         */
        protected function preText() { return ''; }
+
+       /**
+        * @return string
+        */
        protected function postText() { return ''; }
 
        /**