);
}
+ /**
+ * Die if more than one of a certain set of parameters is set and not false.
+ *
+ * @param $params array
+ */
+ public function requireMaxOneParameter( $params ) {
+ $required = func_get_args();
+ array_shift( $required );
+
+ $intersection = array_intersect( array_keys( array_filter( $params,
+ array( $this, "parameterNotEmpty" ) ) ), $required );
+
+ if ( count( $intersection ) > 1 ) {
+ $this->dieUsage( 'The parameters ' . implode( ', ', $intersection ) . ' can not be used together', 'invalidparammix' );
+ }
+ }
+
+ /**
+ * Generates the possible error requireMaxOneParameter() can die with
+ *
+ * @param $params array
+ * @return array
+ */
+ public function getRequireMaxOneParameterErrorMessages( $params ) {
+ $p = $this->getModulePrefix();
+ $params = implode( ", {$p}", $params );
+
+ return array(
+ array( 'code' => "{$p}invalidparammix", 'info' => "The parameters {$p}{$params} can not be used together" )
+ );
+ }
+
/**
* Callback function used in requireOnlyOneParameter to check whether reequired parameters are set
*
global $wgUser, $wgContLang;
$params = $this->extractRequestParams();
- if ( isset( $params['users'] ) && isset( $params['ip'] ) ) {
- $this->dieUsage( 'bkusers and bkip cannot be used together', 'usersandip' );
- }
+ $this->requireMaxOneParameter( $params, 'users', 'ip' );
$prop = array_flip( $params['prop'] );
$fld_id = isset( $prop['id'] );
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
- array( 'code' => 'usersandip', 'info' => 'bkusers and bkip cannot be used together' ),
+ $this->getRequireOnlyOneParameterErrorMessages( array( 'users', 'ip' ) ),
array( 'code' => 'cidrtoobroad', 'info' => 'CIDR ranges broader than /16 are not accepted' ),
array( 'code' => 'param_user', 'info' => 'User parameter may not be empty' ),
array( 'code' => 'param_user', 'info' => 'User name user is not valid' ),