Add a function to require one and only one parameter of a list.
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 29 Aug 2008 21:09:18 +0000 (21:09 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 29 Aug 2008 21:09:18 +0000 (21:09 +0000)
includes/api/ApiBase.php

index f926a2d..4253822 100644 (file)
@@ -365,6 +365,21 @@ abstract class ApiBase {
                $paramSettings = $params[$paramName];
                return $this->getParameterFromSettings($paramName, $paramSettings, $parseMaxLimit);
        }
+       
+       /**
+        * Die if none or more than one of a certain set of parameters is set
+        */
+       public function requireOnlyOneParameter($params) {
+               $required = func_get_args();
+               array_shift($required);
+               
+               $intersection = array_intersect(array_keys($params), $required);
+               if (count($intersection) > 1) {
+                       $this->dieUsage('The parameters '.implode(', ', $intersection).' can not be used together', 'invalidparammix');
+               } elseif (count($intersection) == 0) {
+                       $this->dieUsage('One of the parameters '.implode(', ', $required).' is required', 'missingparam');
+               }
+       }
 
        /**
         * Returns an array of the namespaces (by integer id) that exist on the