X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=c1a4cd353ec05a198ff8e6bc974a56a7ba6bf35c;hb=cdf4a17a56572ed47e6f62653268714498f8ee3b;hp=40edf4ecced1c27fba045db50725c28253c30d1b;hpb=4e7ab6970835033cf0f44872cf958ca5f6dfe930;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 40edf4ecce..c1a4cd353e 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -801,6 +801,38 @@ abstract class ApiBase extends ContextSource { ); } + /** + * Die if none of a certain set of parameters is set and not false. + * @param array $params of parameter names + */ + public function requireAtLeastOneParameter( $params ) { + $required = func_get_args(); + array_shift( $required ); + $p = $this->getModulePrefix(); + + $intersection = array_intersect( array_keys( array_filter( $params, + array( $this, "parameterNotEmpty" ) ) ), $required ); + + if ( count( $intersection ) == 0 ) { + $this->dieUsage( "At least one of the parameters {$p}" . implode( ", {$p}", $required ) . ' is required', "{$p}missingparam" ); + } + } + + /** + * Generates the possible errors requireAtLeastOneParameter() can die with + * + * @param $params array + * @return array + */ + public function getRequireAtLeastOneParameterErrorMessages( $params ) { + $p = $this->getModulePrefix(); + $params = implode( ", {$p}", $params ); + + return array( + array( 'code' => "{$p}missingparam", 'info' => "At least one of the parameters {$p}{$params} is required" ), + ); + } + /** * @param $params array * @param bool|string $load Whether load the object's state from the database: