Merge "Make it possible to disable the "cite_error" wrapper message"

This commit is contained in:
jenkins-bot 2024-05-27 08:16:04 +00:00 committed by Gerrit Code Review
commit 4f8e06b97b
2 changed files with 18 additions and 5 deletions

View file

@ -75,8 +75,9 @@ class ErrorReporter {
$parser->addTrackingCategory( 'cite-tracking-category-cite-error' );
}
// Messages: cite_error, cite_warning
return $this->messageLocalizer->msg( "cite_$type", $msg->plain() )->inLanguage( $language );
// Optional wrapper messages: cite_error, cite_warning
$wrapper = $this->messageLocalizer->msg( "cite_$type", $msg->plain() )->inLanguage( $language );
return $wrapper->isDisabled() ? $msg : $wrapper;
}
/**
@ -116,7 +117,7 @@ class ErrorReporter {
/**
* @param string $messageKey Expected to be a message key like "cite_error_ref_numeric_key"
*
* @return string[] Two elements, e.g. "error" and "ref_too_many_keys"
* @return string[] Two elements, e.g. "error" and "ref_numeric_key"
*/
private function parseTypeAndIdFromMessageKey( string $messageKey ): array {
return array_slice( explode( '_', str_replace( '-', '_', $messageKey ), 3 ), 1 );

View file

@ -31,6 +31,17 @@ class ErrorReporterTest extends \MediaWikiUnitTestCase {
$reporter->plain( $mockParser, $key, 'first param' ) );
}
public function testDisabledWrapperMessages() {
$language = $this->createLanguage();
$reporter = $this->createReporter( $language, true );
$mockParser = $this->createParser( $language );
$this->assertSame(
'<span class="warning mw-ext-cite-warning mw-ext-cite-warning-a" lang="qqx" ' .
'dir="rtl">(cite_warning_a)</span>',
$reporter->plain( $mockParser, 'cite_warning_a' )
);
}
public function testHalfParsed() {
$language = $this->createLanguage();
$reporter = $this->createReporter( $language );
@ -65,11 +76,12 @@ class ErrorReporterTest extends \MediaWikiUnitTestCase {
return $language;
}
private function createReporter( Language $language ): ErrorReporter {
private function createReporter( Language $language, bool $disabled = false ): ErrorReporter {
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
function ( ...$args ) use ( $language ) {
function ( ...$args ) use ( $language, $disabled ) {
$message = $this->createMock( Message::class );
$message->method( 'isDisabled' )->willReturn( $disabled );
$message->method( 'getKey' )->willReturn( $args[0] );
$message->method( 'plain' )->willReturn( '(' . implode( '|', $args ) . ')' );
$message->method( 'inLanguage' )->with( $language )->willReturnSelf();