API: Unrecognized values for multivalue parameters now don't cause the API to abort...
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 20 May 2008 19:31:45 +0000 (19:31 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 20 May 2008 19:31:45 +0000 (19:31 +0000)
RELEASE-NOTES
includes/api/ApiBase.php

index b53ab6f..f464649 100644 (file)
@@ -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 ===
 
index 14d5522..978e056 100644 (file)
@@ -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];