From 4c6d01f82484c2e47210260a9d2a87b2c9fb918a Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 17 Apr 2014 10:24:30 -0400 Subject: [PATCH] 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 --- includes/api/ApiMain.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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; } /** -- 2.20.1