From ffd52683c8e9ba7fe352bbcd8664d32df2409d27 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 8 Jul 2011 16:18:31 +0000 Subject: [PATCH] Create a new RequestContext to use its OutputPage and Skin members instead of messing with global ones --- includes/api/ApiBase.php | 18 ++++++++++++++++++ includes/api/ApiParse.php | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index c10aeedc27..8fbeb1264d 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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 diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 60758884ab..1b0e94076a 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -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(); } /** -- 2.20.1