Index: trunk/phase3/includes/api/ApiQueryBlocks.php |
— | — | @@ -49,9 +49,7 @@ |
50 | 50 | global $wgUser, $wgContLang; |
51 | 51 | |
52 | 52 | $params = $this->extractRequestParams(); |
53 | | - if ( isset( $params['users'] ) && isset( $params['ip'] ) ) { |
54 | | - $this->dieUsage( 'bkusers and bkip cannot be used together', 'usersandip' ); |
55 | | - } |
| 53 | + $this->requireMaxOneParameter( $params, 'users', 'ip' ); |
56 | 54 | |
57 | 55 | $prop = array_flip( $params['prop'] ); |
58 | 56 | $fld_id = isset( $prop['id'] ); |
— | — | @@ -290,7 +288,7 @@ |
291 | 289 | |
292 | 290 | public function getPossibleErrors() { |
293 | 291 | return array_merge( parent::getPossibleErrors(), array( |
294 | | - array( 'code' => 'usersandip', 'info' => 'bkusers and bkip cannot be used together' ), |
| 292 | + $this->getRequireOnlyOneParameterErrorMessages( array( 'users', 'ip' ) ), |
295 | 293 | array( 'code' => 'cidrtoobroad', 'info' => 'CIDR ranges broader than /16 are not accepted' ), |
296 | 294 | array( 'code' => 'param_user', 'info' => 'User parameter may not be empty' ), |
297 | 295 | array( 'code' => 'param_user', 'info' => 'User name user is not valid' ), |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -582,6 +582,38 @@ |
583 | 583 | } |
584 | 584 | |
585 | 585 | /** |
| 586 | + * Die if more than one of a certain set of parameters is set and not false. |
| 587 | + * |
| 588 | + * @param $params array |
| 589 | + */ |
| 590 | + public function requireMaxOneParameter( $params ) { |
| 591 | + $required = func_get_args(); |
| 592 | + array_shift( $required ); |
| 593 | + |
| 594 | + $intersection = array_intersect( array_keys( array_filter( $params, |
| 595 | + array( $this, "parameterNotEmpty" ) ) ), $required ); |
| 596 | + |
| 597 | + if ( count( $intersection ) > 1 ) { |
| 598 | + $this->dieUsage( 'The parameters ' . implode( ', ', $intersection ) . ' can not be used together', 'invalidparammix' ); |
| 599 | + } |
| 600 | + } |
| 601 | + |
| 602 | + /** |
| 603 | + * Generates the possible error requireMaxOneParameter() can die with |
| 604 | + * |
| 605 | + * @param $params array |
| 606 | + * @return array |
| 607 | + */ |
| 608 | + public function getRequireMaxOneParameterErrorMessages( $params ) { |
| 609 | + $p = $this->getModulePrefix(); |
| 610 | + $params = implode( ", {$p}", $params ); |
| 611 | + |
| 612 | + return array( |
| 613 | + array( 'code' => "{$p}invalidparammix", 'info' => "The parameters {$p}{$params} can not be used together" ) |
| 614 | + ); |
| 615 | + } |
| 616 | + |
| 617 | + /** |
586 | 618 | * Callback function used in requireOnlyOneParameter to check whether reequired parameters are set |
587 | 619 | * |
588 | 620 | * @param $x object Parameter to check is not null/false |