From 79948c3077bacaecad60e2eedfa1ba53771912d1 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sun, 8 Jan 2012 01:31:56 +0000 Subject: [PATCH] Implement MediaWiki::getPerformedAction() * Fixes: -- Bug 27930 - Ablity to get current action (The Right Way) --- includes/Wiki.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/includes/Wiki.php b/includes/Wiki.php index 0bbcee40f2..6f043e8797 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -33,6 +33,11 @@ class MediaWiki { */ private $context; + /** + * @var string + */ + private $peformedAction = 'nosuchaction'; + public function request( WebRequest $x = null ){ $old = $this->context->getRequest(); $this->context->setRequest( $x ); @@ -296,9 +301,14 @@ 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" + * $wgDisabledActions will be replaced by "nosuchaction". * - * @return String: action + * 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; @@ -489,6 +499,7 @@ class MediaWiki { $action = Action::factory( $act, $article ); if ( $action instanceof Action ) { + $this->performedAction = $act; $action->show(); wfProfileOut( __METHOD__ ); return; @@ -497,12 +508,14 @@ class MediaWiki { switch( $act ) { case 'view': $output->setSquidMaxage( $wgSquidMaxage ); + $this->performedAction = $act; $article->view(); break; case 'delete': case 'protect': case 'unprotect': case 'render': + $this->performedAction = $act; $article->$act(); break; case 'submit': @@ -513,6 +526,7 @@ class MediaWiki { // Continue... case 'edit': if ( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) { + $this->performedAction = 'edit'; if ( ExternalEdit::useExternalEngine( $this->context, 'edit' ) && $act == 'edit' && !$request->getVal( 'section' ) && !$request->getVal( 'oldid' ) ) @@ -527,12 +541,23 @@ class MediaWiki { break; default: 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. + * + * @return string: action + */ + public function getPerformedAction(){ + return $this->performedAction; + } + /** * Run the current MediaWiki instance * index.php just calls this -- 2.20.1