Create a new RequestContext to use its OutputPage and Skin members instead of messing...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Fri, 8 Jul 2011 16:18:31 +0000 (16:18 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Fri, 8 Jul 2011 16:18:31 +0000 (16:18 +0000)
includes/api/ApiBase.php
includes/api/ApiParse.php

index c10aeed..8fbeb12 100644 (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
index 6075888..1b0e940 100644 (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();
        }
 
        /**