From be1bfe4d5a41fe9068cdfa91e92a529872a17a78 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 28 May 2007 06:59:19 +0000 Subject: [PATCH] API bug 10046: incorrect action produces invalid response format --- includes/api/ApiLogin.php | 18 +++++++++--------- includes/api/ApiMain.php | 22 ++++++++++++++++------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 1caac148f7..48f6b5b77f 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -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; } /** diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index fa5c6eef32..635432137f 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -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()) -- 2.20.1