Merge "API: Don't return a deprecation warning for default values"
This commit is contained in:
commit
982d2c6e62
2 changed files with 29 additions and 2 deletions
|
|
@ -1157,6 +1157,7 @@ abstract class ApiBase extends ContextSource {
|
|||
}
|
||||
|
||||
$value = $this->getMain()->getCheck( $encParamName );
|
||||
$provided = $value;
|
||||
} elseif ( $type == 'upload' ) {
|
||||
if ( isset( $default ) ) {
|
||||
// Having a default value is not allowed
|
||||
|
|
@ -1169,6 +1170,7 @@ abstract class ApiBase extends ContextSource {
|
|||
self::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" );
|
||||
}
|
||||
$value = $this->getMain()->getUpload( $encParamName );
|
||||
$provided = $value->exists();
|
||||
if ( !$value->exists() ) {
|
||||
// This will get the value without trying to normalize it
|
||||
// (because trying to normalize a large binary file
|
||||
|
|
@ -1183,6 +1185,7 @@ abstract class ApiBase extends ContextSource {
|
|||
}
|
||||
} else {
|
||||
$value = $this->getMain()->getVal( $encParamName, $default );
|
||||
$provided = $this->getMain()->getCheck( $encParamName );
|
||||
|
||||
if ( isset( $value ) && $type == 'namespace' ) {
|
||||
$type = MWNamespace::getValidNamespaces();
|
||||
|
|
@ -1373,7 +1376,7 @@ abstract class ApiBase extends ContextSource {
|
|||
}
|
||||
|
||||
// Set a warning if a deprecated parameter has been passed
|
||||
if ( $deprecated && $value !== false ) {
|
||||
if ( $deprecated && $provided ) {
|
||||
$feature = $encParamName;
|
||||
$m = $this;
|
||||
while ( !$m->isMain() ) {
|
||||
|
|
@ -1387,7 +1390,7 @@ abstract class ApiBase extends ContextSource {
|
|||
}
|
||||
|
||||
// Set a warning if a deprecated parameter value has been passed
|
||||
$usedDeprecatedValues = $deprecatedValues && $value !== false
|
||||
$usedDeprecatedValues = $deprecatedValues && $provided
|
||||
? array_intersect( array_keys( $deprecatedValues ), (array)$value )
|
||||
: [];
|
||||
if ( $usedDeprecatedValues ) {
|
||||
|
|
|
|||
|
|
@ -529,12 +529,36 @@ class ApiBaseTest extends ApiTestCase {
|
|||
'foo',
|
||||
[ [ 'apiwarn-deprecation-parameter', 'myParam' ] ],
|
||||
],
|
||||
'Deprecated parameter with default, unspecified' => [
|
||||
null,
|
||||
[ ApiBase::PARAM_DEPRECATED => true, ApiBase::PARAM_DFLT => 'foo' ],
|
||||
'foo',
|
||||
[],
|
||||
],
|
||||
'Deprecated parameter with default, specified' => [
|
||||
'foo',
|
||||
[ ApiBase::PARAM_DEPRECATED => true, ApiBase::PARAM_DFLT => 'foo' ],
|
||||
'foo',
|
||||
[ [ 'apiwarn-deprecation-parameter', 'myParam' ] ],
|
||||
],
|
||||
'Deprecated parameter value' => [
|
||||
'a',
|
||||
[ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ] ],
|
||||
'a',
|
||||
[ [ 'apiwarn-deprecation-parameter', 'myParam=a' ] ],
|
||||
],
|
||||
'Deprecated parameter value as default, unspecified' => [
|
||||
null,
|
||||
[ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ], ApiBase::PARAM_DFLT => 'a' ],
|
||||
'a',
|
||||
[],
|
||||
],
|
||||
'Deprecated parameter value as default, specified' => [
|
||||
'a',
|
||||
[ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ], ApiBase::PARAM_DFLT => 'a' ],
|
||||
'a',
|
||||
[ [ 'apiwarn-deprecation-parameter', 'myParam=a' ] ],
|
||||
],
|
||||
'Multiple deprecated parameter values' => [
|
||||
'a|b|c|d',
|
||||
[ ApiBase::PARAM_DEPRECATED_VALUES =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue