From: Roan Kattouw Date: Fri, 20 Mar 2009 11:40:54 +0000 (+0000) Subject: * API: Really fix bug 17673 this time: exportnowrap still returned fatal errors when... X-Git-Tag: 1.31.0-rc.0~42434 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=902cc71973a0a710271df40492c5fb772ba93450;p=lhc%2Fweb%2Fwiklou.git * 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 --- diff --git a/includes/api/ApiFormatRaw.php b/includes/api/ApiFormatRaw.php index 603a950627..02eccda627 100644 --- a/includes/api/ApiFormatRaw.php +++ b/includes/api/ApiFormatRaw.php @@ -34,12 +34,20 @@ if (!defined('MEDIAWIKI')) { */ class ApiFormatRaw extends ApiFormatBase { - public function __construct($main, $format) { - parent :: __construct($main, $format); + /** + * Constructor + * @param $main ApiMain object + * @param $errorFallback Formatter object to fall back on for errors + */ + public function __construct($main, $errorFallback) { + parent :: __construct($main, 'raw'); + $this->mErrorFallback = $errorFallback; } public function getMimeType() { $data = $this->getResultData(); + if(isset($data['error'])) + return $this->mErrorFallback->getMimeType(); if(!isset($data['mime'])) ApiBase::dieDebug(__METHOD__, "No MIME type set for raw formatter"); return $data['mime']; @@ -47,6 +55,11 @@ class ApiFormatRaw extends ApiFormatBase { public function execute() { $data = $this->getResultData(); + if(isset($data['error'])) + { + $this->mErrorFallback->execute(); + return; + } if(!isset($data['text'])) ApiBase::dieDebug(__METHOD__, "No text given for raw formatter"); $this->printText($data['text']); diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 2ce5649360..e3719e0d50 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -175,7 +175,8 @@ class ApiQuery extends ApiBase { // If &exportnowrap is set, use the raw formatter if ($this->getParameter('export') && $this->getParameter('exportnowrap')) - return new ApiFormatRaw($this->getMain()); + return new ApiFormatRaw($this->getMain(), + $this->getMain()->createPrinterByName('xml')); else return null; } @@ -375,36 +376,35 @@ class ApiQuery extends ApiBase { } $result->setIndexedTagName($pages, 'page'); - $result->addValue('query', 'pages', $pages); - - if ($this->params['export']) { - $exporter = new WikiExporter($this->getDB()); - // WikiExporter writes to stdout, so catch its - // output with an ob - ob_start(); - $exporter->openStream(); - foreach ($pageSet->getGoodTitles() as $title) - if ($title->userCanRead()) - $exporter->pageByTitle($title); - $exporter->closeStream(); - $exportxml = ob_get_contents(); - ob_end_clean(); - // Don't check the size of exported stuff - // It's not continuable, so it would cause more - // problems than it'd solve - $result->disableSizeCheck(); - if ($this->params['exportnowrap']) { - $result->reset(); - // Raw formatter will handle this - $result->addValue(null, 'text', $exportxml); - $result->addValue(null, 'mime', 'text/xml'); - } else { - $r = array(); - ApiResult::setContent($r, $exportxml); - $result->addValue('query', 'export', $r); - } - $result->enableSizeCheck(); + $result->addValue('query', 'pages', $pages); + } + if ($this->params['export']) { + $exporter = new WikiExporter($this->getDB()); + // WikiExporter writes to stdout, so catch its + // output with an ob + ob_start(); + $exporter->openStream(); + foreach (@$pageSet->getGoodTitles() as $title) + if ($title->userCanRead()) + $exporter->pageByTitle($title); + $exporter->closeStream(); + $exportxml = ob_get_contents(); + ob_end_clean(); + // Don't check the size of exported stuff + // It's not continuable, so it would cause more + // problems than it'd solve + $result->disableSizeCheck(); + if ($this->params['exportnowrap']) { + $result->reset(); + // Raw formatter will handle this + $result->addValue(null, 'text', $exportxml); + $result->addValue(null, 'mime', 'text/xml'); + } else { + $r = array(); + ApiResult::setContent($r, $exportxml); + $result->addValue('query', 'export', $r); } + $result->enableSizeCheck(); } }