From 2a56d619e2e236fe158a966c599b90140f9cdaac Mon Sep 17 00:00:00 2001 From: Arne Heizmann Date: Sat, 28 Aug 2004 21:37:56 +0000 Subject: [PATCH] instead of HTML-escaping everything and then creating a diff of it, diff the original text and HTML-escape each bit when we actually output it. Fixes http://bugzilla.wikipedia.org/show_bug.cgi?id=216 in a non-hacky way. --- includes/DifferenceEngine.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 571b7abbcd..94a310223a 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -100,8 +100,8 @@ class DifferenceEngine { { global $wgOut, $wgUseExternalDiffEngine; - $otext = str_replace( "\r\n", "\n", htmlspecialchars( $otext ) ); - $ntext = str_replace( "\r\n", "\n", htmlspecialchars( $ntext ) ); + $otext = str_replace( "\r\n", "\n", $otext ); + $ntext = str_replace( "\r\n", "\n", $ntext ); $wgOut->addHTML( "_group !== '') { - if ($this->_tag == 'mark') - $this->_line .= ''.$this->_group.''; - else - $this->_line .= $this->_group; - } + if ($this->_tag == 'mark') + $this->_line .= ''.htmlspecialchars ( $this->_group ).''; + else + $this->_line .= htmlspecialchars ( $this->_group ); + } $this->_group = ''; $this->_tag = $new_tag; } @@ -1055,7 +1055,9 @@ class _HWLDF_WordAccumulator { function _flushLine ($new_tag) { $this->_flushGroup($new_tag); if ($this->_line != '') - $this->_lines[] = $this->_line; + array_push ( $this->_lines, $this->_line ); + else + array_push ( $this->_lines, NBSP ); $this->_line = ''; } @@ -1068,7 +1070,6 @@ class _HWLDF_WordAccumulator { if ($word == '') continue; if ($word[0] == "\n") { - $this->_group .= NBSP; $this->_flushLine($tag); $word = substr($word, 1); } @@ -1095,8 +1096,6 @@ class WordLevelDiff extends MappedDiff } function _split($lines) { - // FIXME: fix POSIX char class. -# if (!preg_match_all('/ ( [^\S\n]+ | [[:alnum:]]+ | . ) (?: (?!< \n) [^\S\n])? /xs', if (!preg_match_all('/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs', implode("\n", $lines), $m)) { @@ -1146,7 +1145,7 @@ class TableDiffFormatter extends DiffFormatter $l2 = wfMsg( 'lineno', $ybeg ); $r = '\n" . - '\n"; + '\n"; return $r; } @@ -1163,12 +1162,12 @@ class TableDiffFormatter extends DiffFormatter function addedLine( $line ) { return ''; + $line . ''; } function deletedLine( $line ) { return ''; + $line . ''; } function emptyLine() { @@ -1176,21 +1175,22 @@ class TableDiffFormatter extends DiffFormatter } function contextLine( $line ) { - return ''; + return ''; } function _added($lines) { global $wgOut; foreach ($lines as $line) { $wgOut->addHTML( '' . $this->emptyLine() . - $this->addedLine( $line ) . "\n" ); + $this->addedLine( htmlspecialchars ( $line ) ) . "\n" ); } } function _deleted($lines) { global $wgOut; foreach ($lines as $line) { - $wgOut->addHTML( '' . $this->deletedLine( $line ) . + $wgOut->addHTML( '' . $this->deletedLine( htmlspecialchars ( $line ) ) . $this->emptyLine() . "\n" ); } } -- 2.20.1
'.$l1."'.$l2."
'.$l2."
+' . - $line.'-' . - $line.' '.$line.' ' . + htmlspecialchars ( $line ) . '