* API: Really fix bug 17673 this time: exportnowrap still returned fatal errors when...
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 20 Mar 2009 11:40:54 +0000 (11:40 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 20 Mar 2009 11:40:54 +0000 (11:40 +0000)
* 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

includes/api/ApiFormatRaw.php
includes/api/ApiQuery.php

index 603a950..02eccda 100644 (file)
@@ -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']);
index 2ce5649..e3719e0 100644 (file)
@@ -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();
                }
        }