r48629 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48628‎ | r48629 | r48630 >
Date:11:40, 20 March 2009
Author:catrope
Status:ok
Tags:
Comment:
* API: Really fix bug 17673 this time: exportnowrap still returned fatal errors when no titles were given or generated
* Move export/exportnowrap handling code out of the if(count($pages)) branch
* Add an error fallback to ApiFormatRaw (exportnowrap uses the XML formatter for errors), since Raw doesn't know how to format errors
Modified paths:
  • /trunk/phase3/includes/api/ApiFormatRaw.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiFormatRaw.php
@@ -34,12 +34,20 @@
3535 */
3636 class ApiFormatRaw extends ApiFormatBase {
3737
38 - public function __construct($main, $format) {
39 - parent :: __construct($main, $format);
 38+ /**
 39+ * Constructor
 40+ * @param $main ApiMain object
 41+ * @param $errorFallback Formatter object to fall back on for errors
 42+ */
 43+ public function __construct($main, $errorFallback) {
 44+ parent :: __construct($main, 'raw');
 45+ $this->mErrorFallback = $errorFallback;
4046 }
4147
4248 public function getMimeType() {
4349 $data = $this->getResultData();
 50+ if(isset($data['error']))
 51+ return $this->mErrorFallback->getMimeType();
4452 if(!isset($data['mime']))
4553 ApiBase::dieDebug(__METHOD__, "No MIME type set for raw formatter");
4654 return $data['mime'];
@@ -47,6 +55,11 @@
4856
4957 public function execute() {
5058 $data = $this->getResultData();
 59+ if(isset($data['error']))
 60+ {
 61+ $this->mErrorFallback->execute();
 62+ return;
 63+ }
5164 if(!isset($data['text']))
5265 ApiBase::dieDebug(__METHOD__, "No text given for raw formatter");
5366 $this->printText($data['text']);
Index: trunk/phase3/includes/api/ApiQuery.php
@@ -175,7 +175,8 @@
176176 // If &exportnowrap is set, use the raw formatter
177177 if ($this->getParameter('export') &&
178178 $this->getParameter('exportnowrap'))
179 - return new ApiFormatRaw($this->getMain());
 179+ return new ApiFormatRaw($this->getMain(),
 180+ $this->getMain()->createPrinterByName('xml'));
180181 else
181182 return null;
182183 }
@@ -375,36 +376,35 @@
376377 }
377378
378379 $result->setIndexedTagName($pages, 'page');
379 - $result->addValue('query', 'pages', $pages);
380 -
381 - if ($this->params['export']) {
382 - $exporter = new WikiExporter($this->getDB());
383 - // WikiExporter writes to stdout, so catch its
384 - // output with an ob
385 - ob_start();
386 - $exporter->openStream();
387 - foreach ($pageSet->getGoodTitles() as $title)
388 - if ($title->userCanRead())
389 - $exporter->pageByTitle($title);
390 - $exporter->closeStream();
391 - $exportxml = ob_get_contents();
392 - ob_end_clean();
393 - // Don't check the size of exported stuff
394 - // It's not continuable, so it would cause more
395 - // problems than it'd solve
396 - $result->disableSizeCheck();
397 - if ($this->params['exportnowrap']) {
398 - $result->reset();
399 - // Raw formatter will handle this
400 - $result->addValue(null, 'text', $exportxml);
401 - $result->addValue(null, 'mime', 'text/xml');
402 - } else {
403 - $r = array();
404 - ApiResult::setContent($r, $exportxml);
405 - $result->addValue('query', 'export', $r);
406 - }
407 - $result->enableSizeCheck();
 380+ $result->addValue('query', 'pages', $pages);
 381+ }
 382+ if ($this->params['export']) {
 383+ $exporter = new WikiExporter($this->getDB());
 384+ // WikiExporter writes to stdout, so catch its
 385+ // output with an ob
 386+ ob_start();
 387+ $exporter->openStream();
 388+ foreach (@$pageSet->getGoodTitles() as $title)
 389+ if ($title->userCanRead())
 390+ $exporter->pageByTitle($title);
 391+ $exporter->closeStream();
 392+ $exportxml = ob_get_contents();
 393+ ob_end_clean();
 394+ // Don't check the size of exported stuff
 395+ // It's not continuable, so it would cause more
 396+ // problems than it'd solve
 397+ $result->disableSizeCheck();
 398+ if ($this->params['exportnowrap']) {
 399+ $result->reset();
 400+ // Raw formatter will handle this
 401+ $result->addValue(null, 'text', $exportxml);
 402+ $result->addValue(null, 'mime', 'text/xml');
 403+ } else {
 404+ $r = array();
 405+ ApiResult::setContent($r, $exportxml);
 406+ $result->addValue('query', 'export', $r);
408407 }
 408+ $result->enableSizeCheck();
409409 }
410410 }
411411

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r47827API: (bug 17673) Using &exportnowrap without &export results in an internal e...catrope10:11, 26 February 2009

Status & tagging log