diff --git a/i18n/qqq.json b/i18n/qqq.json index 27080f038..cfe49e759 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -57,8 +57,8 @@ "cite_reference_link": "{{notranslate}}\n\nParameters:\n* $1 - ref key\n* $2 - references key\n* $3 - link label", "cite_references_link_one": "{{notranslate}}\n\nParameters:\n* $1 - references key\n* $2 - ref key\n* $3 - reference text\n* $4 - optional CSS class for direction", "cite_references_link_many": "{{notranslate}}\n\nParameters:\n* $1 - references key\n* $2 - list of links\n* $3 - reference text\n* $4 - optional CSS class for direction", - "cite_references_link_many_format": "{{notranslate}}\n\nParameters:\n* $1 - reference key\n* $2 - canonical numeric backlink label for the link, always in the form \"1.2\"\n* $3 - optional alternate backlink label as defined via [[MediaWiki:cite_references_link_many_format_backlink_labels]]", - "cite_references_link_many_format_backlink_labels": "{{Optional}}", + "cite_references_link_many_format": "{{notranslate}}\n\nParameters:\n* $1 - Reference key\n* $2 - Canonical numerical label for the backlink, always in the form \"1.1\", \"1.2\", and so on.\n* $3 - Alternative alphabetic label for the backlink as defined via [[MediaWiki:cite_references_link_many_format_backlink_labels]], typically \"a\", \"b\", and so on.", + "cite_references_link_many_format_backlink_labels": "{{optional}}\nAlternative alphabetic backlink labels for use in the [[MediaWiki:cite_references_link_many_format]] message as parameter $3. Should only be customized when the alphabet is not identical to the 26 basic Latin characters \"a\" to \"z\". Make sure to include at least as many labels as in the default sequence \"a\" to \"zz\" (702 labels), possibly even more. E.g. adding \"aaa\" to \"azz\" gives 1378 total. This message can be disabled if not needed.", "cite_references_link_many_sep": "{{notranslate}}", "cite_references_link_many_and": "{{optional}}", "cite_references_link_accessibility_label": "Text for screen readers to describe the jump to citation link (\"↑\").\n\nSee also:\n* {{msg-mw|Cite references link many accessibility label}} - if the citation is used multiple times", diff --git a/src/ReferenceListFormatter.php b/src/ReferenceListFormatter.php index e07cfba89..82311a347 100644 --- a/src/ReferenceListFormatter.php +++ b/src/ReferenceListFormatter.php @@ -184,16 +184,16 @@ class ReferenceListFormatter { // Named references with >1 occurrences $backlinks = []; for ( $i = 0; $i < $ref->count; $i++ ) { + $numericLabel = $this->referencesFormatEntryNumericBacklinkLabel( + $ref->number . ( $ref->extendsIndex ? '.' . $ref->extendsIndex : '' ), + $i, + $ref->count + ); $backlinks[] = $this->messageLocalizer->msg( 'cite_references_link_many_format', $this->anchorFormatter->backLink( $key, $ref->key . '-' . $i ), - $this->referencesFormatEntryNumericBacklinkLabel( - $ref->number . - ( isset( $ref->extendsIndex ) ? '.' . $ref->extendsIndex : '' ), - $i, - $ref->count - ), - $this->referencesFormatEntryAlternateBacklinkLabel( $parser, $i ) + $numericLabel, + $this->referencesFormatEntryAlternateBacklinkLabel( $parser, $i ) ?? $numericLabel )->plain(); } $linkTargetId = $ref->count > 0 ? @@ -267,12 +267,16 @@ class ReferenceListFormatter { */ private function referencesFormatEntryAlternateBacklinkLabel( Parser $parser, int $offset - ): string { - $this->backlinkLabels ??= preg_split( - '/\s+/', - $this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' ) - ->plain() - ); + ): ?string { + if ( !isset( $this->backlinkLabels ) ) { + $msg = $this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' ); + $this->backlinkLabels = $msg->isDisabled() ? [] : preg_split( '/\s+/', $msg->plain() ); + } + + // Disabling the message just disables the feature + if ( !$this->backlinkLabels ) { + return null; + } return $this->backlinkLabels[$offset] ?? $this->errorReporter->plain( $parser, 'cite_error_references_no_backlink_label' ); diff --git a/tests/phpunit/unit/ReferenceListFormatterTest.php b/tests/phpunit/unit/ReferenceListFormatterTest.php index 765d88fb2..04b3b7baa 100644 --- a/tests/phpunit/unit/ReferenceListFormatterTest.php +++ b/tests/phpunit/unit/ReferenceListFormatterTest.php @@ -353,7 +353,8 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase { public function testReferencesFormatEntryAlternateBacklinkLabel( ?string $expectedLabel, string $labelList, int $offset ) { - $mockMessage = $this->createNoOpMock( Message::class, [ 'plain' ] ); + $mockMessage = $this->createNoOpMock( Message::class, [ 'isDisabled', 'plain' ] ); + $mockMessage->method( 'isDisabled' )->willReturn( !$labelList ); $mockMessage->method( 'plain' )->willReturn( $labelList ); $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); @@ -361,8 +362,7 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase { ->willReturn( $mockMessage ); $errorReporter = $this->createMock( ErrorReporter::class ); - $errorReporter->expects( $expectedLabel ? $this->never() : $this->once() ) - ->method( 'plain' ); + $errorReporter->method( 'plain' )->willReturnArgument( 1 ); /** @var ReferenceListFormatter $formatter */ $formatter = TestingAccessWrapper::newFromObject( new ReferenceListFormatter( @@ -373,16 +373,15 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase { $parser = $this->createNoOpMock( Parser::class ); $label = $formatter->referencesFormatEntryAlternateBacklinkLabel( $parser, $offset ); - if ( $expectedLabel !== null ) { - $this->assertSame( $expectedLabel, $label ); - } + $this->assertSame( $expectedLabel, $label ); } public static function provideReferencesFormatEntryAlternateBacklinkLabel() { yield [ 'aa', 'aa ab ac', 0 ]; yield [ 'ab', 'aa ab ac', 1 ]; yield [ 'å', 'å b c', 0 ]; - yield [ null, 'a b c', 10 ]; + yield [ 'cite_error_references_no_backlink_label', 'a b c', 10 ]; + yield [ null, '', 0 ]; } /**