Don't display multiple language links to the same language
authorTim Starling <tstarling@wikimedia.org>
Wed, 26 Sep 2012 07:42:17 +0000 (17:42 +1000)
committerMax Semenik <maxsem.wiki@gmail.com>
Fri, 5 Oct 2012 19:14:07 +0000 (23:14 +0400)
(bug 24502) Resolve the various issues with this accidental feature
by removing it. I think it could be done properly, along the lines of
my comment #5, but I don't think just changing the DB schema to make
langlinks non-unique is a good direction to take. A comment on
I4e1e08a3 from Daniel Kinzler indicates that duplicate language links
won't be possible with Wikidata anyway, so there's not much value in
I4e1e08a3 for WMF wikis.

Change-Id: Iba5f3f29e20f5119d4414b1e87ce5eee674701a8

RELEASE-NOTES-1.20
includes/parser/Parser.php
tests/parser/parserTests.txt

index 3ba5a13..848e07a 100644 (file)
@@ -244,6 +244,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 39635) PostgreSQL LOCK IN SHARE MODE option is a syntax error.
 * (bug 36329) Accesskey tooltips for Firefox 14 on Mac should use "ctrl-option-" prefix.
 * (bug 32552) Drop unused database field cat_hidden from table category.
+* (bug 24502) Do not allow multiple language links to the same language.
 * (bug 40214) Category pages no longer use deprecated "width" HTML attribute.
 * (bug 39941) Add missing stylesheets to the installer pages
 * In HTML5 mode, allow new input element types values (such as color, range..)
index 59d379a..abc017b 100644 (file)
@@ -200,6 +200,13 @@ class Parser {
         */
        var $mUniqPrefix;
 
+       /**
+        * @var Array with the language name of each language link (i.e. the
+        * interwiki prefix) in the key, value arbitrary. Used to avoid sending
+        * duplicate language links to the ParserOutput.
+        */
+       var $mLangLinkLanguages;
+
        /**
         * Constructor
         *
@@ -282,6 +289,7 @@ class Parser {
                        $this->mRevisionId = $this->mRevisionUser = null;
                $this->mVarCache = array();
                $this->mUser = null;
+               $this->mLangLinkLanguages = array();
 
                /**
                 * Prefix for temporary replacement strings for the multipass parser.
@@ -1953,7 +1961,11 @@ class Parser {
                                # Interwikis
                                wfProfileIn( __METHOD__."-interwiki" );
                                if ( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && Language::fetchLanguageName( $iw, null, 'mw' ) ) {
-                                       $this->mOutput->addLanguageLink( $nt->getFullText() );
+                                       # Bug 24502: filter duplicates
+                                       if ( !isset( $this->mLangLinkLanguages[$iw] ) ) {
+                                               $this->mLangLinkLanguages[$iw] = true;
+                                               $this->mOutput->addLanguageLink( $nt->getFullText() );
+                                       }
                                        $s = rtrim( $s . $prefix );
                                        $s .= trim( $trail, "\n" ) == '' ? '': $prefix . $trail;
                                        wfProfileOut( __METHOD__."-interwiki" );
index 0c767c7..7c2f291 100644 (file)
@@ -5553,6 +5553,19 @@ ill
 es:Alimento fr:Nourriture zh:食品
 !! end
 
+!! test
+Duplicate interlanguage links (bug 24502)
+!! options
+ill
+!! input
+[[es:1]]
+[[es:2]]
+[[fr:1]]
+[[fr:2]]
+!! result
+es:1 fr:1
+!! end
+
 ###
 ### Sections
 ###