Merge "Make multiple colons escaping interlanguage links invalid, consistently"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 11 Jul 2017 15:19:17 +0000 (15:19 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 11 Jul 2017 15:19:17 +0000 (15:19 +0000)
1  2 
includes/parser/Parser.php
tests/parser/parserTests.txt

@@@ -2240,12 -2240,6 +2240,6 @@@ class Parser 
                                $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 ) {
                        $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
                                        $found = false;
                        $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>
                                        }
  
                                        $s = rtrim( $s . $prefix );
-                                       $s .= trim( $trail, "\n" ) == '' ? '': $prefix . $trail;
+                                       $s .= trim( $trail, "\n" ) == '' ? '' : $prefix . $trail;
                                        continue;
                                }
  
                # which may corrupt this parser instance via its wfMessage()->text() call-
  
                # Signatures
 -              $sigText = $this->getUserSig( $user );
 -              $text = strtr( $text, [
 -                      '~~~~~' => $d,
 -                      '~~~~' => "$sigText $d",
 -                      '~~~' => $sigText
 -              ] );
 +              if ( strpos( $text, '~~~' ) !== false ) {
 +                      $sigText = $this->getUserSig( $user );
 +                      $text = strtr( $text, [
 +                              '~~~~~' => $d,
 +                              '~~~~' => "$sigText $d",
 +                              '~~~' => $sigText
 +                      ] );
 +                      # The main two signature forms used above are time-sensitive
 +                      $this->mOutput->setFlag( 'user-signature' );
 +              }
  
                # Context links ("pipe tricks"): [[|name]] and [[name (context)|]]
                $tc = '[' . Title::legalChars() . ']';
@@@ -8741,6 -8741,19 +8741,19 @@@ Blah blah bla
  <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)
@@@ -10421,13 -10434,11 +10434,13 @@@ parsoid={ "modes": ["wt2html","wt2wt"]
  Magic Word: {{REVISIONID}}
  !! options
  parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
 +showflags
  !! wikitext
  {{REVISIONID}}
  !! html/*
  <p>1337
  </p>
 +flags=vary-revision-id
  !! end
  
  !! test
@@@ -13621,34 -13632,17 +13634,34 @@@ pre-save transform: Signature expansio
  pst
  !! wikitext
  * ~~~
 +* ~~~~
 +* ~~~~~
  * <noinclude>~~~</noinclude>
  * <includeonly>~~~</includeonly>
  * <onlyinclude>~~~</onlyinclude>
  !! html/php
  * [[Special:Contributions/127.0.0.1|127.0.0.1]]
 +* [[Special:Contributions/127.0.0.1|127.0.0.1]] 00:02, 1 January 1970 (UTC)
 +* 00:02, 1 January 1970 (UTC)
  * <noinclude>[[Special:Contributions/127.0.0.1|127.0.0.1]]</noinclude>
  * <includeonly>[[Special:Contributions/127.0.0.1|127.0.0.1]]</includeonly>
  * <onlyinclude>[[Special:Contributions/127.0.0.1|127.0.0.1]]</onlyinclude>
  !! end
  
  
 +!! test
 +ParserOutput flags from signature expansion (T84843)
 +!! options
 +pst
 +showflags
 +!! wikitext
 +~~~~
 +!! html/php
 +[[Special:Contributions/127.0.0.1|127.0.0.1]] 00:02, 1 January 1970 (UTC)
 +flags=user-signature
 +!! end
 +
 +
  !! test
  pre-save transform: Signature expansion in nowiki tags (T2093)
  !! options