mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-11 16:49:26 +00:00
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:
parent
8a6993ccd9
commit
1aeac001fe
|
@ -174,9 +174,12 @@ class Cite {
|
||||||
// @phan-suppress-next-line PhanParamTooFewUnpack No good way to document it.
|
// @phan-suppress-next-line PhanParamTooFewUnpack No good way to document it.
|
||||||
$ref = $this->referenceStack->pushRef(
|
$ref = $this->referenceStack->pushRef(
|
||||||
$parser->getStripState(), $text, $argv, ...array_values( $arguments ) );
|
$parser->getStripState(), $text, $argv, ...array_values( $arguments ) );
|
||||||
return $ref
|
if ( !$ref ) {
|
||||||
? $this->footnoteMarkFormatter->linkRef( $parser, $ref )
|
// Rare edge-cases like follow="…" don't render a footnote marker in-place
|
||||||
: '';
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->footnoteMarkFormatter->linkRef( $parser, $ref );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -129,6 +129,73 @@ wgCiteBookReferencing=true
|
||||||
</p>
|
</p>
|
||||||
!! end
|
!! 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">[1]</a></sup>
|
||||||
|
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code><ref></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><ref></code> tag with name "book" defined in <code><references></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">[1]</a></sup>
|
||||||
|
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code><ref></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><ref></code> tag with name "book" defined in <code><references></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">[1]</a></sup>
|
||||||
|
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code><ref></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><ref></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><ref></code> tag with name "book" defined in <code><references></code> is not used in prior text.</span>
|
||||||
|
</p>
|
||||||
|
!! end
|
||||||
|
|
||||||
!! test
|
!! test
|
||||||
T236256 - Naming book references is fine
|
T236256 - Naming book references is fine
|
||||||
!! config
|
!! config
|
||||||
|
|
Loading…
Reference in a new issue