mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-28 00:40:12 +00:00
Detect duplicate <ref> definitions inside <references> too
For some reason there's an entirely separate function generating the ref in this case. This changes the behavior (in addition to adding the error message): now the contents of the first <ref> with the same name inside <references> are displayed, not the last. (This was already the case for <ref>s outside <references>.) Bug: T116377 Change-Id: I81b64ccd8a2e58f3b25938a63b8ad5967fe2a2c0
This commit is contained in:
parent
831d2d6367
commit
9aa7961c60
|
@ -234,10 +234,16 @@ class Cite {
|
||||||
# Called with name attribute not defined in text.
|
# Called with name attribute not defined in text.
|
||||||
$this->mReferencesErrors[] =
|
$this->mReferencesErrors[] =
|
||||||
$this->error( 'cite_error_references_missing_key', $key );
|
$this->error( 'cite_error_references_missing_key', $key );
|
||||||
|
} else {
|
||||||
|
if ( isset( $this->mRefs[$group][$key]['text'] ) && $str !== $this->mRefs[$group][$key]['text'] ) {
|
||||||
|
// two refs with same key and different content
|
||||||
|
// add error message to the original ref
|
||||||
|
$this->mRefs[$group][$key]['text'] .= ' ' . $this->error( 'cite_error_references_duplicate_key', $key, 'noparse' );
|
||||||
} else {
|
} else {
|
||||||
# Assign the text to corresponding ref
|
# Assign the text to corresponding ref
|
||||||
$this->mRefs[$group][$key]['text'] = $str;
|
$this->mRefs[$group][$key]['text'] = $str;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
# <ref> called in <references> has no content.
|
# <ref> called in <references> has no content.
|
||||||
$this->mReferencesErrors[] =
|
$this->mReferencesErrors[] =
|
||||||
|
|
|
@ -532,3 +532,55 @@ Page one.<ref name="the-name" follow="the-name">This ref is invalid.</ref>
|
||||||
invalid names, e.g. too many</strong>
|
invalid names, e.g. too many</strong>
|
||||||
</p>
|
</p>
|
||||||
!! end
|
!! end
|
||||||
|
|
||||||
|
!! test
|
||||||
|
Multiple definition (outside <references/>)
|
||||||
|
!! input
|
||||||
|
<ref name=a>abc</ref>
|
||||||
|
<ref name=a>def</ref>
|
||||||
|
<references />
|
||||||
|
!! result
|
||||||
|
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">[1]</a></sup>
|
||||||
|
<sup id="cite_ref-a_1-1" class="reference"><a href="#cite_note-a-1">[1]</a></sup>
|
||||||
|
</p>
|
||||||
|
<ol class="references">
|
||||||
|
<li id="cite_note-a-1"><span class="mw-cite-backlink">↑ <sup><a href="#cite_ref-a_1-0">1.0</a></sup> <sup><a href="#cite_ref-a_1-1">1.1</a></sup></span> <span class="reference-text">abc <strong class="error mw-ext-cite-error">Cite error: Invalid <code><ref></code> tag; name "a" defined multiple times with different content</strong></span>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
!! end
|
||||||
|
|
||||||
|
!! test
|
||||||
|
Multiple definition (inside <references/>)
|
||||||
|
!! input
|
||||||
|
<ref name=a />
|
||||||
|
<references>
|
||||||
|
<ref name=a>abc</ref>
|
||||||
|
<ref name=a>def</ref>
|
||||||
|
</references>
|
||||||
|
!! result
|
||||||
|
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">[1]</a></sup>
|
||||||
|
</p>
|
||||||
|
<ol class="references">
|
||||||
|
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">abc <strong class="error mw-ext-cite-error">Cite error: Invalid <code><ref></code> tag; name "a" defined multiple times with different content</strong></span>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
!! end
|
||||||
|
|
||||||
|
!! test
|
||||||
|
Multiple definition (mixed outside/inside)
|
||||||
|
!! input
|
||||||
|
<ref name=a>abc</ref>
|
||||||
|
<references>
|
||||||
|
<ref name=a>def</ref>
|
||||||
|
</references>
|
||||||
|
!! result
|
||||||
|
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">[1]</a></sup>
|
||||||
|
</p>
|
||||||
|
<ol class="references">
|
||||||
|
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">abc <strong class="error mw-ext-cite-error">Cite error: Invalid <code><ref></code> tag; name "a" defined multiple times with different content</strong></span>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
!! end
|
||||||
|
|
Loading…
Reference in a new issue