From: Roan Kattouw Date: Tue, 20 May 2008 19:31:45 +0000 (+0000) Subject: API: Unrecognized values for multivalue parameters now don't cause the API to abort... X-Git-Tag: 1.31.0-rc.0~47506 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=119ca6e2ed71284291fc0c6eed033083f8b096b0;p=lhc%2Fweb%2Fwiklou.git API: Unrecognized values for multivalue parameters now don't cause the API to abort with an error anymore, but just throw a warning and are ignored. This is useful for ??prop parameters, but also applies to other multivalue parameters such as list, meta and prop. Single values still throw an error like they used to. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b53ab6f0e8..f464649d58 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -351,6 +351,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 13829) Expose parse tree via action=expandtemplates * (bug 13606) Allow deletion of images * Added iiprop=mime and aiprop=metadata +* Handled unrecognized values for parameters more gracefully === Languages updated in 1.13 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 14d5522aa6..978e0565ef 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -518,10 +518,21 @@ abstract class ApiBase { $this->dieUsage("Only one $possibleValues is allowed for parameter '$valueName'", "multival_$valueName"); } if (is_array($allowedValues)) { - $unknownValues = array_diff($valuesList, $allowedValues); - if ($unknownValues) { - $this->dieUsage('Unrecognised value' . (count($unknownValues) > 1 ? "s" : "") . " for parameter '$valueName'", "unknown_$valueName"); + # Check for unknown values + $unknown = array_diff($valuesList, $allowedValues); + if(!empty($unknown)) + { + if($allowMultiple) + { + $s = count($unknown) > 1 ? "s" : ""; + $vals = implode(", ", $unknown); + $this->setWarning("Unrecognized value$s for parameter '$valueName': $vals"); + } + else + $this->dieUsage("Unrecognized value for parameter '$valueName': {$valuesList[0]}", "unknown_$valueName"); } + # Now throw them out + $valuesList = array_intersect($valuesList, $allowedValues); } return $allowMultiple ? $valuesList : $valuesList[0];