Linker: Do not localize links to other wikis in comments
authorMatěj Suchánek <matejsuchanek97@gmail.com>
Thu, 29 Jun 2017 13:06:24 +0000 (15:06 +0200)
committerKunal Mehta <legoktm@member.fsf.org>
Thu, 6 Jul 2017 01:56:27 +0000 (18:56 -0700)
The title, although it refers to a foreign page, is considered local
due to Title::isExternal() being false, hence it's namespace prefix
is localized.

We need to use the canonical namespace name instead.

Bug: T169221
Change-Id: I5e5f7d873b9497ca6c8853e7d8170a4f4f07c051

includes/Linker.php
tests/phpunit/includes/LinkerTest.php

index 6942a39..9ae7cc6 100644 (file)
@@ -1331,7 +1331,10 @@ class Linker {
                        $link = Linker::makeExternalLink(
                                WikiMap::getForeignURL(
                                        $wikiId,
-                                       $title->getPrefixedText(),
+                                       $title->getNamespace() === 0
+                                               ? $title->getDBkey()
+                                               : MWNamespace::getCanonicalName( $title->getNamespace() ) . ':'
+                                                       . $title->getDBkey(),
                                        $title->getFragment()
                                ),
                                $text,
index 2ca5935..d684a43 100644 (file)
@@ -307,6 +307,11 @@ class LinkerTest extends MediaWikiLangTestCase {
                                'foo bar [[Special:BlankPage]]',
                                'enwiki',
                        ],
+                       [
+                               'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/File:Example">Image:Example</a>',
+                               'foo bar [[Image:Example]]',
+                               'enwiki',
+                       ],
                ];
                // @codingStandardsIgnoreEnd
        }