Add a context to SpecialPage, so that subclasses don't need globals anymore. Introduc...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 10 Feb 2011 16:14:56 +0000 (16:14 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 10 Feb 2011 16:14:56 +0000 (16:14 +0000)
includes/SpecialPage.php

index 348100a..d220990 100644 (file)
@@ -73,6 +73,22 @@ class SpecialPage {
         * Query parameteres added by redirects
         */
        var $mAddedRedirectParams = array();
+       /**
+        * Current request
+        * @var WebRequest 
+        */
+       protected $mRequest;
+       /**
+        * Current output page
+        * @var OutputPage
+        */
+       protected $mOutput;
+       /**
+        * Full title including $par
+        * @var Title
+        */
+       protected $mFullTitle;
+               
        /**
         * List of special pages, followed by parameters.
         * If the only parameter is a string, that is the page name.
@@ -539,6 +555,9 @@ class SpecialPage {
                        wfProfileOut( __METHOD__ );
                        return false;
                }
+               
+               # Page exists, set the context
+               $page->setContext( $wgRequest, $wgOut );
 
                # Check for redirect
                if ( !$including ) {
@@ -951,6 +970,27 @@ class SpecialPage {
                        ? $params
                        : false;
        }
+       
+       /**
+        * Sets the context this SpecialPage is executed in
+        * 
+        * @param $request WebRequest
+        * @param $output OutputPage
+        */
+       protected function setContext( $request, $output ) {
+               $this->mRequest = $request;
+               $this->mOutput = $output;
+               $this->mFullTitle = $output->getTitle();
+       }
+       /**
+        * Wrapper around wfMessage that sets the current context. Currently this
+        * is only the title.
+        * 
+        * @see wfMessage
+        */
+       public function msg( /* $args */ ) {
+               return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->mFullTitle );
+       }
 }
 
 /**