No interlanguage links after local interwiki prefixes
authorThis, that and the other <at.light@live.com.au>
Mon, 21 Jul 2014 02:35:50 +0000 (12:35 +1000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 22 Jul 2014 13:01:07 +0000 (15:01 +0200)
This was noticed on enwiki after w: was marked as a local interwiki prefix
there. Links like [[w:de:Foo]] ought to act like [[:de:Foo]], not
[[de:Foo]].

Also adding a number of additional parser tests related to interwiki links.

Bug: 68085
Change-Id: If39af06edb4af2da85c9bcf43df7088181809fcf

RELEASE-NOTES-1.24
includes/parser/Parser.php
tests/parser/parserTest.inc
tests/parser/parserTests.txt
tests/phpunit/includes/parser/NewParserTest.php

index ead5196..680a641 100644 (file)
@@ -126,6 +126,9 @@ production.
 * (bug 66440) The MediaWiki web installer will now allow you to choose the skins
   to enable (from the ones included in download tarball) and decide which one
   should be the default.
+* (bug 68085) Links of the form [[localInterwikiPrefix:languageCode:pageTitle]],
+  where localInterwikiPrefix is a member of the $wgLocalInterwikis array, will
+  no longer be displayed in the sidebar when $wgInterwikiMagic is true.
 
 === Bug fixes in 1.24 ===
 * (bug 49116) Footer copyright notice is now always displayed in user language
@@ -266,7 +269,6 @@ changes to languages because of Bugzilla reports.
 * A _from_namespace field has been added to the templatelinks, pagelinks,
   and filelinks tables. Run update.php to apply this change to the schema.
 
-
 ==== Renamed classes ====
 * CLDRPluralRuleConverter_Expression to CLDRPluralRuleConverterExpression
 * CLDRPluralRuleConverter_Fragment to CLDRPluralRuleConverterFragment
index e5917b8..b37e977 100644 (file)
@@ -2002,10 +2002,12 @@ class Parser {
                        wfProfileOut( __METHOD__ . "-e1" );
                        wfProfileIn( __METHOD__ . "-misc" );
 
+                       $origLink = $m[1];
+
                        # Don't allow internal links to pages containing
                        # PROTO: where PROTO is a valid URL protocol; these
                        # should be external links.
-                       if ( preg_match( '/^(?i:' . $this->mUrlProtocols . ')/', $m[1] ) ) {
+                       if ( preg_match( '/^(?i:' . $this->mUrlProtocols . ')/', $origLink ) ) {
                                $s .= $prefix . '[[' . $line;
                                wfProfileOut( __METHOD__ . "-misc" );
                                continue;
@@ -2013,12 +2015,12 @@ class Parser {
 
                        # Make subpage if necessary
                        if ( $useSubpages ) {
-                               $link = $this->maybeDoSubpageLink( $m[1], $text );
+                               $link = $this->maybeDoSubpageLink( $origLink, $text );
                        } else {
-                               $link = $m[1];
+                               $link = $origLink;
                        }
 
-                       $noforce = ( substr( $m[1], 0, 1 ) !== ':' );
+                       $noforce = ( substr( $origLink, 0, 1 ) !== ':' );
                        if ( !$noforce ) {
                                # Strip off leading ':'
                                $link = substr( $link, 1 );
@@ -2097,11 +2099,13 @@ class Parser {
                        if ( $noforce ) {
                                # Interwikis
                                wfProfileIn( __METHOD__ . "-interwiki" );
+                               # The final condition here is due to bug 68085
                                if (
                                        $iw && $this->mOptions->getInterwikiMagic() && $nottalk && (
                                                Language::fetchLanguageName( $iw, null, 'mw' ) ||
                                                in_array( $iw, $wgExtraInterlanguageLinkPrefixes )
-                                       )
+                                       ) && substr_compare( $this->getTargetLanguage()->lc( ltrim( $origLink ) ),
+                                               $iw, 0, strlen( $iw ) ) === 0
                                ) {
                                        # Bug 24502: filter duplicates
                                        if ( !isset( $this->mLangLinkLanguages[$iw] ) ) {
index 24c5aba..027c7b9 100644 (file)
@@ -148,7 +148,7 @@ class ParserTest {
                global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc,
                        $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
                        $wgExtraNamespaces, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
-                       $wgExtraInterlanguageLinkPrefixes,
+                       $wgExtraInterlanguageLinkPrefixes, $wgLocalInterwikis,
                        $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
                        $wgArticlePath, $wgScript, $wgStylePath, $wgExtensionAssetsPath,
                        $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgLockManagers;
@@ -219,11 +219,12 @@ class ParserTest {
                if ( $wgStyleDirectory === false ) {
                        $wgStyleDirectory = "$IP/skins";
                }
+
+               self::setupInterwikis();
+               $wgLocalInterwikis = array( 'local', 'mi' );
                // "extra language links"
                // see https://gerrit.wikimedia.org/r/111390
                array_push( $wgExtraInterlanguageLinkPrefixes, 'mul' );
-
-               self::setupInterwikis();
        }
 
        /**
@@ -240,6 +241,11 @@ class ParserTest {
                # for testing inter-language links
                Hooks::register( 'InterwikiLoadPrefix', function ( $prefix, &$iwData ) {
                        static $testInterwikis = array(
+                               'local' => array(
+                                       'iw_url' => 'http://doesnt.matter.org/$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 0 ),
                                'wikipedia' => array(
                                        'iw_url' => 'http://en.wikipedia.org/wiki/$1',
                                        'iw_api' => '',
@@ -275,6 +281,11 @@ class ParserTest {
                                        'iw_api' => '',
                                        'iw_wikiid' => '',
                                        'iw_local' => 1 ),
+                               'mi' => array(
+                                       'iw_url' => 'http://mi.wikipedia.org/wiki/$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 1 ),
                                'mul' => array(
                                        'iw_url' => 'http://wikisource.org/wiki/$1',
                                        'iw_api' => '',
index 4a3889d..62e160b 100644 (file)
@@ -6392,6 +6392,44 @@ parsoid
 <p data-parsoid='{}'><a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/Foo" data-parsoid='{"stx":"piped","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":"wikipedia:Foo"},"isIW":true,"tail":"r"}'>Bar</a></p>
 !! end
 
+!! test
+Local interwiki link
+!! wikitext
+[[local:Template:Foo]]
+!! html
+<p><a href="/wiki/Template:Foo" title="Template:Foo">local:Template:Foo</a>
+</p>
+!! end
+
+!! test
+Local interwiki link: self-link to current page
+!! options
+title=[[Main Page]]
+!! wikitext
+[[local:Main Page]]
+!! html
+<p><strong class="selflink">local:Main Page</strong>
+</p>
+!! end
+
+!! test
+Local interwiki link: prefix only (bug 64167)
+!! wikitext
+[[local:]]
+!! html
+<p><a href="/wiki/Main_Page" title="Main Page">local:</a>
+</p>
+!! end
+
+!! test
+Local interwiki link: with additional interwiki prefix (bug 61357)
+!! wikitext
+[[local:meatball:Hello]]
+!! html
+<p><a href="http://www.usemod.com/cgi-bin/mb.pl?Hello" class="extiw" title="meatball:Hello">local:meatball:Hello</a>
+</p>
+!! end
+
 ###
 ### Interlanguage links
 ### Language links (so that searching for '### language' matches..)
@@ -6410,6 +6448,19 @@ Blah blah blah
 <link rel="mw:PageProp/Language" href="//zh.wikipedia.org/wiki/Chinese"/></p>
 !! end
 
+!! test
+Interlanguage link with spacing
+!! wikitext
+Blah blah blah
+[[   zh  :    Chinese     ]]
+!! html/php
+<p>Blah blah blah
+</p>
+!! html/parsoid
+<p>Blah blah blah
+<link rel="mw:PageProp/Language" href="//zh.wikipedia.org/wiki/Chinese"/></p>
+!! end
+
 !! test
 Double interlanguage link
 !! wikitext
@@ -6538,6 +6589,28 @@ parsoid
 <p><a rel="mw:WikiLink" href="./Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"en:Foo"}}'>Foo</a></p>
 !! end
 
+!! test
+Interlanguage link with preceding local interwiki link (bug 68085)
+!! wikitext
+Blah blah blah
+[[local:es:Spanish]]
+!! html
+<p>Blah blah blah
+<a href="http://es.wikipedia.org/wiki/Spanish" class="extiw" title="es:Spanish">local:es:Spanish</a>
+</p>
+!! end
+
+!! test
+Looks like an interlanguage link, but is actually a local interwiki
+!! wikitext
+Blah blah blah
+[[mi:Template:Foo]]
+!! html
+<p>Blah blah blah
+<a href="/wiki/Template:Foo" title="Template:Foo">mi:Template:Foo</a>
+</p>
+!! end
+
 ###
 ### Redirects, Parsoid-only
 ###
index 4c72d1c..253c10b 100644 (file)
@@ -148,6 +148,7 @@ class NewParserTest extends MediaWikiTestCase {
                # proper precedence when resolving links. (bug 51680)
                $tmpGlobals['wgExtraNamespaces'] = array( 100 => 'MemoryAlpha' );
 
+               $tmpGlobals['wgLocalInterwikis'] = array( 'local', 'mi' );
                # "extra language links"
                # see https://gerrit.wikimedia.org/r/111390
                $tmpGlobals['wgExtraInterlanguageLinkPrefixes'] = array( 'mul' );