Deprecate Message::objectParams() and related code
This functionality was introduced in 2021 (commit 349819dc5a)
to support the addition of UserGroupMembershipParam, which was
never used, and no other use case appeared.
Its existence is now preventing us from allowing serializing
of MessageValue objects as JSON (since the parameters can't be
guaranteed to be serializable).
Deprecate:
* method: MessageValue::objectParams()
* method: Message::objectParams()
* method: Message::objectParam()
* class: UserGroupMembershipParam
* constant: ParamType::OBJECT
* Passing Stringable objects to ScalarParam
Change-Id: I492edabb7ea1d75774b45eb9fd18261b39963f9f
This commit is contained in:
parent
29a9fd398c
commit
f18362ccce
10 changed files with 32 additions and 9 deletions
|
|
@ -365,6 +365,11 @@ because of Phabricator reports.
|
|||
DatabaseBlockStore.
|
||||
* DatabaseBlockStore::getReadStage() and ::getWriteStage() are deprecated.
|
||||
Use the new schema unconditionally.
|
||||
* To support a future change allowing serializing of MessageValue objects
|
||||
as JSON, the methods MessageValue::objectParams(), Message::objectParams()
|
||||
and Message::objectParam() are deprecated. The UserGroupMembershipParam
|
||||
class, the ParamType::OBJECT constant, and passing Stringable objects to
|
||||
ScalarParam are likewise deprecated.
|
||||
* …
|
||||
|
||||
=== Other changes in 1.43 ===
|
||||
|
|
|
|||
|
|
@ -718,6 +718,7 @@ class Message implements MessageSpecifier, Serializable {
|
|||
* Add parameters that represent stringable objects
|
||||
*
|
||||
* @since 1.38
|
||||
* @deprecated since 1.43
|
||||
*
|
||||
* @param Stringable|Stringable[] ...$params stringable parameters,
|
||||
* or a single argument that is an array of stringable parameters.
|
||||
|
|
@ -725,11 +726,14 @@ class Message implements MessageSpecifier, Serializable {
|
|||
* @return self $this
|
||||
*/
|
||||
public function objectParams( ...$params ) {
|
||||
wfDeprecated( __METHOD__, '1.43' );
|
||||
if ( isset( $params[0] ) && is_array( $params[0] ) ) {
|
||||
$params = $params[0];
|
||||
}
|
||||
foreach ( $params as $param ) {
|
||||
$this->parameters[] = self::objectParam( $param );
|
||||
// Suppress redundant deprecation warning
|
||||
// phpcs:ignore Generic.PHP.NoSilencedErrors
|
||||
$this->parameters[] = @self::objectParam( $param );
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -1285,12 +1289,14 @@ class Message implements MessageSpecifier, Serializable {
|
|||
|
||||
/**
|
||||
* @since 1.38
|
||||
* @deprecated since 1.43
|
||||
*
|
||||
* @param Stringable $object
|
||||
*
|
||||
* @return Stringable[] Array with a single "object" key.
|
||||
*/
|
||||
public static function objectParam( Stringable $object ) {
|
||||
wfDeprecated( __METHOD__, '1.43' );
|
||||
return [ 'object' => $object ];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ use Stringable;
|
|||
|
||||
/**
|
||||
* @since 1.38
|
||||
* @deprecated since 1.43 Use Language::getGroupMemberName() instead
|
||||
*/
|
||||
class UserGroupMembershipParam implements Stringable {
|
||||
/** @var string */
|
||||
|
|
@ -37,6 +38,7 @@ class UserGroupMembershipParam implements Stringable {
|
|||
private $member;
|
||||
|
||||
public function __construct( string $group, UserIdentity $member ) {
|
||||
wfDeprecated( __CLASS__, '1.43' );
|
||||
$this->group = $group;
|
||||
$this->member = $member;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,10 +97,12 @@ class MessageValue {
|
|||
/**
|
||||
* Chainable mutator which adds object parameters
|
||||
*
|
||||
* @deprecated since 1.43
|
||||
* @param Stringable ...$values stringable object values
|
||||
* @return $this
|
||||
*/
|
||||
public function objectParams( ...$values ) {
|
||||
wfDeprecated( __METHOD__, '1.43' );
|
||||
foreach ( $values as $value ) {
|
||||
$this->params[] = new ScalarParam( ParamType::OBJECT, $value );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ class ParamType {
|
|||
/**
|
||||
* For arbitrary stringable objects
|
||||
* @since 1.38
|
||||
* @deprecated since 1.43
|
||||
*/
|
||||
public const OBJECT = 'object';
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class ScalarParam extends MessageParam {
|
|||
*
|
||||
* @param string $type One of the ParamType constants.
|
||||
* @param string|int|float|MessageValue|Stringable $value
|
||||
* Using Stringable objects is deprecated since 1.43.
|
||||
*/
|
||||
public function __construct( $type, $value ) {
|
||||
if ( $type === ParamType::LIST ) {
|
||||
|
|
@ -27,8 +28,11 @@ class ScalarParam extends MessageParam {
|
|||
'ParamType::LIST cannot be used with ScalarParam; use ListParam instead'
|
||||
);
|
||||
}
|
||||
if ( !is_string( $value ) && !is_numeric( $value ) &&
|
||||
!$value instanceof MessageValue && !$value instanceof Stringable ) {
|
||||
if ( $value instanceof Stringable ) {
|
||||
wfDeprecatedMsg( 'Passing Stringable objects to ScalarParam' .
|
||||
' was deprecated in MediaWiki 1.43', '1.43' );
|
||||
} elseif ( !is_string( $value ) && !is_numeric( $value ) &&
|
||||
!$value instanceof MessageValue ) {
|
||||
$type = is_object( $value ) ? get_class( $value ) : gettype( $value );
|
||||
throw new InvalidArgumentException(
|
||||
"Scalar parameter must be a string, number, or MessageValue; got $type"
|
||||
|
|
|
|||
|
|
@ -95,7 +95,8 @@ class TextFormatterTest extends MediaWikiIntegrationTestCase {
|
|||
'test (group-bot) $2'
|
||||
];
|
||||
|
||||
yield [ ( new MessageValue( 'test' ) )
|
||||
// Deprecated, silence deprecation warnings
|
||||
@yield [ ( new MessageValue( 'test' ) )
|
||||
->objectParams(
|
||||
new UserGroupMembershipParam( 'bot', new UserIdentityValue( 1, 'user' ) )
|
||||
),
|
||||
|
|
|
|||
|
|
@ -493,6 +493,8 @@ class MessageTest extends MediaWikiLangTestCase {
|
|||
}
|
||||
|
||||
public function testUserGroupMemberParams() {
|
||||
$this->expectDeprecationAndContinue( '/UserGroupMembershipParam/' );
|
||||
$this->expectDeprecationAndContinue( '/objectParams/' );
|
||||
$lang = $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'qqx' );
|
||||
$msg = new RawMessage( '$1' );
|
||||
$this->setUserLang( $lang );
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class UserGroupMembershipParamTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public function testConstruct() {
|
||||
$param = new UserGroupMembershipParam( $this->group, $this->member );
|
||||
$param = @new UserGroupMembershipParam( $this->group, $this->member );
|
||||
$this->assertSame( $this->group, $param->getGroup() );
|
||||
$this->assertSame( $this->member, $param->getMember() );
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ class UserGroupMembershipParamTest extends MediaWikiUnitTestCase {
|
|||
$groupMock = 'users';
|
||||
$userNameMock = 'MockUser';
|
||||
$userIdentityMock = new UserIdentityValue( 1, $userNameMock );
|
||||
$param = new UserGroupMembershipParam( $groupMock, $userIdentityMock );
|
||||
$param = @new UserGroupMembershipParam( $groupMock, $userIdentityMock );
|
||||
$this->assertSame( $groupMock, $param->getGroup(),
|
||||
'Group name should match the constructor argument.' );
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ class UserGroupMembershipParamTest extends MediaWikiUnitTestCase {
|
|||
$groupMock = 'users';
|
||||
$userNameMock = 'MockUser';
|
||||
$userIdentityMock = new UserIdentityValue( 1, $userNameMock );
|
||||
$param = new UserGroupMembershipParam( $groupMock, $userIdentityMock );
|
||||
$param = @new UserGroupMembershipParam( $groupMock, $userIdentityMock );
|
||||
$this->assertSame( $userIdentityMock, $param->getMember(),
|
||||
'User identity object should match the constructor argument.' );
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ class UserGroupMembershipParamTest extends MediaWikiUnitTestCase {
|
|||
$userIdentityMock = new UserIdentityValue( 2, 'MockAdminUser' );
|
||||
|
||||
// Create the UserGroupMembershipParam instance with mocks.
|
||||
$param = new UserGroupMembershipParam( $groupMock, $userIdentityMock );
|
||||
$param = @new UserGroupMembershipParam( $groupMock, $userIdentityMock );
|
||||
$expectedString = 'sysop:MockAdminUser';
|
||||
// Asserting if the string representation is as expected.
|
||||
$this->assertSame( $expectedString, (string)$param,
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ class MessageValueTest extends TestCase {
|
|||
|
||||
public function testUserGroupMemberParams() {
|
||||
$mv = new MessageValue( 'key' );
|
||||
$mv2 = $mv->objectParams(
|
||||
$mv2 = @$mv->objectParams(
|
||||
new UserGroupMembershipParam( 'bot', new UserIdentityValue( 1, 'user' ) )
|
||||
);
|
||||
$this->assertSame( '<message key="key">' .
|
||||
|
|
|
|||
Loading…
Reference in a new issue