From 1aeac001fe7ab122e3586ddd965c99e57cac3263 Mon Sep 17 00:00:00 2001
From: thiemowmde
Date: Thu, 20 Jun 2024 18:22:08 +0200
Subject: [PATCH] Additional parser test cases for delayed extends usage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We want it to be possible to turn a [ into an extended one after
it was re-used for the first time, not knowing if it later turns out
to be an extended ref.
This should work: ][ is a short re-use of a ref that later
turns out to be a ][…].
is just another syntax that should behave
identical.
However, it should probably not be possible to turn
[foo] into a subref later because it really, really
looks like a normal ref. Even if the content matches with a later
[foo] and we usually ignore identical
content, I suggest to block this with a dedicated error message. But
this is for a later patch. This patch here just documents the status
quo.
This patch also contains minor code cleanups that will be useful in
Ia752a7d.
Bug: T367749
Change-Id: Ie38769b36e5c476b96e7af7f03b0fc800b32ba97
---
src/Cite.php | 9 +++--
tests/parser/bookReferencing.txt | 67 ++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/src/Cite.php b/src/Cite.php
index 04de7195f..89acd94ba 100644
--- a/src/Cite.php
+++ b/src/Cite.php
@@ -174,9 +174,12 @@ class Cite {
// @phan-suppress-next-line PhanParamTooFewUnpack No good way to document it.
$ref = $this->referenceStack->pushRef(
$parser->getStripState(), $text, $argv, ...array_values( $arguments ) );
- return $ref
- ? $this->footnoteMarkFormatter->linkRef( $parser, $ref )
- : '';
+ if ( !$ref ) {
+ // Rare edge-cases like follow="…" don't render a footnote marker in-place
+ return '';
+ }
+
+ return $this->footnoteMarkFormatter->linkRef( $parser, $ref );
}
/**
diff --git a/tests/parser/bookReferencing.txt b/tests/parser/bookReferencing.txt
index 641243a25..6b483dbf1 100644
--- a/tests/parser/bookReferencing.txt
+++ b/tests/parser/bookReferencing.txt
@@ -129,6 +129,73 @@ wgCiteBookReferencing=true
!! end
+# TODO: T367749 - We are misusing an existing error message here that is super confusing
+!! test
+T367749 - Turning a top-level ref into a subref is forbidden, even if the content is the same
+!! config
+wgCiteBookReferencing=true
+!! wikitext
+[page 20]
+[page 20]
+
+[book]
+
+!! html
+[1]
+Cite error: Invalid <ref>
tag; name "p20" defined multiple times with different content
+
+
+Cite error: <ref>
tag with name "book" defined in <references>
is not used in prior text.
+
+!! end
+
+!! test
+T367749 - Turning a top-level ref into a subref is forbidden, especially when the content conflicts
+!! config
+wgCiteBookReferencing=true
+!! wikitext
+[page 20]
+[different content]
+
+[book]
+
+!! html
+[1]
+Cite error: Invalid <ref>
tag; name "p20" defined multiple times with different content
+
+
+Cite error: <ref>
tag with name "book" defined in <references>
is not used in prior text.
+
+!! end
+
+# TODO: T367749 - We want this to render successfully
+!! test
+T367749 - Turning a top-level ref into a subref is fine when the content is an empty string
+!! config
+wgCiteBookReferencing=true
+!! wikitext
+
+[page 20]
+
+[book]
+
+!! html
+[1]
+Cite error: Invalid <ref>
tag; name "p20" defined multiple times with different content
+
+
+- ↑ Cite error: Invalid
<ref>
tag; no text was provided for refs named p20
+
+Cite error: <ref>
tag with name "book" defined in <references>
is not used in prior text.
+
+!! end
+
!! test
T236256 - Naming book references is fine
!! config