Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/249401

Change subject: Detect duplicate <ref> definitions inside <references> too
......................................................................

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> is displayed, not the last. (This was already the case
for <ref>s outside <references>.)

Bug: T116377
Change-Id: I81b64ccd8a2e58f3b25938a63b8ad5967fe2a2c0
---
M Cite_body.php
M citeParserTests.txt
2 files changed, 41 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cite 
refs/changes/01/249401/1

diff --git a/Cite_body.php b/Cite_body.php
index 98331d1..c2bc814 100644
--- a/Cite_body.php
+++ b/Cite_body.php
@@ -235,8 +235,14 @@
                                        $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.
diff --git a/citeParserTests.txt b/citeParserTests.txt
index b160059..42cfb4e 100644
--- a/citeParserTests.txt
+++ b/citeParserTests.txt
@@ -532,3 +532,36 @@
 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
+foo
+!! end
+
+!! test
+Multiple definition (inside <references/>)
+!! input
+<ref name=a />
+<references>
+<ref name=a>abc</ref>
+<ref name=a>def</ref>
+</references>
+!! result
+foo
+!! end
+
+!! test
+Multiple definition (mixed outside/inside)
+!! input
+<ref name=a>abc</ref>
+<references>
+<ref name=a>def</ref>
+</references>
+!! result
+foo
+!! end

-- 
To view, visit https://gerrit.wikimedia.org/r/249401
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I81b64ccd8a2e58f3b25938a63b8ad5967fe2a2c0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cite
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to