Index: trunk/phase3/includes/api/ApiFormatRaw.php |
— | — | @@ -34,12 +34,20 @@ |
35 | 35 | */ |
36 | 36 | class ApiFormatRaw extends ApiFormatBase { |
37 | 37 | |
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; |
40 | 46 | } |
41 | 47 | |
42 | 48 | public function getMimeType() { |
43 | 49 | $data = $this->getResultData(); |
| 50 | + if(isset($data['error'])) |
| 51 | + return $this->mErrorFallback->getMimeType(); |
44 | 52 | if(!isset($data['mime'])) |
45 | 53 | ApiBase::dieDebug(__METHOD__, "No MIME type set for raw formatter"); |
46 | 54 | return $data['mime']; |
— | — | @@ -47,6 +55,11 @@ |
48 | 56 | |
49 | 57 | public function execute() { |
50 | 58 | $data = $this->getResultData(); |
| 59 | + if(isset($data['error'])) |
| 60 | + { |
| 61 | + $this->mErrorFallback->execute(); |
| 62 | + return; |
| 63 | + } |
51 | 64 | if(!isset($data['text'])) |
52 | 65 | ApiBase::dieDebug(__METHOD__, "No text given for raw formatter"); |
53 | 66 | $this->printText($data['text']); |
Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -175,7 +175,8 @@ |
176 | 176 | // If &exportnowrap is set, use the raw formatter |
177 | 177 | if ($this->getParameter('export') && |
178 | 178 | $this->getParameter('exportnowrap')) |
179 | | - return new ApiFormatRaw($this->getMain()); |
| 179 | + return new ApiFormatRaw($this->getMain(), |
| 180 | + $this->getMain()->createPrinterByName('xml')); |
180 | 181 | else |
181 | 182 | return null; |
182 | 183 | } |
— | — | @@ -375,36 +376,35 @@ |
376 | 377 | } |
377 | 378 | |
378 | 379 | $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); |
408 | 407 | } |
| 408 | + $result->enableSizeCheck(); |
409 | 409 | } |
410 | 410 | } |
411 | 411 | |