r22500 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22499‎ | r22500 | r22501 >
Date:06:59, 28 May 2007
Author:yurik
Status:old
Tags:
Comment:
API bug 10046: incorrect action produces invalid response format
Modified paths:
  • /trunk/phase3/includes/api/ApiLogin.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiLogin.php
@@ -72,15 +72,9 @@
7373 $name = $password = $domain = null;
7474 extract($this->extractRequestParams());
7575
76 - $params = new FauxRequest(array (
77 - 'wpName' => $name,
78 - 'wpPassword' => $password,
79 - 'wpDomain' => $domain,
80 - 'wpRemember' => ''
81 - ));
82 -
8376 $result = array ();
8477
 78+ // Make sure noone is trying to guess the password brut-force
8579 $nextLoginIn = $this->getNextLoginTimeout();
8680 if ($nextLoginIn > 0) {
8781 $result['result'] = 'NeedToWait';
@@ -90,6 +84,13 @@
9185 return;
9286 }
9387
 88+ $params = new FauxRequest(array (
 89+ 'wpName' => $name,
 90+ 'wpPassword' => $password,
 91+ 'wpDomain' => $domain,
 92+ 'wpRemember' => ''
 93+ ));
 94+
9495 $loginForm = new LoginForm($params);
9596 switch ($loginForm->authenticateUserData()) {
9697 case LoginForm :: SUCCESS :
@@ -179,9 +180,8 @@
180181
181182 $elapse = (time() - $val['lastReqTime']) / 1000; // in seconds
182183 $canRetryIn = ApiLogin::calculateDelay($val) - $elapse;
183 - $canRetryIn = $canRetryIn < 0 ? 0 : $canRetryIn;
184184
185 - return $canRetryIn;
 185+ return $canRetryIn < 0 ? 0 : $canRetryIn;
186186 }
187187
188188 /**
Index: trunk/phase3/includes/api/ApiMain.php
@@ -179,7 +179,12 @@
180180
181181 // Printer may not be initialized if the extractRequestParams() fails for the main module
182182 if (!isset ($this->mPrinter)) {
183 - $this->mPrinter = $this->createPrinterByName(self :: API_DEFAULT_FORMAT);
 183+ // The printer has not been created yet. Try to manually get formatter value.
 184+ $value = $this->getRequest()->getVal('format', self::API_DEFAULT_FORMAT);
 185+ if (!in_array($value, $this->mFormatNames))
 186+ $value = self::API_DEFAULT_FORMAT;
 187+
 188+ $this->mPrinter = $this->createPrinterByName($value);
184189 if ($this->mPrinter->getNeedsRawData())
185190 $this->getResult()->setRawMode();
186191 }
@@ -190,7 +195,10 @@
191196 //
192197 $errMessage = array (
193198 'code' => $e->getCodeString(), 'info' => $e->getMessage());
194 - ApiResult :: setContent($errMessage, $this->makeHelpMsg());
 199+
 200+ // Only print the help message when this is for the developer, not runtime
 201+ if ($this->mPrinter->getIsHtml())
 202+ ApiResult :: setContent($errMessage, $this->makeHelpMsg());
195203
196204 } else {
197205 //
@@ -235,9 +243,11 @@
236244 * Execute the actual module, without any error handling
237245 */
238246 protected function executeAction() {
239 - $action = $format = $version = null;
240 - extract($this->extractRequestParams());
241 - $this->mShowVersions = $version;
 247+
 248+ $params = $this->extractRequestParams();
 249+
 250+ $this->mShowVersions = $params['version'];
 251+ $action = $params['action'];
242252
243253 // Instantiate the module requested by the user
244254 $module = new $this->mModules[$action] ($this, $action);
@@ -248,7 +258,7 @@
249259 $this->mPrinter = $module->getCustomPrinter();
250260 if (is_null($this->mPrinter)) {
251261 // Create an appropriate printer
252 - $this->mPrinter = $this->createPrinterByName($format);
 262+ $this->mPrinter = $this->createPrinterByName($params['format']);
253263 }
254264
255265 if ($this->mPrinter->getNeedsRawData())

Follow-up revisions

RevisionCommit summaryAuthorDate
r22518Merged revisions 22484-22517 via svnmerge from...david22:22, 28 May 2007