Merge "Fix link prefix/suffixes around Category and Language links (take 2)."
[lhc/web/wiklou.git] / includes / parser / Parser.php
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;
                                }
                        }