Message: Downgrade exception on bool/null param to warning

Bug: T378876
Change-Id: Iecbf83dd060b2a1dc30bd33bfc4f2a42cfbd2a1f
This commit is contained in:
Bartosz Dziewoński 2024-11-02 13:08:37 +01:00
parent 711bc46a04
commit 4efe6fe7e2
3 changed files with 13 additions and 7 deletions

View file

@ -1016,6 +1016,8 @@ supported.
as JSON, the methods MessageValue::objectParams(), Message::objectParams()
and Message::objectParam() are deprecated. The UserGroupMembershipParam
class and the ParamType::OBJECT constant are likewise deprecated.
* Passing null or boolean values as message parameters, which are converted
to strings "" and "1", is deprecated.
* The Less mixin .column-break-after-avoid() is deprecated. Use just the
CSS rule `break-after: avoid-column;` instead now.
* The Less mixins .horizontal-gradient and .vertical-gradient are deprecated.

View file

@ -48,10 +48,15 @@ class ScalarParam extends MessageParam {
// TODO: Remove separate '__toString' check above once we drop PHP 7.4
$value = (string)$value;
} elseif ( !is_string( $value ) && !is_numeric( $value ) ) {
$type = get_debug_type( $value );
throw new InvalidArgumentException(
"Scalar parameter must be a string, number, Stringable, or MessageSpecifier; got $type"
);
$valType = get_debug_type( $value );
if ( $value === null || is_bool( $value ) ) {
wfDeprecatedMsg( "Using $valType as message parameter was deprecated in MediaWiki 1.43", '1.43' );
$value = (string)$value;
} else {
throw new InvalidArgumentException(
"Scalar parameter must be a string, number, Stringable, or MessageSpecifier; got $valType"
);
}
}
$this->type = $type;

View file

@ -82,9 +82,8 @@ class ScalarParamTest extends MediaWikiUnitTestCase {
}
public function testConstruct_badValueNULL() {
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage(
'Scalar parameter must be a string, number, Stringable, or MessageSpecifier; got null'
$this->expectDeprecationAndContinue(
'/Using null as message parameter was deprecated/'
);
new ScalarParam( ParamType::TEXT, null );
}