Merge "Fix link prefix/suffixes around Category and Language links (take 2)."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 19 Sep 2017 16:59:58 +0000 (16:59 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 19 Sep 2017 16:59:58 +0000 (16:59 +0000)
includes/parser/Parser.php
tests/parser/parserTests.txt

index e901f6f..d00b333 100644 (file)
@@ -2296,8 +2296,13 @@ 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;
+                                       // Special case: strip newlines when only thing between
+                                       // this link and next are newlines
+                                       $s .= trim( $trail, "\n" ) === '' ? '' : $trail;
                                        continue;
                                }
 
@@ -2322,7 +2327,13 @@ 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
+                                       // Special case: strip newlines when only thing between
+                                       // this link and next are newlines
+                                       $s .= trim( $trail, "\n" ) === '' ? '' : $trail;
 
                                        if ( $wasblank ) {
                                                $sortkey = $this->getDefaultSort();
@@ -2334,11 +2345,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 2064e03..0aa0e03 100644 (file)
@@ -16142,6 +16142,68 @@ 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
+10. No regressions on internal links following category (T174639)
+!! options
+parsoid=wt2html,html2html
+!! wikitext
+[[Category:Foo]]<div>a
+
+[[Foo]]</div>
+!! html/php
+<div>a
+<a href="/wiki/Foo" title="Foo">Foo</a></div>
+
+!! html/parsoid
+<link rel="mw:PageProp/Category" href="./Category:Foo"/><div>a
+
+<a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a></div>
+!! end
+
+# NOTE that Parsoid does not currently implement this special case
+# (T175416).  The plan is to remove this weird special-case in the PHP
+# parser to make it match the Parsoid output.
+!! test
+11. Special case where only newlines separate links
+!! options
+parsoid=wt2html,html2html
+!! wikitext
+[[Category:Foo]]
+
+[[Foo]][[es:Alimento]]
+
+[[Foo]]
+!! html/php
+<p><a href="/wiki/Foo" title="Foo">Foo</a><a href="/wiki/Foo" title="Foo">Foo</a>
+</p>
+!! html/parsoid
+<link rel="mw:PageProp/Category" href="./Category:Foo"/>
+
+<p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a></p><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Alimento"/>
+
+<p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a></p>
+!! end
+
 !! test
 Category links with multiple namespaces
 !! wikitext
@@ -16189,6 +16251,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