* Use local context to get messages
[lhc/web/wiklou.git] / includes / Action.php
index d81d2fe..84c0f80 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+/**
+ * @defgroup Actions Action done on pages
+ */
+
 /**
  * Actions are things which can be done to pages (edit, delete, rollback, etc).  They
  * are distinct from Special Pages because an action must apply to exactly one page.
@@ -74,7 +78,7 @@ abstract class Action {
         * @param $action String
         * @param $page Page
         * @param $context IContextSource
-        * @return Action|false|null false if the action is disabled, null
+        * @return Action|bool|null false if the action is disabled, null
         *     if it is not recognised
         */
        public final static function factory( $action, Page $page, IContextSource $context = null ) {
@@ -86,6 +90,53 @@ abstract class Action {
                return $class;
        }
 
+       /**
+        * Get the action that will be executed, not necessarily the one passed
+        * passed through the "action" request parameter. Actions disabled in
+        * $wgActions will be replaced by "nosuchaction".
+        *
+        * @since 1.19
+        * @param $context IContextSource
+        * @return string: action name
+        */
+       public final static function getActionName( IContextSource $context ) {
+               global $wgActions;
+
+               $request = $context->getRequest();
+               $actionName = $request->getVal( 'action', 'view' );
+
+               // Check for disabled actions
+               if ( isset( $wgActions[$actionName] ) && $wgActions[$actionName] === false ) {
+                       $actionName = 'nosuchaction';
+               }
+
+               // Workaround for bug #20966: inability of IE to provide an action dependent
+               // on which submit button is clicked.
+               if ( $actionName === 'historysubmit' ) {
+                       if ( $request->getBool( 'revisiondelete' ) ) {
+                               $actionName = 'revisiondelete';
+                       } else {
+                               $actionName = 'view';
+                       }
+               } elseif ( $actionName == 'editredlink' ) {
+                       $actionName = 'edit';
+               }
+
+               // Trying to get a WikiPage for NS_SPECIAL etc. will result
+               // in WikiPage::factory throwing "Invalid or virtual namespace -1 given."
+               // For SpecialPages et al, default to action=view.
+               if ( !$context->canUseWikiPage() ) {
+                       return 'view';
+               }
+
+               $action = Action::factory( $actionName, $context->getWikiPage() );
+               if ( $action instanceof Action ) {
+                       return $action->getName();
+               }
+
+               return 'nosuchaction';
+       }
+
        /**
         * Check if a given action is recognised, even if it's disabled
         *
@@ -226,7 +277,7 @@ abstract class Action {
                }
 
                if ( $this->requiresUnblock() && $user->isBlocked() ) {
-                       $block = $user->mBlock;
+                       $block = $user->getBlock();
                        throw new UserBlockedError( $block );
                }
 
@@ -281,7 +332,7 @@ abstract class Action {
         * @return String
         */
        protected function getDescription() {
-               return wfMsg( strtolower( $this->getName() ) );
+               return wfMsgHtml( strtolower( $this->getName() ) );
        }
 
        /**
@@ -450,6 +501,7 @@ abstract class FormlessAction extends Action {
 
        /**
         * We don't want an HTMLForm
+        * @return bool
         */
        protected function getFormFields() {
                return false;