From: Brad Jorsch Date: Thu, 17 Apr 2014 14:24:30 +0000 (-0400) Subject: API: Warn when unsupported PHP array syntax is used X-Git-Tag: 1.31.0-rc.0~15980^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=4c6d01f82484c2e47210260a9d2a87b2c9fb918a;p=lhc%2Fweb%2Fwiklou.git API: Warn when unsupported PHP array syntax is used The API takes multi-valued parameters as key=value1|value2|value3, not key[]=value1&key[]=value2&key[]=value3, in part because the latter is overly verbose when the API encourages use of large arrays. But when someone, not knowing this, does accidentally use the verbose syntax, they should get a warning instead of having the parameter be silently ignored. Bug: 64057 Change-Id: I32a16efb8028d7f6d120d20dfc886f08ed9ec97d --- diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 2e16312eaa..5cdcd51784 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -980,7 +980,18 @@ class ApiMain extends ApiBase { public function getVal( $name, $default = null ) { $this->mParamsUsed[$name] = true; - return $this->getRequest()->getVal( $name, $default ); + $ret = $this->getRequest()->getVal( $name ); + if ( $ret === null ) { + if ( $this->getRequest()->getArray( $name ) !== null ) { + // See bug 10262 for why we don't just join( '|', ... ) the + // array. + $this->setWarning( + "Parameter '$name' uses unsupported PHP array syntax" + ); + } + $ret = $default; + } + return $ret; } /** @@ -988,9 +999,7 @@ class ApiMain extends ApiBase { * was used, for logging. */ public function getCheck( $name ) { - $this->mParamsUsed[$name] = true; - - return $this->getRequest()->getCheck( $name ); + return $this->getVal( $name, null ) !== null; } /**