Additional parser test cases for delayed extends usage

We want it to be possible to turn a <ref> 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: <ref name=x/> is a short re-use of a ref that later
turns out to be a <ref extends=… name=x>…</ref>.

<ref name=x></ref> is just another syntax that should behave
identical.

However, it should probably not be possible to turn
<ref name=x>foo</ref> into a subref later because it really, really
looks like a normal ref. Even if the content matches with a later
<ref extends=… name=x>foo</ref> 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
This commit is contained in:
thiemowmde 2024-06-20 18:22:08 +02:00 committed by WMDE-Fisch
parent 8a6993ccd9
commit 1aeac001fe
2 changed files with 73 additions and 3 deletions

View file

@ -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 );
}
/**

View file

@ -129,6 +129,73 @@ wgCiteBookReferencing=true
</p>
!! 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
<ref name=p20>page 20</ref>
<ref extends=book name=p20>page 20</ref>
<references>
<ref name=book>book</ref>
</references>
!! html
<p><sup id="cite_ref-p20_1-0" class="reference"><a href="#cite_note-p20-1">&#91;1&#93;</a></sup>
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code>&lt;ref&gt;</code> tag; name "p20" defined multiple times with different content</span>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-p20-1"><span class="mw-cite-backlink"><a href="#cite_ref-p20_1-0">↑</a></span> <span class="reference-text">page 20</span>
</li>
</ol></div>
<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: <code>&lt;ref&gt;</code> tag with name "book" defined in <code>&lt;references&gt;</code> is not used in prior text.</span>
</p>
!! end
!! test
T367749 - Turning a top-level ref into a subref is forbidden, especially when the content conflicts
!! config
wgCiteBookReferencing=true
!! wikitext
<ref name=p20>page 20</ref>
<ref extends=book name=p20>different content</ref>
<references>
<ref name=book>book</ref>
</references>
!! html
<p><sup id="cite_ref-p20_1-0" class="reference"><a href="#cite_note-p20-1">&#91;1&#93;</a></sup>
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code>&lt;ref&gt;</code> tag; name "p20" defined multiple times with different content</span>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-p20-1"><span class="mw-cite-backlink"><a href="#cite_ref-p20_1-0">↑</a></span> <span class="reference-text">page 20</span>
</li>
</ol></div>
<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: <code>&lt;ref&gt;</code> tag with name "book" defined in <code>&lt;references&gt;</code> is not used in prior text.</span>
</p>
!! 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
<ref name=p20></ref>
<ref extends=book name=p20>page 20</ref>
<references>
<ref name=book>book</ref>
</references>
!! html
<p><sup id="cite_ref-p20_1-0" class="reference"><a href="#cite_note-p20-1">&#91;1&#93;</a></sup>
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code>&lt;ref&gt;</code> tag; name "p20" defined multiple times with different content</span>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-p20-1"><span class="mw-cite-backlink"><a href="#cite_ref-p20_1-0">↑</a></span> <span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code>&lt;ref&gt;</code> tag; no text was provided for refs named <code>p20</code></span></li>
</ol></div>
<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: <code>&lt;ref&gt;</code> tag with name "book" defined in <code>&lt;references&gt;</code> is not used in prior text.</span>
</p>
!! end
!! test
T236256 - Naming book references is fine
!! config