The old code was similar to Message::params(), but Message::params()
was unable to handle "special" parameters and received an overhaul
in
7f2663f, yet wfMessage remained broken. To avoid duplication,
wfMessage shall call Message::params() to correctly handle these
parameters.
CategoryMembershipChange::getChangeMessageText and its caller has
been updated so as not to take advantage of this bug.
Bug: T153747
Change-Id: I6667acf7e71c9db07fefc9fbb741c160e15823ff
* @see Message::__construct
*/
function wfMessage( $key /*...*/ ) {
+ $message = new Message( $key );
+
+ // We call Message::params() to reduce code duplication
$params = func_get_args();
array_shift( $params );
- if ( isset( $params[0] ) && is_array( $params[0] ) ) {
- $params = $params[0];
+ if ( $params ) {
+ call_user_func_array( [ $message, 'params' ], $params );
}
- return new Message( $key, $params );
+
+ return $message;
}
/**
$this->getUser(),
$this->getChangeMessageText(
$type,
- [ 'prefixedText' => $this->pageTitle->getPrefixedText() ],
+ $this->pageTitle->getPrefixedText(),
$this->numTemplateLinks
),
$this->pageTitle,
*
* @param int $type may be CategoryMembershipChange::CATEGORY_ADDITION
* or CategoryMembershipChange::CATEGORY_REMOVAL
- * @param array $params
- * - prefixedText: result of Title::->getPrefixedText()
+ * @param string $prefixedText result of Title::->getPrefixedText()
* @param int $numTemplateLinks
*
* @return string
*/
- private function getChangeMessageText( $type, array $params, $numTemplateLinks ) {
+ private function getChangeMessageText( $type, $prefixedText, $numTemplateLinks ) {
$array = [
self::CATEGORY_ADDITION => 'recentchanges-page-added-to-category',
self::CATEGORY_REMOVAL => 'recentchanges-page-removed-from-category',
$msgKey .= '-bundled';
}
- return wfMessage( $msgKey, $params )->inContentLanguage()->text();
+ return wfMessage( $msgKey, $prefixedText )->inContentLanguage()->text();
}
/**
public function testWfMessageParams() {
$this->assertSame( 'Return to $1.', wfMessage( 'returnto' )->text() );
$this->assertSame( 'Return to $1.', wfMessage( 'returnto', [] )->text() );
+ $this->assertSame(
+ 'Return to 1,024.',
+ wfMessage( 'returnto', Message::numParam( 1024 ) )->text()
+ );
+ $this->assertSame(
+ 'Return to 1,024.',
+ wfMessage( 'returnto', [ Message::numParam( 1024 ) ] )->text()
+ );
$this->assertSame(
'You have foo (bar).',
wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text()
'You have foo (bar).',
wfMessage( 'youhavenewmessages', [ 'foo', 'bar' ] )->text()
);
+ $this->assertSame(
+ 'You have 1,024 (bar).',
+ wfMessage(
+ 'youhavenewmessages',
+ Message::numParam( 1024 ), 'bar'
+ )->text()
+ );
+ $this->assertSame(
+ 'You have foo (2,048).',
+ wfMessage(
+ 'youhavenewmessages',
+ 'foo', Message::numParam( 2048 )
+ )->text()
+ );
+ $this->assertSame(
+ 'You have 1,024 (2,048).',
+ wfMessage(
+ 'youhavenewmessages',
+ [ Message::numParam( 1024 ), Message::numParam( 2048 ) ]
+ )->text()
+ );
}
/**