mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-27 16:30:12 +00:00
Merge "Allow disabling the alternative backlink labels message"
This commit is contained in:
commit
1116cfb9a9
|
@ -57,8 +57,8 @@
|
||||||
"cite_reference_link": "{{notranslate}}\n\nParameters:\n* $1 - ref key\n* $2 - references key\n* $3 - link label",
|
"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_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": "{{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": "{{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}}",
|
"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_sep": "{{notranslate}}",
|
||||||
"cite_references_link_many_and": "{{optional}}",
|
"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",
|
"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",
|
||||||
|
|
|
@ -184,16 +184,16 @@ class ReferenceListFormatter {
|
||||||
|
|
||||||
$backlinks = [];
|
$backlinks = [];
|
||||||
for ( $i = 0; $i < $ref->count; $i++ ) {
|
for ( $i = 0; $i < $ref->count; $i++ ) {
|
||||||
|
$numericLabel = $this->referencesFormatEntryNumericBacklinkLabel(
|
||||||
|
$ref->number . ( $ref->extendsIndex ? '.' . $ref->extendsIndex : '' ),
|
||||||
|
$i,
|
||||||
|
$ref->count
|
||||||
|
);
|
||||||
$backlinks[] = $this->messageLocalizer->msg(
|
$backlinks[] = $this->messageLocalizer->msg(
|
||||||
'cite_references_link_many_format',
|
'cite_references_link_many_format',
|
||||||
$this->anchorFormatter->backLink( $key, $ref->key . '-' . $i ),
|
$this->anchorFormatter->backLink( $key, $ref->key . '-' . $i ),
|
||||||
$this->referencesFormatEntryNumericBacklinkLabel(
|
$numericLabel,
|
||||||
$ref->number .
|
$this->referencesFormatEntryAlternateBacklinkLabel( $parser, $i ) ?? $numericLabel
|
||||||
( isset( $ref->extendsIndex ) ? '.' . $ref->extendsIndex : '' ),
|
|
||||||
$i,
|
|
||||||
$ref->count
|
|
||||||
),
|
|
||||||
$this->referencesFormatEntryAlternateBacklinkLabel( $parser, $i )
|
|
||||||
)->plain();
|
)->plain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,12 +269,16 @@ class ReferenceListFormatter {
|
||||||
*/
|
*/
|
||||||
private function referencesFormatEntryAlternateBacklinkLabel(
|
private function referencesFormatEntryAlternateBacklinkLabel(
|
||||||
Parser $parser, int $offset
|
Parser $parser, int $offset
|
||||||
): string {
|
): ?string {
|
||||||
$this->backlinkLabels ??= preg_split(
|
if ( !isset( $this->backlinkLabels ) ) {
|
||||||
'/\s+/',
|
$msg = $this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' );
|
||||||
$this->messageLocalizer->msg( 'cite_references_link_many_format_backlink_labels' )
|
$this->backlinkLabels = $msg->isDisabled() ? [] : preg_split( '/\s+/', $msg->plain() );
|
||||||
->plain()
|
}
|
||||||
);
|
|
||||||
|
// Disabling the message just disables the feature
|
||||||
|
if ( !$this->backlinkLabels ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->backlinkLabels[$offset]
|
return $this->backlinkLabels[$offset]
|
||||||
?? $this->errorReporter->plain( $parser, 'cite_error_references_no_backlink_label' );
|
?? $this->errorReporter->plain( $parser, 'cite_error_references_no_backlink_label' );
|
||||||
|
|
|
@ -353,7 +353,8 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase {
|
||||||
public function testReferencesFormatEntryAlternateBacklinkLabel(
|
public function testReferencesFormatEntryAlternateBacklinkLabel(
|
||||||
?string $expectedLabel, string $labelList, int $offset
|
?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 );
|
$mockMessage->method( 'plain' )->willReturn( $labelList );
|
||||||
|
|
||||||
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
||||||
|
@ -361,8 +362,7 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase {
|
||||||
->willReturn( $mockMessage );
|
->willReturn( $mockMessage );
|
||||||
|
|
||||||
$errorReporter = $this->createMock( ErrorReporter::class );
|
$errorReporter = $this->createMock( ErrorReporter::class );
|
||||||
$errorReporter->expects( $expectedLabel ? $this->never() : $this->once() )
|
$errorReporter->method( 'plain' )->willReturnArgument( 1 );
|
||||||
->method( 'plain' );
|
|
||||||
|
|
||||||
/** @var ReferenceListFormatter $formatter */
|
/** @var ReferenceListFormatter $formatter */
|
||||||
$formatter = TestingAccessWrapper::newFromObject( new ReferenceListFormatter(
|
$formatter = TestingAccessWrapper::newFromObject( new ReferenceListFormatter(
|
||||||
|
@ -373,16 +373,15 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase {
|
||||||
|
|
||||||
$parser = $this->createNoOpMock( Parser::class );
|
$parser = $this->createNoOpMock( Parser::class );
|
||||||
$label = $formatter->referencesFormatEntryAlternateBacklinkLabel( $parser, $offset );
|
$label = $formatter->referencesFormatEntryAlternateBacklinkLabel( $parser, $offset );
|
||||||
if ( $expectedLabel !== null ) {
|
$this->assertSame( $expectedLabel, $label );
|
||||||
$this->assertSame( $expectedLabel, $label );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function provideReferencesFormatEntryAlternateBacklinkLabel() {
|
public static function provideReferencesFormatEntryAlternateBacklinkLabel() {
|
||||||
yield [ 'aa', 'aa ab ac', 0 ];
|
yield [ 'aa', 'aa ab ac', 0 ];
|
||||||
yield [ 'ab', 'aa ab ac', 1 ];
|
yield [ 'ab', 'aa ab ac', 1 ];
|
||||||
yield [ 'å', 'å b c', 0 ];
|
yield [ 'å', 'å b c', 0 ];
|
||||||
yield [ null, 'a b c', 10 ];
|
yield [ 'cite_error_references_no_backlink_label', 'a b c', 10 ];
|
||||||
|
yield [ null, '', 0 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue