r76133 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:< r76132‎ | r76133 | r76134 >
Date:19:53, 5 November 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Handle whitespace better
Modified paths:
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/TranslateEditAddons.php
——@@ -418,16 +418,26 @@
419419 list( $key, $code, $group ) = self::getKeyCodeGroup( $article->getTitle() );
420420 if ( !$group ) return true;
421421 $def = $group->getMessage( $key, 'en' );
422 - $content = TranslateUtils::convertWhiteSpaceToHTML( $content );
 422+ $content = self::preserveWhitespaces( $content );
 423+ $def = self::preserveWhitespaces( $def );
423424 $deftext = wfMsgNoTrans( 'translate-edit-show-def' );
424425 $trans = wfMsgNoTrans( 'translate-edit-show-trans' );
425426 $content = <<<HTML
426427 <table class=wikitable>
427428 <tr><th>$deftext</th><th>$trans</th></tr>
428 - <tr><td><nowiki>$def</nowiki></td><td><nowiki>$content</nowiki></td></tr>
 429+ <tr><td style=vertical-align:top>$def</td><td style=vertical-align:top>$content</td></tr>
429430 </table>
430431 HTML;
431432 }
432433 return true;
433434 }
 435+
 436+ public static function preserveWhitespaces( $text ) {
 437+ $text = wfEscapeWikiText( $text );
 438+ $text = preg_replace( '/^ /m', '&#160;', $text );
 439+ $text = preg_replace( '/ $/m', '&#160;', $text );
 440+ $text = preg_replace( '/ /', '&#160; ', $text );
 441+ $text = str_replace( "\n", '<br />', $text );
 442+ return $text;
 443+ }
434444 }

Status & tagging log