https://www.mediawiki.org/wiki/Special:Code/MediaWiki/109223

Revision: 109223
Author:   krinkle
Date:     2012-01-17 21:49:27 +0000 (Tue, 17 Jan 2012)
Log Message:
-----------
[Actions] Move action logic out of 
MediaWiki::getAction/MediaWiki::performAction into Action::getActionName.
* Follows-up r109195
* Reverts/Redoes r108342, r108343, r108345

* Contributes to solution of bug 27930 - Ability to get current action (The 
Right Way)

Modified Paths:
--------------
    trunk/phase3/includes/Action.php
    trunk/phase3/includes/OutputPage.php
    trunk/phase3/includes/Wiki.php

Modified: trunk/phase3/includes/Action.php
===================================================================
--- trunk/phase3/includes/Action.php    2012-01-17 21:48:50 UTC (rev 109222)
+++ trunk/phase3/includes/Action.php    2012-01-17 21:49:27 UTC (rev 109223)
@@ -87,6 +87,45 @@
        }
 
        /**
+        * Get the action that will be executed, not necessarily the one passed
+        * passed through the "action" request parameter. Actions disabled in
+        * $wgDisabledActions will be replaced by "nosuchaction".
+        *
+        * @param $context IContextSource
+        * @return string: action name
+        */
+       public final static function getActionName( IContextSource $context ) {
+               global $wgDisabledActions;
+
+               $request = $context->getRequest();
+               $actionName = $request->getVal( 'action', 'view' );
+
+               // Check for disabled actions
+               if ( in_array( $actionName, $wgDisabledActions ) ) {
+                       $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';
+               }
+
+               $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
         *
         * @param $name String: name of an action

Modified: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php        2012-01-17 21:48:50 UTC (rev 
109222)
+++ trunk/phase3/includes/OutputPage.php        2012-01-17 21:49:27 UTC (rev 
109223)
@@ -2380,7 +2380,7 @@
         * @return String: The doctype, opening <html>, and head element.
         */
        public function headElement( Skin $sk, $includeStyle = true ) {
-               global $wgContLang, $mediaWiki;
+               global $wgContLang;
 
                $userdir = $this->getLanguage()->getDir();
                $sitedir = $wgContLang->getDir();
@@ -2426,7 +2426,7 @@
                }
                $bodyAttrs['class'] .= ' ' . $sk->getPageClasses( 
$this->getTitle() );
                $bodyAttrs['class'] .= ' skin-' . Sanitizer::escapeClass( 
$sk->getSkinName() );
-               $bodyAttrs['class'] .= ' action-' . Sanitizer::escapeClass( 
$mediaWiki->getPerformedAction() );
+               $bodyAttrs['class'] .= ' action-' . Sanitizer::escapeClass( 
Action::getActionName( $this->getContext() ) );
 
                $sk->addToBodyAttributes( $this, $bodyAttrs ); // Allow skins 
to add body attributes they need
                wfRunHooks( 'OutputPageBodyAttributes', array( $this, $sk, 
&$bodyAttrs ) );
@@ -2828,7 +2828,7 @@
         * @return array
         */
        public function getJSVars() {
-               global $wgUseAjax, $wgEnableMWSuggest, $mediaWiki;
+               global $wgUseAjax, $wgEnableMWSuggest;
 
                $title = $this->getTitle();
                $ns = $title->getNamespace();
@@ -2864,7 +2864,7 @@
                        'wgCurRevisionId' => $title->getLatestRevID(),
                        'wgArticleId' => $title->getArticleId(),
                        'wgIsArticle' => $this->isArticle(),
-                       'wgAction' => $mediaWiki->getPerformedAction(),
+                       'wgAction' => Action::getActionName( 
$this->getContext() ),
                        'wgUserName' => $this->getUser()->isAnon() ? null : 
$this->getUser()->getName(),
                        'wgUserGroups' => 
$this->getUser()->getEffectiveGroups(),
                        'wgCategories' => $this->getCategories(),

Modified: trunk/phase3/includes/Wiki.php
===================================================================
--- trunk/phase3/includes/Wiki.php      2012-01-17 21:48:50 UTC (rev 109222)
+++ trunk/phase3/includes/Wiki.php      2012-01-17 21:49:27 UTC (rev 109223)
@@ -34,11 +34,6 @@
        private $context;
 
        /**
-        * @var string
-        */
-       private $performedAction = 'nosuchaction';
-
-       /**
         * @param $x null|WebRequest
         * @return WebRequest
         */
@@ -81,6 +76,7 @@
                $request = $this->context->getRequest();
                $curid = $request->getInt( 'curid' );
                $title = $request->getVal( 'title' );
+               $action = $request->getVal( 'action', 'view' );
 
                if ( $request->getCheck( 'search' ) ) {
                        // Compatibility with old search URLs which didn't use 
Special:Search
@@ -90,7 +86,7 @@
                } elseif ( $curid ) {
                        // URLs like this are generated by RC, because rc_title 
isn't always accurate
                        $ret = Title::newFromID( $curid );
-               } elseif ( $title == '' && $this->getAction() != 'delete' ) {
+               } elseif ( $title == '' && $action != 'delete' ) {
                        $ret = Title::newMainPage();
                } else {
                        $ret = Title::newFromURL( $title );
@@ -310,40 +306,17 @@
        }
 
        /**
-        * Returns the action that will be executed, not necessarily the one 
passed
-        * passed through the "action" parameter. Actions disabled in
-        * $wgDisabledActions will be replaced by "nosuchaction".
+        * Returns the name of the action that will be executed.
         *
-        * The return value is merely a suggestion, not the actually performed 
action,
-        * which may be different. The actually performed action is determined 
by performAction().
-        * Requests like action=nonsense will make this function return 
"nonsense".
-        * Use getPerformedAction() to get the performed action.
-        *
         * @return string: action
         */
        public function getAction() {
-               global $wgDisabledActions;
-
-               $request = $this->context->getRequest();
-               $action = $request->getVal( 'action', 'view' );
-
-               // Check for disabled actions
-               if ( in_array( $action, $wgDisabledActions ) ) {
-                       return 'nosuchaction';
+               static $action = null;
+               
+               if ( $action === null ) {
+                       $action = Action::getActionName( $this->context );
                }
 
-               // Workaround for bug #20966: inability of IE to provide an 
action dependent
-               // on which submit button is clicked.
-               if ( $action === 'historysubmit' ) {
-                       if ( $request->getBool( 'revisiondelete' ) ) {
-                               return 'revisiondelete';
-                       } else {
-                               return 'view';
-                       }
-               } elseif ( $action == 'editredlink' ) {
-                       return 'edit';
-               }
-
                return $action;
        }
 
@@ -510,14 +483,12 @@
 
                $action = Action::factory( $act, $article );
                if ( $action instanceof Action ) {
-                       $this->performedAction = $act;
                        $action->show();
                        wfProfileOut( __METHOD__ );
                        return;
                }
 
                if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {
-                       $this->performedAction = 'nosuchaction';
                        $output->showErrorPage( 'nosuchaction', 
'nosuchactiontext' );
                }
 
@@ -525,18 +496,6 @@
        }
 
        /**
-        * Returns the real action as determined by performAction.
-        * Do not use internally in this class as it depends on the actions by 
this class.
-        *
-        * @since 1.19
-        *
-        * @return string: action
-        */
-       public function getPerformedAction() {
-               return $this->performedAction;
-       }
-
-       /**
         * Run the current MediaWiki instance
         * index.php just calls this
         */


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to