array_shift( $required );
$intersection = array_intersect( array_keys( array_filter( $params,
- create_function( '$x', 'return !is_null($x) && $x !== false;' )
- ) ), $required );
+ array( $this, "parameterNotEmpty" ) ) ), $required );
+
if ( count( $intersection ) > 1 ) {
$this->dieUsage( 'The parameters ' . implode( ', ', $intersection ) . ' can not be used together', 'invalidparammix' );
} elseif ( count( $intersection ) == 0 ) {
}
}
+ /**
+ * Callback function used in requireOnlyOneParameter to check whether reequired parameters are set
+ *
+ * @param $x object Parameter to check is not null/false
+ * @return bool
+ */
+ private function parameterNotEmpty( $x ) {
+ return !is_null( $x ) && $x !== false;
+ }
+
/**
* @deprecated use MWNamespace::getValidNamespaces()
*/
break;
case 'integer': // Force everything using intval() and optionally validate limits
- $value = is_array( $value ) ? array_map( 'intval', $value ) : intval( $value );
-
$min = isset ( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : null;
$max = isset ( $paramSettings[self::PARAM_MAX] ) ? $paramSettings[self::PARAM_MAX] : null;
$enforceLimits = isset ( $paramSettings[self::PARAM_RANGE_ENFORCE] )
if ( !is_null( $min ) || !is_null( $max ) ) {
if ( is_array( $value ) ) {
+ $value = array_map( 'intval', $value );
foreach ( $value as &$v ) {
- $this->validateLimit( $paramName, $v, $min, $max, $enforceLimits );
+ $this->validateLimit( $paramName, $v, $min, $max, null, $enforceLimits );
}
} else {
- $this->validateLimit( $paramName, $value, $min, $max, $enforceLimits );
+ $value = intval( $value );
+ $this->validateLimit( $paramName, $value, $min, $max, null, $enforceLimits );
}
}
break;
*/
private function warnOrDie( $msg, $enforceLimits = false ) {
if ( $enforceLimits ) {
- $this->dieUsageMsg( $msg );
+ $this->dieUsage( $msg, 'integeroutofrange' );
} else {
$this->setWarning( $msg );
}
'createonly-exists' => array( 'code' => 'articleexists', 'info' => "The article you tried to create has been created already" ),
'nocreate-missing' => array( 'code' => 'missingtitle', 'info' => "The article you tried to edit doesn't exist" ),
'nosuchrcid' => array( 'code' => 'nosuchrcid', 'info' => "There is no change with rcid ``\$1''" ),
- 'cantpurge' => array( 'code' => 'cantpurge', 'info' => "Only users with the 'purge' right can purge pages via the API" ),
'protect-invalidaction' => array( 'code' => 'protect-invalidaction', 'info' => "Invalid protection type ``\$1''" ),
'protect-invalidlevel' => array( 'code' => 'protect-invalidlevel', 'info' => "Invalid protection level ``\$1''" ),
'toofewexpiries' => array( 'code' => 'toofewexpiries', 'info' => "\$1 expiry timestamps were provided where \$2 were needed" ),