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

Revision: 108342
Author:   krinkle
Date:     2012-01-08 01:31:56 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
Implement MediaWiki::getPerformedAction()
* Fixes:
-- Bug 27930 - Ablity to get current action (The Right Way)

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

Modified: trunk/phase3/includes/Wiki.php
===================================================================
--- trunk/phase3/includes/Wiki.php      2012-01-08 00:52:50 UTC (rev 108341)
+++ trunk/phase3/includes/Wiki.php      2012-01-08 01:31:56 UTC (rev 108342)
@@ -33,6 +33,11 @@
         */
        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 @@
        /**
         * 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 @@
 
                $action = Action::factory( $act, $article );
                if ( $action instanceof Action ) {
+                       $this->performedAction = $act;
                        $action->show();
                        wfProfileOut( __METHOD__ );
                        return;
@@ -497,12 +508,14 @@
                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 @@
                                // 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,6 +541,7 @@
                                break;
                        default:
                                if ( wfRunHooks( 'UnknownAction', array( $act, 
$article ) ) ) {
+                                       $this->performedAction = 'nosuchaction';
                                        $output->showErrorPage( 'nosuchaction', 
'nosuchactiontext' );
                                }
                }
@@ -534,6 +549,16 @@
        }
 
        /**
+        * 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
         */


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to