From 5f6862c89e5832c117613cf6232f08ab57436fdb Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Thu, 10 Feb 2011 16:14:56 +0000 Subject: [PATCH] Add a context to SpecialPage, so that subclasses don't need globals anymore. Introduces $mRequest, $mOutput and $mFullTitle, which can be used instead of $wgRequest, $wgOut and $wgTitle. Introduces msg(), which is a wrapper around wfMessage()->title(). --- includes/SpecialPage.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 348100aad4..d220990ee5 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -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 ); + } } /** -- 2.20.1