*/
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.
'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',
* 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
$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 ) {
$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;
}
# 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;
}
wfProfileOut( __METHOD__ );
return false;
} elseif ( !$including ) {
- $wgTitle = $page->getTitle();
+ $context->title = $page->getTitle();
}
$page->including( $including );
* @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();
}
* 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) {
* @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 );
}
}
/**
* 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();
+ }
}
/**
* @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();
}
/**
* @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();
}
/**
* @since 1.18
*/
public function getUser() {
- return $this->getOutput()->getUser();
+ return $this->getContext()->getUser();
}
/**
* @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();
}
/**
* @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() );
}
}