* Trim the first and last newlines of strings passed via <onlyinclude> to avoid white...
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Mon, 7 Nov 2005 14:55:23 +0000 (14:55 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Mon, 7 Nov 2005 14:55:23 +0000 (14:55 +0000)
includes/Parser.php

index 6228154..9b5c593 100644 (file)
@@ -2497,7 +2497,7 @@ class Parser
                                        preg_match_all( '/<onlyinclude>(.*?)<\/onlyinclude>/s', $text, $m );
                                        $text = '';
                                        foreach ($m[1] as $piece)
-                                               $text .= $piece;
+                                               $text .= $this->trimOnlyinclude( $piece );
                                }
                                # Remove <noinclude> sections and <includeonly> tags
                                $text = preg_replace( '/<noinclude>.*?<\/noinclude>/s', '', $text );
@@ -2572,6 +2572,19 @@ class Parser
                        return $text;
                }
        }
+       
+       /**
+        * Trim the first and last newlines of a string, this is not equivalent
+        * to trim( $str, "\n" ) which would trim them all.
+        *
+        * @param string $str The string to trim
+        * @return string
+        */
+       function trimOnlyinclude( $str ) {
+               $str = preg_replace( "/^\n/", '', $str );
+               $str = preg_replace( "/\n$/", '', $str );
+               return $str;
+       }
 
        /**
         * Translude an interwiki link.