From 5f6fa16138339b3e4f0f41f7d070fd2cd1421d04 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sat, 21 Jan 2012 06:57:34 +0000 Subject: [PATCH] Reinstate r109223 per CR + fixes * Action/Context stuff is pretty deeply nested everywhere. * Should be okay now, at last. * Reverts reverting r109243 * Same as r109223, except adding this: + if ( !$context->canUseWikiPage() ) { + return 'view'; + } --- includes/Action.php | 46 ++++++++++++++++++++++++++++++++++ includes/OutputPage.php | 8 +++--- includes/Wiki.php | 55 ++++++----------------------------------- 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/includes/Action.php b/includes/Action.php index d81d2fe374..c7c06bd13a 100644 --- a/includes/Action.php +++ b/includes/Action.php @@ -86,6 +86,52 @@ 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'; + } + + // 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 * diff --git a/includes/OutputPage.php b/includes/OutputPage.php index b9d46b4d17..e7364ea684 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 ) ); @@ -2824,7 +2824,7 @@ $templates * @return array */ public function getJSVars() { - global $wgUseAjax, $wgEnableMWSuggest, $mediaWiki; + global $wgUseAjax, $wgEnableMWSuggest; $title = $this->getTitle(); $ns = $title->getNamespace(); @@ -2860,7 +2860,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