From d28d00071ae7fb23488a3a37aead52fe22a376d7 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Tue, 17 Jan 2012 21:49:27 +0000 Subject: [PATCH] [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) --- includes/Action.php | 39 +++++++++++++++++++++++++++++ includes/OutputPage.php | 8 +++--- includes/Wiki.php | 55 ++++++----------------------------------- 3 files changed, 50 insertions(+), 52 deletions(-) diff --git a/includes/Action.php b/includes/Action.php index d81d2fe374..08179d6b84 100644 --- a/includes/Action.php +++ b/includes/Action.php @@ -86,6 +86,45 @@ 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 + * $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 * diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 9c46ff8529..2cef51c5bb 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2380,7 +2380,7 @@ $templates * @return String: The doctype, opening , 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 @@ $templates } $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 @@ $templates * @return array */ public function getJSVars() { - global $wgUseAjax, $wgEnableMWSuggest, $mediaWiki; + global $wgUseAjax, $wgEnableMWSuggest; $title = $this->getTitle(); $ns = $title->getNamespace(); @@ -2864,7 +2864,7 @@ $templates '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(), diff --git a/includes/Wiki.php b/includes/Wiki.php index c896f49660..13e4f08074 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -33,11 +33,6 @@ class MediaWiki { */ private $context; - /** - * @var string - */ - private $performedAction = 'nosuchaction'; - /** * @param $x null|WebRequest * @return WebRequest @@ -81,6 +76,7 @@ class MediaWiki { $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 @@ class MediaWiki { } 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,38 +306,15 @@ class MediaWiki { } /** - * 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". - * - * 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. + * Returns the name of the action that will be executed. * * @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'; - } - - // 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'; + static $action = null; + + if ( $action === null ) { + $action = Action::getActionName( $this->context ); } return $action; @@ -510,32 +483,18 @@ class MediaWiki { $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' ); } wfProfileOut( __METHOD__ ); } - /** - * 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 -- 2.20.1