From: This, that and the other
Date: Mon, 21 Jul 2014 02:35:50 +0000 (+1000)
Subject: No interlanguage links after local interwiki prefixes
X-Git-Tag: 1.31.0-rc.0~14827
X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22messagerie%22%29%20.%20%22?a=commitdiff_plain;h=e349358a5da3def796b92f9092fd28c8987bc23f;p=lhc%2Fweb%2Fwiklou.git
No interlanguage links after local interwiki prefixes
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
---
diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24
index ead5196aec..680a641429 100644
--- a/RELEASE-NOTES-1.24
+++ b/RELEASE-NOTES-1.24
@@ -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
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index e5917b8f83..b37e977e82 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -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] ) ) {
diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc
index 24c5aba513..027c7b9b00 100644
--- a/tests/parser/parserTest.inc
+++ b/tests/parser/parserTest.inc
@@ -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' => '',
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index 4a3889d10b..62e160be25 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -6392,6 +6392,44 @@ parsoid
Bar
!! end
+!! test
+Local interwiki link
+!! wikitext
+[[local:Template:Foo]]
+!! html
+local:Template:Foo
+
+!! end
+
+!! test
+Local interwiki link: self-link to current page
+!! options
+title=[[Main Page]]
+!! wikitext
+[[local:Main Page]]
+!! html
+local:Main Page
+
+!! end
+
+!! test
+Local interwiki link: prefix only (bug 64167)
+!! wikitext
+[[local:]]
+!! html
+local:
+
+!! end
+
+!! test
+Local interwiki link: with additional interwiki prefix (bug 61357)
+!! wikitext
+[[local:meatball:Hello]]
+!! html
+local:meatball:Hello
+
+!! end
+
###
### Interlanguage links
### Language links (so that searching for '### language' matches..)
@@ -6410,6 +6448,19 @@ Blah blah blah
!! end
+!! test
+Interlanguage link with spacing
+!! wikitext
+Blah blah blah
+[[ zh : Chinese ]]
+!! html/php
+Blah blah blah
+
+!! html/parsoid
+Blah blah blah
+
+!! end
+
!! test
Double interlanguage link
!! wikitext
@@ -6538,6 +6589,28 @@ parsoid
Foo
!! end
+!! test
+Interlanguage link with preceding local interwiki link (bug 68085)
+!! wikitext
+Blah blah blah
+[[local:es:Spanish]]
+!! html
+Blah blah blah
+local:es:Spanish
+
+!! end
+
+!! test
+Looks like an interlanguage link, but is actually a local interwiki
+!! wikitext
+Blah blah blah
+[[mi:Template:Foo]]
+!! html
+Blah blah blah
+mi:Template:Foo
+
+!! end
+
###
### Redirects, Parsoid-only
###
diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php
index 4c72d1c9e4..253c10b5d7 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -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' );