Fix link prefix/suffixes around Category and Language links.
authorC. Scott Ananian <cscott@cscott.net>
Sun, 13 Aug 2017 18:19:13 +0000 (14:19 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Tue, 15 Aug 2017 17:13:12 +0000 (13:13 -0400)
Bug: T2087
Bug: T10897
Bug: T87753
Change-Id: I943cd9bec0855d9a326b0b50739d686a29995370

includes/parser/Parser.php
tests/parser/parserTests.txt

index 3261002..5ef0032 100644 (file)
@@ -2323,8 +2323,11 @@ class Parser {
                                                $this->mOutput->addLanguageLink( $nt->getFullText() );
                                        }
 
+                                       /**
+                                        * Strip the whitespace interwiki links produce, see T10897
+                                        */
                                        $s = rtrim( $s . $prefix );
-                                       $s .= trim( $trail, "\n" ) == '' ? '' : $prefix . $trail;
+                                       $s .= rtrim( $trail, "\n" );
                                        continue;
                                }
 
@@ -2349,7 +2352,11 @@ class Parser {
                                                continue;
                                        }
                                } elseif ( $ns == NS_CATEGORY ) {
-                                       $s = rtrim( $s . "\n" ); # T2087
+                                       /**
+                                        * Strip the whitespace Category links produce, see T2087
+                                        */
+                                       $s = rtrim( $s . $prefix ); # T2087, T87753
+                                       $s .= rtrim( $trail, "\n" );
 
                                        if ( $wasblank ) {
                                                $sortkey = $this->getDefaultSort();
@@ -2361,11 +2368,6 @@ class Parser {
                                        $sortkey = $this->getConverterLanguage()->convertCategoryKey( $sortkey );
                                        $this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
 
-                                       /**
-                                        * Strip the whitespace Category links produce, see T2087
-                                        */
-                                       $s .= trim( $prefix . $trail, "\n" ) == '' ? '' : $prefix . $trail;
-
                                        continue;
                                }
                        }
index ab79b59..2fa3cb0 100644 (file)
@@ -15807,6 +15807,26 @@ parsoid=wt2html
 <link rel="mw:PageProp/Category" href="./Category:Baz" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:Baz"}}'/>
 !! end
 
+!! test
+9. Categories and newlines: should behave properly with linkprefix (T87753)
+!! options
+language=ar
+!! wikitext
+foo bar
+foo bar
+[[تصنيف:Foo]]
+[[تصنيف:Bar]]
+!! html/php
+<p>foo bar
+foo bar
+</p>
+!! html/parsoid
+<p>foo bar
+foo bar</p>
+<link rel="mw:PageProp/Category" href="./تصنيف:Foo"/>
+<link rel="mw:PageProp/Category" href="./تصنيف:Bar"/>
+!! end
+
 !! test
 Category links with multiple namespaces
 !! wikitext
@@ -15854,6 +15874,20 @@ x[[Category:Foo]]y
 <p>x<link rel="mw:PageProp/Category" href="./Flokkur:Foo" data-parsoid=""/>y</p>
 !! end
 
+!! test
+Link prefix/suffixes aren't applied to language links
+!! options
+parsoid=wt2html
+language=is
+!! wikitext
+x[[es:Foo]]y
+!! html/php
+<p>xy
+</p>
+!! html/parsoid
+<p>x<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" data-parsoid=""/>y</p>
+!! end
+
 !! test
 Parsoid: Serialize link to file page with colon escape
 !! options