From 6d5fd8077fdbb5d4861395a187fd402cd4da405f Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Sun, 13 Aug 2017 14:19:13 -0400 Subject: [PATCH] Fix link prefix/suffixes around Category and Language links (take 2). Previous attempt was I943cd9bec0855d9a326b0b50739d686a29995370, reverted in e687f2da3eb5be95855d9aafc53a7524dfaefa34 due to T174639. There's still a weird behavior with newline stripping between links, which I'll try to tackle in a follow-on patch (T175416). Bug: T2087 Bug: T10897 Bug: T87753 Bug: T174639 Change-Id: I8228cdd3b80faf899000adb511a983edc454bc76 --- includes/parser/Parser.php | 20 ++++++---- tests/parser/parserTests.txt | 76 ++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 988e2488d8..0d11d5a397 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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; } } diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 3f93793263..ca16738219 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -16102,6 +16102,68 @@ parsoid=wt2html !! end +!! test +9. Categories and newlines: should behave properly with linkprefix (T87753) +!! options +language=ar +!! wikitext +foo bar +foo bar +[[تصنيف:Foo]] +[[تصنيف:Bar]] +!! html/php +

foo bar +foo bar +

+!! html/parsoid +

foo bar +foo bar

+ + +!! end + +!! test +10. No regressions on internal links following category (T174639) +!! options +parsoid=wt2html,html2html +!! wikitext +[[Category:Foo]]
a + +[[Foo]]
+!! html/php +
a +Foo
+ +!! html/parsoid +
a + +Foo
+!! 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 +

FooFoo +

+!! html/parsoid + + +

Foo

+ +

Foo

+!! end + !! test Category links with multiple namespaces !! wikitext @@ -16149,6 +16211,20 @@ x[[Category:Foo]]y

xy

!! end +!! test +Link prefix/suffixes aren't applied to language links +!! options +parsoid=wt2html +language=is +!! wikitext +x[[es:Foo]]y +!! html/php +

xy +

+!! html/parsoid +

xy

+!! end + !! test Parsoid: Serialize link to file page with colon escape !! options -- 2.20.1