Merge "No expensive transformations on prefix/suffix messages"

This commit is contained in:
jenkins-bot 2023-07-21 13:22:35 +00:00 committed by Gerrit Code Review
commit bceaf47597
2 changed files with 9 additions and 10 deletions

View file

@ -26,8 +26,8 @@ class AnchorFormatter {
* @return string A key for use in wikitext
*/
public function refKey( string $key, string $num = null ): string {
$prefix = $this->messageLocalizer->msg( 'cite_reference_link_prefix' )->text();
$suffix = $this->messageLocalizer->msg( 'cite_reference_link_suffix' )->text();
$prefix = $this->messageLocalizer->msg( 'cite_reference_link_prefix' )->plain();
$suffix = $this->messageLocalizer->msg( 'cite_reference_link_suffix' )->plain();
if ( $num !== null ) {
$key = $this->messageLocalizer->msg( 'cite_reference_link_key_with_num', $key, $num )
->plain();
@ -46,8 +46,8 @@ class AnchorFormatter {
* @return string A key for use in wikitext
*/
public function getReferencesKey( string $key ): string {
$prefix = $this->messageLocalizer->msg( 'cite_references_link_prefix' )->text();
$suffix = $this->messageLocalizer->msg( 'cite_references_link_suffix' )->text();
$prefix = $this->messageLocalizer->msg( 'cite_references_link_prefix' )->plain();
$suffix = $this->messageLocalizer->msg( 'cite_references_link_suffix' )->plain();
return $this->normalizeKey( $prefix . $key . $suffix );
}

View file

@ -29,19 +29,18 @@ class AnchorFormatterTest extends \MediaWikiIntegrationTestCase {
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
function ( ...$args ) {
$msg = $this->createMock( Message::class );
$msg->method( 'plain' )->willReturn( '(plain:' . implode( '|', $args ) . ')' );
$msg->method( 'text' )->willReturn( '(text:' . implode( '|', $args ) . ')' );
$msg->method( 'plain' )->willReturn( '(' . implode( '|', $args ) . ')' );
return $msg;
}
);
$formatter = new AnchorFormatter( $mockMessageLocalizer );
$this->assertSame(
'(text:cite_reference_link_prefix)key(text:cite_reference_link_suffix)',
'(cite_reference_link_prefix)key(cite_reference_link_suffix)',
$formatter->refKey( 'key', null ) );
$this->assertSame(
'(text:cite_reference_link_prefix)' .
'(plain:cite_reference_link_key_with_num|key|2)(text:cite_reference_link_suffix)',
'(cite_reference_link_prefix)' .
'(cite_reference_link_key_with_num|key|2)(cite_reference_link_suffix)',
$formatter->refKey( 'key', '2' ) );
}
@ -53,7 +52,7 @@ class AnchorFormatterTest extends \MediaWikiIntegrationTestCase {
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
function ( ...$args ) {
$msg = $this->createMock( Message::class );
$msg->method( 'text' )->willReturn( '(' . implode( '|', $args ) . ')' );
$msg->method( 'plain' )->willReturn( '(' . implode( '|', $args ) . ')' );
return $msg;
}
);