jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/361597 )

Change subject: Make multiple colons escaping interlanguage links invalid, 
consistently
......................................................................


Make multiple colons escaping interlanguage links invalid, consistently

 * Right now, one or two are permitted.  This patch limits it to one.
   The current behaviour seems more a byproduct of refactoring than an
   explicit goal.

 * Note that this will break links on a handful of pages surfaced in
   Parsoid's roundtrip testing.

Change-Id: Icabd34bbf15781bb891bd8e0c079d1a65eb28595
---
M includes/parser/Parser.php
M includes/title/MediaWikiTitleCodec.php
M tests/parser/parserTests.txt
3 files changed, 22 insertions(+), 8 deletions(-)

Approvals:
  C. Scott Ananian: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 9ea65e0..0cc2aac 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -2240,12 +2240,6 @@
                                $link = $origLink;
                        }
 
-                       $noforce = ( substr( $origLink, 0, 1 ) !== ':' );
-                       if ( !$noforce ) {
-                               # Strip off leading ':'
-                               $link = substr( $link, 1 );
-                       }
-
                        $unstrip = $this->mStripState->unstripNoWiki( $link );
                        $nt = is_string( $unstrip ) ? Title::newFromText( 
$unstrip ) : null;
                        if ( $nt === null ) {
@@ -2255,6 +2249,8 @@
 
                        $ns = $nt->getNamespace();
                        $iw = $nt->getInterwiki();
+
+                       $noforce = ( substr( $origLink, 0, 1 ) !== ':' );
 
                        if ( $might_be_img ) { # if this is actually an invalid 
link
                                if ( $ns == NS_FILE && $noforce ) { # but might 
be an image
@@ -2300,6 +2296,10 @@
                        $wasblank = ( $text == '' );
                        if ( $wasblank ) {
                                $text = $link;
+                               if ( !$noforce ) {
+                                       # Strip off leading ':'
+                                       $text = substr( $text, 1 );
+                               }
                        } else {
                                # T6598 madness. Handle the quotes only if they 
come from the alternate part
                                # [[Lista d''e paise d''o munno]] -> <a 
href="...">Lista d''e paise d''o munno</a>
@@ -2324,7 +2324,7 @@
                                        }
 
                                        $s = rtrim( $s . $prefix );
-                                       $s .= trim( $trail, "\n" ) == '' ? '': 
$prefix . $trail;
+                                       $s .= trim( $trail, "\n" ) == '' ? '' : 
$prefix . $trail;
                                        continue;
                                }
 
diff --git a/includes/title/MediaWikiTitleCodec.php 
b/includes/title/MediaWikiTitleCodec.php
index 0fff97c..dd8b975 100644
--- a/includes/title/MediaWikiTitleCodec.php
+++ b/includes/title/MediaWikiTitleCodec.php
@@ -301,7 +301,7 @@
 
                # Initial colon indicates main namespace rather than specified 
default
                # but should not create invalid {ns,title} pairs such as 
{0,Project:Foo}
-               if ( $dbkey !== '' && ':' == $dbkey[0] ) {
+               if ( $dbkey !== '' && $dbkey[0] == ':' ) {
                        $parts['namespace'] = NS_MAIN;
                        $dbkey = substr( $dbkey, 1 ); # remove the colon but 
continue processing
                        $dbkey = trim( $dbkey, '_' ); # remove any subsequent 
whitespace
@@ -368,6 +368,7 @@
                                        if ( $dbkey !== '' && $dbkey[0] == ':' 
) {
                                                $parts['namespace'] = NS_MAIN;
                                                $dbkey = substr( $dbkey, 1 );
+                                               $dbkey = trim( $dbkey, '_' );
                                        }
                                }
                                # If there's no recognized interwiki or 
namespace,
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index 44bcdff..f7629cd 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -8741,6 +8741,19 @@
 <a rel="mw:ExtLink" href="http://zh.wikipedia.org/wiki/Chinese"; 
title="zh:Chinese"> zh : Chinese </a></p>
 !! end
 
+!! test
+Multiple colons escaping interlanguage links
+!! wikitext
+[[:es:Spanish]]
+[[::es:Spanish]]
+[[:::es:Spanish]]
+!! html/php
+<p><a href="http://es.wikipedia.org/wiki/Spanish"; class="extiw" 
title="es:Spanish">es:Spanish</a>
+[[::es:Spanish]]
+[[:::es:Spanish]]
+</p>
+!! end
+
 ## parsoid html2wt will normalize the space to _
 !! test
 Space and question mark encoding in interlanguage links (T95473)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Icabd34bbf15781bb891bd8e0c079d1a65eb28595
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: C. Scott Ananian <canan...@wikimedia.org>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to