Reinstate r109223 per CR + fixes
authorKrinkle <krinkle@users.mediawiki.org>
Sat, 21 Jan 2012 06:57:34 +0000 (06:57 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sat, 21 Jan 2012 06:57:34 +0000 (06:57 +0000)
* 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
includes/OutputPage.php
includes/Wiki.php

index d81d2fe..c7c06bd 100644 (file)
@@ -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
         *
index b9d46b4..e7364ea 100644 (file)
@@ -2380,7 +2380,7 @@ $templates
         * @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 @@ $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(),
index c896f49..13e4f08 100644 (file)
@@ -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