API bug 10046: incorrect action produces invalid response format
authorYuri Astrakhan <yurik@users.mediawiki.org>
Mon, 28 May 2007 06:59:19 +0000 (06:59 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Mon, 28 May 2007 06:59:19 +0000 (06:59 +0000)
includes/api/ApiLogin.php
includes/api/ApiMain.php

index 1caac14..48f6b5b 100644 (file)
@@ -72,15 +72,9 @@ class ApiLogin extends ApiBase {
                $name = $password = $domain = null;
                extract($this->extractRequestParams());
 
-               $params = new FauxRequest(array (
-                       'wpName' => $name,
-                       'wpPassword' => $password,
-                       'wpDomain' => $domain,
-                       'wpRemember' => ''
-               ));
-
                $result = array ();
 
+               // Make sure noone is trying to guess the password brut-force
                $nextLoginIn = $this->getNextLoginTimeout();
                if ($nextLoginIn > 0) {
                        $result['result']  = 'NeedToWait';
@@ -90,6 +84,13 @@ class ApiLogin extends ApiBase {
                        return;
                }
 
+               $params = new FauxRequest(array (
+                       'wpName' => $name,
+                       'wpPassword' => $password,
+                       'wpDomain' => $domain,
+                       'wpRemember' => ''
+               ));
+
                $loginForm = new LoginForm($params);
                switch ($loginForm->authenticateUserData()) {
                        case LoginForm :: SUCCESS :
@@ -179,9 +180,8 @@ class ApiLogin extends ApiBase {
 
                $elapse = (time() - $val['lastReqTime']) / 1000;  // in seconds
                $canRetryIn = ApiLogin::calculateDelay($val) - $elapse;
-               $canRetryIn = $canRetryIn < 0 ? 0 : $canRetryIn; 
 
-               return $canRetryIn;
+               return $canRetryIn < 0 ? 0 : $canRetryIn;
        }
        
        /**
index fa5c6ee..6354321 100644 (file)
@@ -179,7 +179,12 @@ class ApiMain extends ApiBase {
 
                        // Printer may not be initialized if the extractRequestParams() fails for the main module
                        if (!isset ($this->mPrinter)) {
-                               $this->mPrinter = $this->createPrinterByName(self :: API_DEFAULT_FORMAT);
+                               // The printer has not been created yet. Try to manually get formatter value.
+                               $value = $this->getRequest()->getVal('format', self::API_DEFAULT_FORMAT);
+                               if (!in_array($value, $this->mFormatNames))
+                                       $value = self::API_DEFAULT_FORMAT;
+
+                               $this->mPrinter = $this->createPrinterByName($value);
                                if ($this->mPrinter->getNeedsRawData())
                                        $this->getResult()->setRawMode();
                        }
@@ -190,7 +195,10 @@ class ApiMain extends ApiBase {
                                //
                                $errMessage = array (
                                'code' => $e->getCodeString(), 'info' => $e->getMessage());
-                               ApiResult :: setContent($errMessage, $this->makeHelpMsg());
+                               
+                               // Only print the help message when this is for the developer, not runtime
+                               if ($this->mPrinter->getIsHtml())
+                                       ApiResult :: setContent($errMessage, $this->makeHelpMsg());
 
                        } else {
                                //
@@ -235,9 +243,11 @@ class ApiMain extends ApiBase {
         * Execute the actual module, without any error handling
         */
        protected function executeAction() {
-               $action = $format = $version = null;
-               extract($this->extractRequestParams());
-               $this->mShowVersions = $version;
+               
+               $params = $this->extractRequestParams();
+               
+               $this->mShowVersions = $params['version'];
+               $action = $params['action'];
 
                // Instantiate the module requested by the user
                $module = new $this->mModules[$action] ($this, $action);
@@ -248,7 +258,7 @@ class ApiMain extends ApiBase {
                        $this->mPrinter = $module->getCustomPrinter();
                        if (is_null($this->mPrinter)) {
                                // Create an appropriate printer
-                               $this->mPrinter = $this->createPrinterByName($format);
+                               $this->mPrinter = $this->createPrinterByName($params['format']);
                        }
 
                        if ($this->mPrinter->getNeedsRawData())