From 94110916b1a041370831f6f7d31d51db55508276 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 7 Feb 2019 15:32:36 -0500 Subject: [PATCH] API: Don't return a deprecation warning for default values If a deprecated parameter has a default value, or a deprecated value is part of the default value for a parameter, don't give the client a deprecation warning about it. Bug: T215548 Change-Id: I980763e3d44fb1b7459c64b175fcaddf5fd44a13 --- includes/api/ApiBase.php | 7 +++++-- tests/phpunit/includes/api/ApiBaseTest.php | 24 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 1efd747f80..21e20c27f9 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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 ) { diff --git a/tests/phpunit/includes/api/ApiBaseTest.php b/tests/phpunit/includes/api/ApiBaseTest.php index 121820ad48..8049a47f25 100644 --- a/tests/phpunit/includes/api/ApiBaseTest.php +++ b/tests/phpunit/includes/api/ApiBaseTest.php @@ -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 => -- 2.20.1