r91732 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91731‎ | r91732 | r91733 >
Date:16:18, 8 July 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
Create a new RequestContext to use its OutputPage and Skin members instead of messing with global ones
Modified paths:
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiParse.php
@@ -373,9 +373,9 @@
374374 }
375375
376376 private function categoriesHtml( $categories ) {
377 - global $wgOut, $wgUser;
378 - $wgOut->addCategoryLinks( $categories );
379 - return $wgUser->getSkin()->getCategories();
 377+ $context = $this->createContext();
 378+ $context->getOutput()->addCategoryLinks( $categories );
 379+ return $context->getSkin()->getCategories();
380380 }
381381
382382 /**
Index: trunk/phase3/includes/api/ApiBase.php
@@ -174,6 +174,24 @@
175175 }
176176
177177 /**
 178+ * Create a new RequestContext object to use e.g. for calls to other parts
 179+ * the software.
 180+ * The object will have the WebRequest and the User object set to the ones
 181+ * used in this instance.
 182+ *
 183+ * @return RequestContext
 184+ */
 185+ public function createContext() {
 186+ global $wgUser;
 187+
 188+ $context = new RequestContext;
 189+ $context->setRequest( $this->getMain()->getRequest() );
 190+ $context->setUser( $wgUser ); /// @todo FIXME: we should store the User object
 191+
 192+ return $context;
 193+ }
 194+
 195+ /**
178196 * Set warning section for this module. Users should monitor this
179197 * section to notice any changes in API. Multiple calls to this
180198 * function will result in the warning messages being separated by

Comments

#Comment by Reedy (talk | contribs)   16:19, 8 July 2011

Should createContext be caching?

#Comment by IAlex (talk | contribs)   16:25, 8 July 2011

In my opinion it should not, otherwise it could mess between different modules (in internal calls, etc.) The module using it need to store it somewhere if it has to.

Status & tagging log