New infrastructure for actions, as discussed on wikitech-l. Fairly huge commit.
[lhc/web/wiklou.git] / includes / SpecialPage.php
index ee6d390..5eea301 100644 (file)
@@ -74,20 +74,10 @@ class SpecialPage {
         */
        var $mAddedRedirectParams = array();
        /**
-        * Current request
-        * @var WebRequest 
+        * Current request context
+        * @var RequestContext
         */
-       protected $mRequest;
-       /**
-        * Current output page
-        * @var OutputPage
-        */
-       protected $mOutput;
-       /**
-        * Full title including $par
-        * @var Title
-        */
-       protected $mFullTitle;
+       protected $mContext;
                
        /**
         * List of special pages, followed by parameters.
@@ -144,7 +134,7 @@ class SpecialPage {
                'Preferences'               => 'SpecialPreferences',
                'Contributions'             => 'SpecialContributions',
                'Listgrouprights'           => 'SpecialListGroupRights',
-               'Listusers'                 => 'SpecialListusers',
+               'Listusers'                 => array( 'SpecialPage', 'Listusers' ),
                'Listadmins'                => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
                'Listbots'                  => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
                'Activeusers'               => 'SpecialActiveUsers',
@@ -529,11 +519,11 @@ class SpecialPage {
         * Returns a title object if the page is redirected, false if there was no such special
         * page, and true if it was successful.
         *
-        * @param $title          a title object
-        * @param $including      output is being captured for use in {{special:whatever}}
+        * @param $title          Title object
+        * @param $context        RequestContext
+        * @param $including      Bool output is being captured for use in {{special:whatever}}
         */
-       static function executePath( &$title, $including = false ) {
-               global $wgOut, $wgTitle, $wgRequest;
+       public static function executePath( &$title, RequestContext &$context, $including = false ) {
                wfProfileIn( __METHOD__ );
 
                # FIXME: redirects broken due to this call
@@ -547,16 +537,16 @@ class SpecialPage {
                $page = SpecialPage::getPageByAlias( $name );
                # Nonexistent?
                if ( !$page ) {
-                       $wgOut->setArticleRelated( false );
-                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                       $wgOut->setStatusCode( 404 );
-                       $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
+                       $context->output->setArticleRelated( false );
+                       $context->output->setRobotPolicy( 'noindex,nofollow' );
+                       $context->output->setStatusCode( 404 );
+                       $context->output->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
                        wfProfileOut( __METHOD__ );
                        return false;
                }
                
                # Page exists, set the context
-               $page->setContext( $wgRequest, $wgOut );
+               $page->setContext( $context );
 
                # Check for redirect
                if ( !$including ) {
@@ -564,13 +554,13 @@ class SpecialPage {
                        $query = $page->getRedirectQuery();
                        if ( $redirect instanceof Title ) {
                                $url = $redirect->getFullUrl( $query );
-                               $wgOut->redirect( $url );
+                               $context->output->redirect( $url );
                                wfProfileOut( __METHOD__ );
                                return $redirect;
                        } elseif( $redirect === true ) {
                                global $wgScript;
                                $url = $wgScript . '?' . wfArrayToCGI( $query );
-                               $wgOut->redirect( $url );
+                               $context->output->redirect( $url );
                                wfProfileOut( __METHOD__ );
                                return $redirect;
                        }
@@ -581,13 +571,13 @@ class SpecialPage {
                # the request. Such POST requests are possible for old extensions that
                # generate self-links without being aware that their default name has
                # changed.
-               if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
+               if ( !$including && $name != $page->getLocalName() && !$context->request->wasPosted() ) {
                        $query = $_GET;
                        unset( $query['title'] );
                        $query = wfArrayToCGI( $query );
                        $title = $page->getTitle( $par );
                        $url = $title->getFullUrl( $query );
-                       $wgOut->redirect( $url );
+                       $context->output->redirect( $url );
                        wfProfileOut( __METHOD__ );
                        return $redirect;
                }
@@ -596,7 +586,7 @@ class SpecialPage {
                        wfProfileOut( __METHOD__ );
                        return false;
                } elseif ( !$including ) {
-                       $wgTitle = $page->getTitle();
+                       $context->title = $page->getTitle();
                }
                $page->including( $including );
 
@@ -617,23 +607,16 @@ class SpecialPage {
         * @return String: HTML fragment
         */
        static function capturePath( &$title ) {
-               global $wgOut, $wgTitle, $wgUser;
-
-               // preload the skin - Sometimes the SpecialPage loads it at a bad point in time making a includable special page override the skin title
-               // This hack is ok for now. The plan is for
-               // - Skin to stop storing it's own title
-               // - includable special pages to stop using $wgTitle and $wgOut
-               // - and OutputPage to store it's own skin object instead of askin $wgUser
-               // Once just about any of those are implemented preloading will not be necessarily
-               $wgOut->getSkin();
+               global $wgOut, $wgTitle;
 
                $oldTitle = $wgTitle;
                $oldOut = $wgOut;
-               $wgOut = new OutputPage;
-               $wgOut->setTitle( $title );
-               $wgOut->setUser( $wgUser ); # for now, there may be a better idea in the future
+               
+               $context = new RequestContext;
+               $context->setTitle( $title );
+               $wgOut = $context->getOutput();
 
-               $ret = SpecialPage::executePath( $title, true );
+               $ret = SpecialPage::executePath( $title, $context, true );
                if ( $ret === true ) {
                        $ret = $wgOut->getHTML();
                }
@@ -888,11 +871,9 @@ class SpecialPage {
         * This may be overridden by subclasses.
         */
        function execute( $par ) {
-               global $wgUser;
-
                $this->setHeaders();
 
-               if ( $this->userCanExecute( $wgUser ) ) {
+               if ( $this->userCanExecute( $this->getUser() ) ) {
                        $func = $this->mFunction;
                        // only load file if the function does not exist
                        if(!is_callable($func) and $this->mFile) {
@@ -972,12 +953,11 @@ class SpecialPage {
         * @return String
         */
        function getRedirectQuery() {
-               global $wgRequest;
                $params = array();
 
                foreach( $this->mAllowedRedirectParams as $arg ) {
-                       if( $wgRequest->getVal( $arg, null ) !== null ){
-                               $params[$arg] = $wgRequest->getVal( $arg );
+                       if( $this->getContext()->request->getVal( $arg, null ) !== null ){
+                               $params[$arg] = $this->getContext()->request->getVal( $arg );
                        }
                }
 
@@ -993,13 +973,26 @@ class SpecialPage {
        /**
         * Sets the context this SpecialPage is executed in
         * 
-        * @param $request WebRequest
-        * @param $output OutputPage
+        * @param $context RequestContext
+        * @since 1.18
         */
-       protected function setContext( $request, $output ) {
-               $this->mRequest = $request;
-               $this->mOutput = $output;
-               $this->mFullTitle = $output->getTitle();
+       protected function setContext( $context ) {
+               $this->mContext = $context;
+       }
+
+       /**
+        * Gets the context this SpecialPage is executed in
+        * 
+        * @return RequestContext
+        * @since 1.18
+        */
+       public function getContext() {
+               if ( $this->mContext instanceof RequestContext ) {
+                       return $this->mContext;
+               } else {
+                       wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
+                       return RequestContext::getMain();
+               }
        }
 
        /**
@@ -1009,12 +1002,7 @@ class SpecialPage {
         * @since 1.18
         */
        public function getRequest() {
-               if ( !isset($this->mRequest) ) {
-                       wfDebug( __METHOD__ . " called and \$mRequest is null. Return \$wgRequest for sanity\n" );
-                       global $wgRequest;
-                       return $wgRequest;
-               }
-               return $this->mRequest;
+               return $this->getContext()->getRequest();
        }
 
        /**
@@ -1024,12 +1012,7 @@ class SpecialPage {
         * @since 1.18
         */
        public function getOutput() {
-               if ( !isset($this->mOutput) ) {
-                       wfDebug( __METHOD__ . " called and \$mOutput is null. Return \$wgOut for sanity\n" );
-                       global $wgOut;
-                       return $wgOut;
-               }
-               return $this->mOutput;
+               return $this->getContext()->getOutput();
        }
 
        /**
@@ -1039,7 +1022,7 @@ class SpecialPage {
         * @since 1.18
         */
        public function getUser() {
-               return $this->getOutput()->getUser();
+               return $this->getContext()->getUser();
        }
 
        /**
@@ -1049,7 +1032,17 @@ class SpecialPage {
         * @since 1.18
         */
        public function getSkin() {
-               return $this->getOutput()->getSkin();
+               return $this->getContext()->getSkin();
+       }
+
+       /**
+        * Return the full title, including $par
+        *
+        * @return Title
+        * @since 1.18
+        */
+       public function getFullTitle() {
+               return $this->getContext()->getTitle();
        }
 
        /**
@@ -1059,7 +1052,7 @@ class SpecialPage {
         * @see wfMessage
         */
        public function msg( /* $args */ ) {
-               return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->mFullTitle );
+               return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->getFullTitle() );
        }
 }