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:
Bartosz Dziewoński 2015-10-28 15:15:48 +01:00
parent 831d2d6367
commit 9aa7961c60
2 changed files with 60 additions and 2 deletions

View file

@ -235,8 +235,14 @@ class Cite {
$this->mReferencesErrors[] =
$this->error( 'cite_error_references_missing_key', $key );
} else {
# Assign the text to corresponding ref
$this->mRefs[$group][$key]['text'] = $str;
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 {
# Assign the text to corresponding ref
$this->mRefs[$group][$key]['text'] = $str;
}
}
} else {
# <ref> called in <references> has no content.

View file

@ -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>
</p>
!! 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>&lt;ref&gt;</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>&lt;ref&gt;</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>&lt;ref&gt;</code> tag; name "a" defined multiple times with different content</strong></span>
</li>
</ol>
!! end