r11675 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11674‎ | r11675 | r11676 >
Date:14:55, 7 November 2005
Author:avar
Status:old
Tags:
Comment:
* Trim the first and last newlines of strings passed via <onlyinclude> to avoid whitespace buildup
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -2497,7 +2497,7 @@
24982498 preg_match_all( '/<onlyinclude>(.*?)<\/onlyinclude>/s', $text, $m );
24992499 $text = '';
25002500 foreach ($m[1] as $piece)
2501 - $text .= $piece;
 2501+ $text .= $this->trimOnlyinclude( $piece );
25022502 }
25032503 # Remove <noinclude> sections and <includeonly> tags
25042504 $text = preg_replace( '/<noinclude>.*?<\/noinclude>/s', '', $text );
@@ -2572,6 +2572,19 @@
25732573 return $text;
25742574 }
25752575 }
 2576+
 2577+ /**
 2578+ * Trim the first and last newlines of a string, this is not equivalent
 2579+ * to trim( $str, "\n" ) which would trim them all.
 2580+ *
 2581+ * @param string $str The string to trim
 2582+ * @return string
 2583+ */
 2584+ function trimOnlyinclude( $str ) {
 2585+ $str = preg_replace( "/^\n/", '', $str );
 2586+ $str = preg_replace( "/\n$/", '', $str );
 2587+ return $str;
 2588+ }
25762589
25772590 /**
25782591 * Translude an interwiki link.

Status & tagging log