Create a new RequestContext to use its OutputPage and Skin members instead of messing with global ones

This commit is contained in:
Alexandre Emsenhuber 2011-07-08 16:18:31 +00:00
parent cf6ed78ed5
commit ffd52683c8
2 changed files with 21 additions and 3 deletions

View file

@ -173,6 +173,24 @@ abstract class ApiBase {
return $this->getResult()->getData();
}
/**
* Create a new RequestContext object to use e.g. for calls to other parts
* the software.
* The object will have the WebRequest and the User object set to the ones
* used in this instance.
*
* @return RequestContext
*/
public function createContext() {
global $wgUser;
$context = new RequestContext;
$context->setRequest( $this->getMain()->getRequest() );
$context->setUser( $wgUser ); /// @todo FIXME: we should store the User object
return $context;
}
/**
* Set warning section for this module. Users should monitor this
* section to notice any changes in API. Multiple calls to this

View file

@ -373,9 +373,9 @@ class ApiParse extends ApiBase {
}
private function categoriesHtml( $categories ) {
global $wgOut, $wgUser;
$wgOut->addCategoryLinks( $categories );
return $wgUser->getSkin()->getCategories();
$context = $this->createContext();
$context->getOutput()->addCategoryLinks( $categories );
return $context->getSkin()->getCategories();
}
/**