diff --git a/i18n/en.json b/i18n/en.json
index cc99fc3ff..3302a4ce4 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -28,7 +28,6 @@
"cite_error_references_duplicate_key": "Invalid <ref>
tag; name \"$1\" defined multiple times with different content",
"cite_error_references_invalid_parameters": "Invalid parameter in <references>
tag",
"cite_error_references_no_backlink_label": "Ran out of custom backlink labels. Define more in the [[MediaWiki:Cite references link many format backlink labels]] message.",
- "cite_error_no_link_label_group": "Ran out of custom link labels for group \"$1\". Define more in the [[MediaWiki:$2]] message.",
"cite_error_references_no_text": "Invalid <ref>
tag; no text was provided for refs named $1
",
"cite_error_included_ref": "Closing </ref>
missing for <ref>
tag",
"cite_error_included_references": "Closing tag missing for <references>
",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 4f676f064..560c3ce66 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -33,7 +33,6 @@
"cite_error_references_duplicate_key": "Error message shown when multiple refs with same name exist but with different content",
"cite_error_references_invalid_parameters": "Generic error message shown when unknown, unsupported parameters are used in a <references>
tag. This can happen when there is a mistake in a parameter name, or a parameter exclusive to the <ref>
tag is used in a <references>
tag. This and [[MediaWiki:Cite error ref too many keys]] form a pair and should be worded similarly.",
"cite_error_references_no_backlink_label": "Error message shown in the references tag when the same name is used for too many ref tags. Too many in this case is more than there are backlink labels defined in [[MediaWiki:Cite references link many format backlink labels]].\n\nIt is not possible to make a clickable link to this message. \"nowiki\" is mandatory around [[MediaWiki:Cite references link many format backlink labels]].",
- "cite_error_no_link_label_group": "Error message shown when there are more references than custom link markers for a group. Gives an actionable remedy.\n\nParameters:\n* $1 - reference group name\n* $2 - System message name, cite_link_label_group-groupname
",
"cite_error_references_no_text": "This error occurs when the tag <ref name=\"something\"/>
is used with the name-option specified and no other tag specifies a cite-text for this name.\n\nParameters:\n* $1 - key of the ref",
"cite_error_included_ref": "Error message shown if the <ref>
tag is unbalanced, that means a <ref>
is not followed by a </ref>
",
"cite_error_included_references": "Error message shown if a <references>
tag is found inside another.",
diff --git a/src/Cite.php b/src/Cite.php
index ae984447c..b4dd0c609 100644
--- a/src/Cite.php
+++ b/src/Cite.php
@@ -78,7 +78,6 @@ class Cite {
$this->referenceStack = new ReferenceStack();
$anchorFormatter = new AnchorFormatter();
$this->footnoteMarkFormatter = new FootnoteMarkFormatter(
- $this->errorReporter,
$anchorFormatter,
$messageLocalizer
);
diff --git a/src/FootnoteMarkFormatter.php b/src/FootnoteMarkFormatter.php
index 43069852c..32c7c459c 100644
--- a/src/FootnoteMarkFormatter.php
+++ b/src/FootnoteMarkFormatter.php
@@ -17,16 +17,13 @@ class FootnoteMarkFormatter {
private array $linkLabels = [];
private AnchorFormatter $anchorFormatter;
- private ErrorReporter $errorReporter;
private ReferenceMessageLocalizer $messageLocalizer;
public function __construct(
- ErrorReporter $errorReporter,
AnchorFormatter $anchorFormatter,
ReferenceMessageLocalizer $messageLocalizer
) {
$this->anchorFormatter = $anchorFormatter;
- $this->errorReporter = $errorReporter;
$this->messageLocalizer = $messageLocalizer;
}
@@ -41,7 +38,7 @@ class FootnoteMarkFormatter {
* @return string HTML
*/
public function linkRef( Parser $parser, ReferenceStackItem $ref ): string {
- $label = $this->makeLabel( $ref, $parser );
+ $label = $this->makeLabel( $ref->group, $ref->number, $ref->extendsIndex );
$key = $ref->name ?? $ref->key;
// TODO: Use count without decrementing.
@@ -58,18 +55,19 @@ class FootnoteMarkFormatter {
);
}
- private function makeLabel( ReferenceStackItem $ref, Parser $parser ): string {
- $label = $this->fetchCustomizedLinkLabel( $parser, $ref->group, $ref->number ) ??
- $this->makeDefaultLabel( $ref );
- if ( $ref->extendsIndex !== null ) {
- $label .= '.' . $this->messageLocalizer->localizeDigits( (string)$ref->extendsIndex );
+ public function makeLabel( string $group, int $number, ?int $extendsIndex = null ): string {
+ $label = $this->fetchCustomizedLinkLabel( $group, $number ) ??
+ $this->makeDefaultLabel( $group, $number );
+ if ( $extendsIndex !== null ) {
+ // TODO: design better behavior, especially when using custom group markers.
+ $label .= '.' . $this->messageLocalizer->localizeDigits( (string)$extendsIndex );
}
return $label;
}
- private function makeDefaultLabel( ReferenceStackItem $ref ): string {
- $label = $this->messageLocalizer->localizeDigits( (string)$ref->number );
- return $ref->group === Cite::DEFAULT_GROUP ? $label : "$ref->group $label";
+ public function makeDefaultLabel( string $group, int $number ): string {
+ $label = $this->messageLocalizer->localizeDigits( (string)$number );
+ return $group === Cite::DEFAULT_GROUP ? $label : "$group $label";
}
/**
@@ -78,13 +76,12 @@ class FootnoteMarkFormatter {
* [ 'a', 'b', 'c', ...].
* Return an error if the offset > the # of array items
*
- * @param Parser $parser
- * @param string $group The group name
- * @param int $number Expected to start at 1
+ * @param string $group
+ * @param int $number
*
- * @return string|null Returns null if no custom labels for this group exist
+ * @return ?string Returns null if no custom label can be found
*/
- private function fetchCustomizedLinkLabel( Parser $parser, string $group, int $number ): ?string {
+ private function fetchCustomizedLinkLabel( string $group, int $number ): ?string {
if ( $group === Cite::DEFAULT_GROUP ) {
return null;
}
@@ -101,12 +98,7 @@ class FootnoteMarkFormatter {
}
// Error message in case we run out of custom labels
- return $this->linkLabels[$group][$number - 1] ?? $this->errorReporter->plain(
- $parser,
- 'cite_error_no_link_label_group',
- $group,
- $message
- );
+ return $this->linkLabels[$group][$number - 1] ?? null;
}
}
diff --git a/tests/phpunit/integration/FootnoteMarkFormatterTest.php b/tests/phpunit/integration/FootnoteMarkFormatterTest.php
index 6346d1a64..d2c7aa83b 100644
--- a/tests/phpunit/integration/FootnoteMarkFormatterTest.php
+++ b/tests/phpunit/integration/FootnoteMarkFormatterTest.php
@@ -4,7 +4,6 @@ namespace Cite\Tests\Integration;
use Cite\AnchorFormatter;
use Cite\Cite;
-use Cite\ErrorReporter;
use Cite\FootnoteMarkFormatter;
use Cite\ReferenceMessageLocalizer;
use Cite\Tests\TestUtils;
@@ -22,10 +21,6 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
* @dataProvider provideLinkRef
*/
public function testLinkRef( array $ref, string $expectedOutput ) {
- $mockErrorReporter = $this->createMock( ErrorReporter::class );
- $mockErrorReporter->method( 'plain' )->willReturnCallback(
- static fn ( $parser, ...$args ) => implode( '|', $args )
- );
$anchorFormatter = $this->createMock( AnchorFormatter::class );
$anchorFormatter->method( 'jumpLink' )->willReturnArgument( 0 );
$anchorFormatter->method( 'backLinkTarget' )->willReturnCallback(
@@ -49,7 +44,6 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
$mockParser = $this->createNoOpMock( Parser::class, [ 'recursiveTagParse' ] );
$mockParser->method( 'recursiveTagParse' )->willReturnArgument( 0 );
$formatter = new FootnoteMarkFormatter(
- $mockErrorReporter,
$anchorFormatter,
$messageLocalizer
);
@@ -95,8 +89,7 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
'number' => 10,
'key' => 4,
],
- '(cite_reference_link|4+|4|' .
- 'cite_error_no_link_label_group|foo|cite_link_label_group-foo)'
+ '(cite_reference_link|4+|4|foo 10)'
],
'Named ref' => [
[
@@ -145,19 +138,13 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
return $msg;
}
);
- $mockErrorReporter = $this->createMock( ErrorReporter::class );
- $mockErrorReporter->method( 'plain' )->willReturnCallback(
- static fn ( $parser, ...$args ) => implode( '|', $args )
- );
/** @var FootnoteMarkFormatter $formatter */
$formatter = TestingAccessWrapper::newFromObject( new FootnoteMarkFormatter(
- $mockErrorReporter,
$this->createMock( AnchorFormatter::class ),
$mockMessageLocalizer
) );
- $parser = $this->createNoOpMock( Parser::class );
- $output = $formatter->fetchCustomizedLinkLabel( $parser, $group, $offset );
+ $output = $formatter->fetchCustomizedLinkLabel( $group, $offset );
$this->assertSame( $expectedLabel, $output );
}
@@ -169,20 +156,18 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
yield [ 'a', 1, 'foo', 'a b c' ];
yield [ 'b', 2, 'foo', 'a b c' ];
yield [ 'å', 1, 'foo', 'å β' ];
- yield [ 'cite_error_no_link_label_group|foo|cite_link_label_group-foo', 4, 'foo', 'a b c' ];
+ yield [ null, 4, 'foo', 'a b c' ];
}
public function testDefaultGroupCannotHaveCustomLinkLabels() {
/** @var FootnoteMarkFormatter $formatter */
$formatter = TestingAccessWrapper::newFromObject( new FootnoteMarkFormatter(
- $this->createNoOpMock( ErrorReporter::class ),
$this->createNoOpMock( AnchorFormatter::class ),
// Assert that ReferenceMessageLocalizer::msg( 'cite_link_label_group-' ) isn't called
$this->createNoOpMock( ReferenceMessageLocalizer::class )
) );
- $parser = $this->createNoOpMock( Parser::class );
- $this->assertNull( $formatter->fetchCustomizedLinkLabel( $parser, Cite::DEFAULT_GROUP, 1 ) );
+ $this->assertNull( $formatter->fetchCustomizedLinkLabel( Cite::DEFAULT_GROUP, 1 ) );
}
}