Revision: 48629
Author: catrope
Date: 2009-03-20 11:40:54 +0000 (Fri, 20 Mar 2009)
Log Message:
-----------
* 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
trunk/phase3/includes/api/ApiQuery.php
Modified: trunk/phase3/includes/api/ApiFormatRaw.php
===================================================================
--- trunk/phase3/includes/api/ApiFormatRaw.php 2009-03-20 11:20:39 UTC (rev
48628)
+++ trunk/phase3/includes/api/ApiFormatRaw.php 2009-03-20 11:40:54 UTC (rev
48629)
@@ -34,12 +34,20 @@
*/
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 @@
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']);
Modified: trunk/phase3/includes/api/ApiQuery.php
===================================================================
--- trunk/phase3/includes/api/ApiQuery.php 2009-03-20 11:20:39 UTC (rev
48628)
+++ trunk/phase3/includes/api/ApiQuery.php 2009-03-20 11:40:54 UTC (rev
48629)
@@ -175,7 +175,8 @@
// 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 @@
}
$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();
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs