Revert r27581, 27598, 27626
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 19 Nov 2007 15:32:06 +0000 (15:32 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 19 Nov 2007 15:32:06 +0000 (15:32 +0000)
format=raw is an HTML injection machine like action=raw but without any safeguards; it's trivial to create JavaScript exploits which hit at least Internet Explorer.
There's no reason to add a whole new danger point here when you've got machine-readable structure already... please do not add this raw formatter back.

RELEASE-NOTES
includes/AutoLoader.php
includes/GlobalFunctions.php
includes/Wiki.php
includes/api/ApiBase.php
includes/api/ApiExpandTemplates.php
includes/api/ApiFormatBase.php
includes/api/ApiHelp.php
includes/api/ApiMain.php
includes/api/ApiQuery.php
includes/api/ApiRender.php

index f7bc968..fa2c3ec 100644 (file)
@@ -194,8 +194,6 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API
 * (bug 11562) Added a user_registration parameter/field to the list=allusers query.
 * (bug 11588) Preserve document structure for empty dataset in backlinks query.
 * Outputting list of all user preferences rather than having to request them by name
-* Add raw formatting support. Now several actions like expandtemplates support raw output with format=raw
-* (bug 11206) api.php should honor maxlag
 
 === Languages updated in 1.12 ===
 
index aa6d909..828be04 100644 (file)
@@ -301,7 +301,6 @@ function __autoload($className) {
                'Services_JSON' => 'includes/api/ApiFormatJson_json.php',
                'ApiFormatJson' => 'includes/api/ApiFormatJson.php',
                'ApiFormatPhp' => 'includes/api/ApiFormatPhp.php',
-               'ApiFormatRaw' => 'includes/api/ApiFormatBase.php',
                'ApiFormatWddx' => 'includes/api/ApiFormatWddx.php',
                'ApiFormatXml' => 'includes/api/ApiFormatXml.php',
                'Spyc' => 'includes/api/ApiFormatYaml_spyc.php',
index fa3eb03..008a6d2 100644 (file)
@@ -2335,24 +2335,4 @@ function wfGetNull() {
        return wfIsWindows()
                ? 'NUL'
                : '/dev/null';
-}
-
-/**
- * Displays a maxlag error
- * 
- * @param string $host Server that lags the most
- * @param int $lag Maxlag (actual)
- * @param int $maxLag Maxlag (requested)
- */
-function wfMaxlagError( $host, $lag, $maxLag ) {
-       global $wgShowHostnames;
-       header( 'HTTP/1.1 503 Service Unavailable' );
-       header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
-       header( 'X-Database-Lag: ' . intval( $lag ) );
-       header( 'Content-Type: text/plain' );
-       if( $wgShowHostnames ) {
-               echo "Waiting for $host: $lag seconds lagged\n";
-       } else {
-               echo "Waiting for a database server: $lag seconds lagged\n";
-       }
 }
\ No newline at end of file
index 4920ff2..02f9430 100644 (file)
@@ -57,10 +57,18 @@ class MediaWiki {
        }
 
        function checkMaxLag( $maxLag ) {
-               global $wgLoadBalancer;
+               global $wgLoadBalancer, $wgShowHostnames;
                list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
                if ( $lag > $maxLag ) {
-                       wfMaxlagError( $host, $lag, $maxLag );
+                       header( 'HTTP/1.1 503 Service Unavailable' );
+                       header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
+                       header( 'X-Database-Lag: ' . intval( $lag ) );
+                       header( 'Content-Type: text/plain' );
+                       if( $wgShowHostnames ) {
+                               echo "Waiting for $host: $lag seconds lagged\n";
+                       } else {
+                               echo "Waiting for a database server: $lag seconds lagged\n";
+                       }
                        return false;
                } else {
                        return true;
index 684ba0c..37bd4e7 100644 (file)
@@ -509,37 +509,6 @@ abstract class ApiBase {
                wfDebugDieBacktrace("Internal error in $method: $message");
        }
 
-       private $mRawFormat = false;
-
-       /**
-        * Returns if module supports raw mode
-        */
-       public function supportRaw() {
-               return false;
-       }
-
-       /**
-        * Enables raw mode
-        */
-       public function setRaw() {
-               $this->mRawFormat = true;
-       }
-
-       /**
-        * Checks if raw mode is enabled
-        */
-       public function isRaw() {
-               return $this->mRawFormat;
-       }
-
-       /**
-        * Indicates if API needs to check maxlag
-        */
-       public function shouldCheckMaxlag() {
-               return true;
-       }
-
-
        /**
         * Profiling: total module execution time
         */
@@ -648,4 +617,3 @@ abstract class ApiBase {
        }
 }
 
-
index d043bcb..df99ba1 100644 (file)
@@ -55,18 +55,11 @@ class ApiExpandTemplates extends ApiBase {
 
                // Return result
                $result = $this->getResult();
-               if( $this->isRaw() ) {
-                       ApiFormatRaw :: setRawData( $result, $retval );
-               }
                $retval_array = array();
                $result->setContent( $retval_array, $retval );
                $result->addValue( null, $this->getModuleName(), $retval_array );
        }
 
-       public function supportRaw() {
-               return true;
-       }
-
        protected function getAllowedParams() {
                return array (
                        'title' => array( 
@@ -98,4 +91,3 @@ class ApiExpandTemplates extends ApiBase {
        }
 }
 
-
index 0693040..5bfbd9e 100644 (file)
@@ -276,64 +276,3 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
                return __CLASS__ . ': $Id$';
        }
 }
-
-/**
- * This printer is used to wrap raw printer
- * @addtogroup API
- */
-class ApiFormatRaw extends ApiFormatBase {
-
-       public function __construct($main, $format) {
-               parent :: __construct($main, $format);
-       }
-
-       public static function setRawData( $result, $raw_data, $raw_type = 'text/plain' ) {
-               $data = & $result->getData();
-               $data['_raw'] = $raw_data;
-               $data['_raw_mimetype'] = $raw_type;
-       }
-
-       public function getMimeType() {
-               $data = $this->getResultData();
-               if( !isset( $data['_raw_mimetype'] ) && !isset( $data['error'] ) ) {
-                       ApiBase :: dieDebug( 'ApiFormatRaw', 'No raw data is set for this module' );
-                       return;
-               }
-               elseif( isset( $data['error'] ) ) {
-                       $this->executeError( $data );
-                       return;
-               }
-               return $data['_raw_mimetype'];
-       }
-
-       public function execute() {
-               $data = $this->getResultData();
-               if( !isset( $data['_raw'] ) && !isset( $data['error'] ) ) {
-                       ApiBase :: dieDebug( 'ApiFormatRaw', 'No raw data is set for this module' );
-                       return;
-               }
-               elseif( isset( $data['error'] ) ) {
-                       $this->executeError( $data );
-                       return;
-               }
-               $this->printText( $data['_raw'] );
-       }
-       
-       private function executeError( $data ) {
-               wfHttpError(500, 'Internal Server Error', '');
-               echo "{$data['error']['code']}\n";
-               echo "{$data['error']['info']}\n";
-       }
-
-       public function getNeedsRawData() {
-               return true;
-       }
-
-       protected function getDescription() {
-               return 'Output data in raw format. NOTE: not all actions support it' . parent :: getDescription();
-       }
-
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
-       }
-}
index 21150a6..aeebb50 100644 (file)
@@ -46,10 +46,6 @@ class ApiHelp extends ApiBase {
                $this->dieUsage('', 'help');
        }
 
-       public function shouldCheckMaxlag() {
-               return false;
-       }
-
        protected function getDescription() {
                return array (
                        'Display this help screen.'
index d80928e..406d23a 100644 (file)
@@ -75,7 +75,6 @@ class ApiMain extends ApiBase {
                'xmlfm' => 'ApiFormatXml',
                'yaml' => 'ApiFormatYaml',
                'yamlfm' => 'ApiFormatYaml',
-               'raw' => 'ApiFormatRaw',
                'rawfm' => 'ApiFormatJson'
        );
 
@@ -290,33 +289,9 @@ class ApiMain extends ApiBase {
 
                // Instantiate the module requested by the user
                $module = new $this->mModules[$this->mAction] ($this, $this->mAction);
-               
-               if( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) {
-                       // Check for maxlag
-                       global $wgLoadBalancer, $wgShowHostnames;
-                       $maxLag = $params['maxlag'];
-                       list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
-                       if ( $lag > $maxLag ) {
-                               if( $wgShowHostnames ) {
-                                       ApiBase :: dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
-                               } else {
-                                       ApiBase :: dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
-                               }
-                               return;
-                       }
-               }
 
                if (!$this->mInternalMode) {
 
-                       //Check usage of raw printer
-                       if( $params['format'] == 'raw' ) {
-                               if( !$module->supportRaw() ) {
-                                       ApiBase :: dieUsage( 'This module doesn\'t support format=raw', 'rawnotsupported' );
-                                       return;
-                               }
-                               $module->setRaw();
-                       }
-
                        // See if custom printer is used
                        $this->mPrinter = $module->getCustomPrinter();
                        if (is_null($this->mPrinter)) {
@@ -373,10 +348,7 @@ class ApiMain extends ApiBase {
                                ApiBase :: PARAM_DFLT => 'help',
                                ApiBase :: PARAM_TYPE => $this->mModuleNames
                        ),
-                       'version' => false,
-                       'maxlag'  => array (
-                               ApiBase :: PARAM_TYPE => 'integer'
-                       ),
+                       'version' => false
                );
        }
 
@@ -387,8 +359,7 @@ class ApiMain extends ApiBase {
                return array (
                        'format' => 'The format of the output',
                        'action' => 'What action you would like to perform',
-                       'version' => 'When showing help, include version for each module',
-                       'maxlag' => 'Maximum lag'
+                       'version' => 'When showing help, include version for each module'
                );
        }
 
@@ -572,4 +543,3 @@ class UsageException extends Exception {
 }
 
 
-
index 1b1c3b3..0223f6f 100644 (file)
@@ -456,11 +456,6 @@ class ApiQuery extends ApiBase {
                $psModule = new ApiPageSet($this);
                return $psModule->makeHelpMsgParameters() . parent :: makeHelpMsgParameters();
        }
-       
-       // @todo should work correctly
-       public function shouldCheckMaxlag() {
-               return true;
-       }
 
        protected function getParamDescription() {
                return array (
index 3540756..9302da3 100644 (file)
@@ -56,18 +56,11 @@ class ApiRender extends ApiBase {
 
                // Return result
                $result = $this->getResult();
-               if( $this->isRaw() ) {
-                       ApiFormatRaw :: setRawData( $result, $retval, 'text/html' );
-               }
                $retval_array = array();
                $result->setContent( $retval_array, $retval );
                $result->addValue( null, $this->getModuleName(), $retval_array );
        }
 
-       public function supportRaw() {
-               return true;
-       }
-
        protected function getAllowedParams() {
                return array (
                        'title' => array( 
@@ -99,4 +92,3 @@ class ApiRender extends ApiBase {
        }
 }
 
-