http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89581
Revision: 89581
Author: reedy
Date: 2011-06-06 16:45:40 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
* (bug 27716) Make a method to do checking of 0 or 1 of the parameters
existence (like requireOnlyOneParameter), but without needing one of the
parameters
Modified Paths:
--------------
trunk/phase3/includes/api/ApiBase.php
trunk/phase3/includes/api/ApiQueryBlocks.php
Modified: trunk/phase3/includes/api/ApiBase.php
===================================================================
--- trunk/phase3/includes/api/ApiBase.php 2011-06-06 16:42:02 UTC (rev
89580)
+++ trunk/phase3/includes/api/ApiBase.php 2011-06-06 16:45:40 UTC (rev
89581)
@@ -582,6 +582,38 @@
}
/**
+ * 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
*
* @param $x object Parameter to check is not null/false
Modified: trunk/phase3/includes/api/ApiQueryBlocks.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryBlocks.php 2011-06-06 16:42:02 UTC
(rev 89580)
+++ trunk/phase3/includes/api/ApiQueryBlocks.php 2011-06-06 16:45:40 UTC
(rev 89581)
@@ -49,9 +49,7 @@
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'] );
@@ -290,7 +288,7 @@
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' ),
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs