MediaWiki REL1_34
TableDiffFormatter.php
Go to the documentation of this file.
1<?php
34
35 function __construct() {
36 $this->leadingContextLines = 2;
37 $this->trailingContextLines = 2;
38 }
39
45 public static function escapeWhiteSpace( $msg ) {
46 $msg = preg_replace( '/^ /m', "\u{00A0} ", $msg );
47 $msg = preg_replace( '/ $/m', " \u{00A0}", $msg );
48 $msg = preg_replace( '/ /', "\u{00A0} ", $msg );
49
50 return $msg;
51 }
52
61 protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
62 // '<!--LINE \d+ -->' get replaced by a localised line number
63 // in DifferenceEngine::localiseLineNumbers
64 $r = '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l' .
65 $xbeg .
66 '" ><!--LINE ' .
67 $xbeg .
68 "--></td>\n" .
69 '<td colspan="2" class="diff-lineno"><!--LINE ' .
70 $ybeg .
71 "--></td></tr>\n";
72
73 return $r;
74 }
75
81 protected function startBlock( $header ) {
82 $this->writeOutput( $header );
83 }
84
85 protected function endBlock() {
86 }
87
93 protected function lines( $lines, $prefix = ' ', $color = 'white' ) {
94 }
95
103 protected function addedLine( $line ) {
104 return $this->wrapLine( '+', 'diff-addedline', $line );
105 }
106
114 protected function deletedLine( $line ) {
115 return $this->wrapLine( '−', 'diff-deletedline', $line );
116 }
117
125 protected function contextLine( $line ) {
126 return $this->wrapLine( "\u{00A0}", 'diff-context', $line );
127 }
128
136 protected function wrapLine( $marker, $class, $line ) {
137 if ( $line !== '' ) {
138 // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
139 $line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
140 }
141
142 return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
143 }
144
148 protected function emptyLine() {
149 return "<td colspan=\"2\">\u{00A0}</td>";
150 }
151
157 protected function added( $lines ) {
158 foreach ( $lines as $line ) {
159 $this->writeOutput( '<tr>' . $this->emptyLine() .
160 $this->addedLine( '<ins class="diffchange">' .
161 htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n" );
162 }
163 }
164
170 protected function deleted( $lines ) {
171 foreach ( $lines as $line ) {
172 $this->writeOutput( '<tr>' . $this->deletedLine( '<del class="diffchange">' .
173 htmlspecialchars( $line ) . '</del>' ) .
174 $this->emptyLine() . "</tr>\n" );
175 }
176 }
177
183 protected function context( $lines ) {
184 foreach ( $lines as $line ) {
185 $this->writeOutput( '<tr>' .
186 $this->contextLine( htmlspecialchars( $line ) ) .
187 $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n" );
188 }
189 }
190
197 protected function changed( $orig, $closing ) {
198 $diff = new WordLevelDiff( $orig, $closing );
199 $del = $diff->orig();
200 $add = $diff->closing();
201
202 # Notice that WordLevelDiff returns HTML-escaped output.
203 # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
204
205 $ndel = count( $del );
206 $nadd = count( $add );
207 $n = max( $ndel, $nadd );
208 for ( $i = 0; $i < $n; $i++ ) {
209 $delLine = $i < $ndel ? $this->deletedLine( $del[$i] ) : $this->emptyLine();
210 $addLine = $i < $nadd ? $this->addedLine( $add[$i] ) : $this->emptyLine();
211 $this->writeOutput( "<tr>{$delLine}{$addLine}</tr>\n" );
212 }
213 }
214
215}
$line
Definition cdb.php:59
Base class for diff formatters.
writeOutput( $text)
Writes a string to the output buffer.
MediaWiki default table style diff formatter.
deletedLine( $line)
HTML-escape parameter before calling this.
startBlock( $header)
Writes the header to the output buffer.
wrapLine( $marker, $class, $line)
added( $lines)
Writes all lines to the output buffer, each enclosed in .
changed( $orig, $closing)
Writes the two sets of lines to the output buffer, each enclosed in .
lines( $lines, $prefix=' ', $color='white')
blockHeader( $xbeg, $xlen, $ybeg, $ylen)
endBlock()
Called at the end of a block of connected edits.
contextLine( $line)
HTML-escape parameter before calling this.
static escapeWhiteSpace( $msg)
addedLine( $line)
HTML-escape parameter before calling this.
context( $lines)
Writes all lines to the output buffer, each enclosed in .
deleted( $lines)
Writes all lines to the output buffer, each enclosed in .
Performs a word-level diff on several lines.
$lines
Definition router.php:61
$header