Fixed for r58099 per CR:
authorRoan Kattouw <catrope@users.mediawiki.org>
Thu, 3 Jun 2010 09:53:28 +0000 (09:53 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Thu, 3 Jun 2010 09:53:28 +0000 (09:53 +0000)
* Only clicktrack local, domain-relative URLs
* Validate redirect URL in ApiClickTracking with the same condition used in ClickTracking.js (local, domain-relative)
* Remove call to nonexistent function OutputPage::enable()
* Add functionality for disabling API output and use this after setting up the redirect. This fixes the issue where the body of the redirect contained an API response in xmlfm form
at; the body is now empty.

includes/api/ApiFormatBase.php
includes/api/ApiMain.php

index 3ad1419..d8bd510 100644 (file)
@@ -36,7 +36,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 abstract class ApiFormatBase extends ApiBase {
 
        private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared;
-       private $mBufferResult = false, $mBuffer;
+       private $mBufferResult = false, $mBuffer, $mDisabled = false;
 
        /**
         * Constructor
@@ -113,6 +113,18 @@ abstract class ApiFormatBase extends ApiBase {
                return $this->getIsHtml();
        }
 
+       /**
+        * Disable the formatter completely. This causes calls to initPrinter(),
+        * printText() and closePrinter() to be ignored.
+        */
+       public function disable() {
+               $this->mDisabled = true;
+       }
+       
+       public function isDisabled() {
+               return $this->mDisabled;
+       }
+
        /**
         * Initialize the printer function and prepare the output headers, etc.
         * This method must be the first outputing method during execution.
@@ -120,6 +132,9 @@ abstract class ApiFormatBase extends ApiBase {
         * @param $isError bool Whether an error message is printed
         */
        function initPrinter( $isError ) {
+               if ( $this->mDisabled ) {
+                       return;
+               }
                $isHtml = $this->getIsHtml();
                $mime = $isHtml ? 'text/html' : $this->getMimeType();
                $script = wfScript( 'api' );
@@ -172,6 +187,9 @@ See <a href='http://www.mediawiki.org/wiki/API'>complete documentation</a>, or
         * Finish printing. Closes HTML tags.
         */
        public function closePrinter() {
+               if ( $this->mDisabled ) {
+                       return;
+               }
                if ( $this->getIsHtml() ) {
 ?>
 
@@ -191,6 +209,9 @@ See <a href='http://www.mediawiki.org/wiki/API'>complete documentation</a>, or
         * @param $text string
         */
        public function printText( $text ) {
+               if ( $this->mDisabled ) {
+                       return;
+               }
                if ( $this->mBufferResult ) {
                        $this->mBuffer = $text;
                } elseif ( $this->getIsHtml() ) {
index 49cee0a..12f8a3f 100644 (file)
@@ -199,6 +199,13 @@ class ApiMain extends ApiBase {
        public function getModule() {
                return $this->mModule;
        }
+       
+       /**
+        * Get the result formatter object. Only works after setupExecuteAction()
+        */
+       public function getPrinter() {
+               return $this->mPrinter;
+       }
 
        /**
         * Only kept for backwards compatibility
@@ -330,7 +337,7 @@ class ApiMain extends ApiBase {
 
                header( "Cache-Control: $ccHeader" );
 
-               if ( $this->mPrinter->getIsHtml() ) {
+               if ( $this->mPrinter->getIsHtml() && !$this->mPrinter->isDisabled() ) {
                        echo wfReportTime();
                }