diff --git a/extension.json b/extension.json index 9907af680..edb4b4a85 100644 --- a/extension.json +++ b/extension.json @@ -213,7 +213,6 @@ "ext.cite.highlighting.css" ], "messages": [ - "cite_reference_link_prefix", "cite_references_link_accessibility_label", "cite_references_link_many_accessibility_label", "cite_references_link_accessibility_back_label" diff --git a/i18n/en.json b/i18n/en.json index 212ccb51a..650e5a8d4 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -40,8 +40,6 @@ "cite_error_empty_references_define": "<ref> tag with name \"$1\" defined in <references> group \"$2\" has no content.", "cite-tracking-category-cite-error": "Pages with reference errors", "cite-tracking-category-cite-error-desc": "Pages in this category have errors in the usage of references tags.", - "cite_reference_link_prefix": "cite_ref-", - "cite_references_link_prefix": "cite_note-", "cite_reference_backlink_symbol": "↑", "cite_reference_link": "[[#$2|[$3]]]", "cite_references_link_one": "
  • [[#$2|↑]] $3
  • ", diff --git a/i18n/qqq.json b/i18n/qqq.json index 6116557a0..9058444d6 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -44,8 +44,6 @@ "cite_error_empty_references_define": "Error message shown when there is a <ref> inside <references>, but it does not have any content, e.g.\n
    \n\n\n\n
    \nParameters:\n* $1 - the name of the erroneous <ref> (in the above example, “foo”)", "cite-tracking-category-cite-error": "{{tracking category name}}\nTracking category name.", "cite-tracking-category-cite-error-desc": "Tracking category description.", - "cite_reference_link_prefix": "{{notranslate}}", - "cite_references_link_prefix": "{{notranslate}}", "cite_reference_backlink_symbol": "{{optional}}\nSymbol used for the reference section, used to link back to where the reference is used.", "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", diff --git a/modules/ext.cite.highlighting.js b/modules/ext.cite.highlighting.js index 82e75daa6..18a0c97b7 100644 --- a/modules/ext.cite.highlighting.js +++ b/modules/ext.cite.highlighting.js @@ -11,10 +11,8 @@ * @return {boolean} */ function isNamedReference( id ) { - const prefix = mw.msg( 'cite_reference_link_prefix' ); - // Note: This assumes IDs start with the prefix; this is guaranteed by the parser function - return /\D/.test( id.slice( prefix.length ) ); + return /^cite_ref-\D/.test( id ); } /** diff --git a/src/AnchorFormatter.php b/src/AnchorFormatter.php index a93dc8e00..354a2ec1f 100644 --- a/src/AnchorFormatter.php +++ b/src/AnchorFormatter.php @@ -12,12 +12,6 @@ use MediaWiki\Parser\Sanitizer; */ class AnchorFormatter { - private ReferenceMessageLocalizer $messageLocalizer; - - public function __construct( ReferenceMessageLocalizer $messageLocalizer ) { - $this->messageLocalizer = $messageLocalizer; - } - /** * Return an id for use in wikitext output based on a key and * optionally the number of it, used in , not @@ -29,11 +23,10 @@ class AnchorFormatter { * @return string */ private function refKey( $key, ?string $num ): string { - $prefix = $this->messageLocalizer->msg( 'cite_reference_link_prefix' )->plain(); if ( $num !== null ) { $key = $key . '_' . $num; } - return $this->normalizeKey( $prefix . $key ); + return $this->normalizeKey( "cite_ref-$key" ); } /** @@ -68,8 +61,7 @@ class AnchorFormatter { * @return string */ private function getReferencesKey( string $key ): string { - $prefix = $this->messageLocalizer->msg( 'cite_references_link_prefix' )->plain(); - return $this->normalizeKey( $prefix . $key ); + return $this->normalizeKey( "cite_note-$key" ); } /** diff --git a/src/Cite.php b/src/Cite.php index a6dce9512..082597392 100644 --- a/src/Cite.php +++ b/src/Cite.php @@ -78,7 +78,7 @@ class Cite { $messageLocalizer = new ReferenceMessageLocalizer( $parser->getContentLanguage() ); $this->errorReporter = new ErrorReporter( $messageLocalizer ); $this->referenceStack = new ReferenceStack(); - $anchorFormatter = new AnchorFormatter( $messageLocalizer ); + $anchorFormatter = new AnchorFormatter(); $this->footnoteMarkFormatter = new FootnoteMarkFormatter( $this->errorReporter, $anchorFormatter, diff --git a/tests/phpunit/ReferenceMessageLocalizerTest.php b/tests/phpunit/ReferenceMessageLocalizerTest.php index 245dad097..acec19739 100644 --- a/tests/phpunit/ReferenceMessageLocalizerTest.php +++ b/tests/phpunit/ReferenceMessageLocalizerTest.php @@ -14,8 +14,8 @@ class ReferenceMessageLocalizerTest extends \MediaWikiIntegrationTestCase { public function testMsg() { $localizer = new ReferenceMessageLocalizer( new LanguageQqx() ); $this->assertSame( - '(cite_reference_link_prefix)', - $localizer->msg( 'cite_reference_link_prefix' )->plain() ); + '(cite-desc)', + $localizer->msg( 'cite-desc' )->plain() ); } } diff --git a/tests/phpunit/integration/AnchorFormatterTest.php b/tests/phpunit/integration/AnchorFormatterTest.php index fad1bf3c0..506349f65 100644 --- a/tests/phpunit/integration/AnchorFormatterTest.php +++ b/tests/phpunit/integration/AnchorFormatterTest.php @@ -3,9 +3,7 @@ namespace Cite\Tests\Integration; use Cite\AnchorFormatter; -use Cite\ReferenceMessageLocalizer; use MediaWiki\Parser\Sanitizer; -use Message; use Wikimedia\TestingAccessWrapper; /** @@ -20,37 +18,21 @@ class AnchorFormatterTest extends \MediaWikiIntegrationTestCase { } public function testRefKey() { - $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); - $mockMessageLocalizer->method( 'msg' )->willReturnCallback( - function ( ...$args ) { - $msg = $this->createMock( Message::class ); - $msg->method( 'plain' )->willReturn( '(' . implode( '|', $args ) . ')' ); - return $msg; - } - ); - $formatter = new AnchorFormatter( $mockMessageLocalizer ); + $formatter = new AnchorFormatter(); $this->assertSame( - '(cite_reference_link_prefix)key', + 'cite_ref-key', $formatter->backLink( 'key', null ) ); $this->assertSame( - '(cite_reference_link_prefix)key_2', + 'cite_ref-key_2', $formatter->backLink( 'key', '2' ) ); } public function testGetReferencesKey() { - $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); - $mockMessageLocalizer->method( 'msg' )->willReturnCallback( - function ( ...$args ) { - $msg = $this->createMock( Message::class ); - $msg->method( 'plain' )->willReturn( '(' . implode( '|', $args ) . ')' ); - return $msg; - } - ); - $formatter = new AnchorFormatter( $mockMessageLocalizer ); + $formatter = new AnchorFormatter(); $this->assertSame( - '(cite_references_link_prefix)key', + 'cite_note-key', $formatter->jumpLink( 'key' ) ); } @@ -59,8 +41,7 @@ class AnchorFormatterTest extends \MediaWikiIntegrationTestCase { */ public function testNormalizeKey( $key, $expected ) { /** @var AnchorFormatter $formatter */ - $formatter = TestingAccessWrapper::newFromObject( new AnchorFormatter( - $this->createMock( ReferenceMessageLocalizer::class ) ) ); + $formatter = TestingAccessWrapper::newFromObject( new AnchorFormatter() ); $normalized = $formatter->normalizeKey( $key ); $encoded = Sanitizer::safeEncodeAttribute( Sanitizer::escapeIdForLink( $normalized ) ); $this->assertSame( $expected, $encoded );