MediaWiki  1.23.6
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 
46  public static function escapeWhiteSpace( $msg ) {
47  $msg = preg_replace( '/^ /m', '&#160; ', $msg );
48  $msg = preg_replace( '/ $/m', ' &#160;', $msg );
49  $msg = preg_replace( '/ /', '&#160; ', $msg );
50 
51  return $msg;
52  }
53 
62  protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
63  $r = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" .
64  '<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\n";
65 
66  return $r;
67  }
68 
74  protected function startBlock( $header ) {
75  echo $header;
76  }
77 
78  protected function endBlock() {
79  }
80 
86  protected function lines( $lines, $prefix = ' ', $color = 'white' ) {
87  }
88 
96  protected function addedLine( $line ) {
97  return $this->wrapLine( '+', 'diff-addedline', $line );
98  }
99 
107  protected function deletedLine( $line ) {
108  return $this->wrapLine( '−', 'diff-deletedline', $line );
109  }
110 
118  protected function contextLine( $line ) {
119  return $this->wrapLine( '&#160;', 'diff-context', $line );
120  }
121 
129  protected function wrapLine( $marker, $class, $line ) {
130  if ( $line !== '' ) {
131  // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
132  $line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
133  }
134 
135  return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
136  }
137 
141  protected function emptyLine() {
142  return '<td colspan="2">&#160;</td>';
143  }
144 
150  protected function added( $lines ) {
151  foreach ( $lines as $line ) {
152  echo '<tr>' . $this->emptyLine() .
153  $this->addedLine( '<ins class="diffchange">' .
154  htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
155  }
156  }
157 
163  protected function deleted( $lines ) {
164  foreach ( $lines as $line ) {
165  echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
166  htmlspecialchars( $line ) . '</del>' ) .
167  $this->emptyLine() . "</tr>\n";
168  }
169  }
170 
176  protected function context( $lines ) {
177  foreach ( $lines as $line ) {
178  echo '<tr>' .
179  $this->contextLine( htmlspecialchars( $line ) ) .
180  $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n";
181  }
182  }
183 
190  protected function changed( $orig, $closing ) {
191  wfProfileIn( __METHOD__ );
192 
193  $diff = new WordLevelDiff( $orig, $closing );
194  $del = $diff->orig();
195  $add = $diff->closing();
196 
197  # Notice that WordLevelDiff returns HTML-escaped output.
198  # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
199 
200  while ( $line = array_shift( $del ) ) {
201  $aline = array_shift( $add );
202  echo '<tr>' . $this->deletedLine( $line ) .
203  $this->addedLine( $aline ) . "</tr>\n";
204  }
205  foreach ( $add as $line ) { # If any leftovers
206  echo '<tr>' . $this->emptyLine() .
207  $this->addedLine( $line ) . "</tr>\n";
208  }
209  wfProfileOut( __METHOD__ );
210  }
211 
212 }
TableDiffFormatter\wrapLine
wrapLine( $marker, $class, $line)
Definition: TableDiffFormatter.php:129
TableDiffFormatter\deleted
deleted( $lines)
Writes all lines to the output buffer, each enclosed in .
Definition: TableDiffFormatter.php:163
TableDiffFormatter\escapeWhiteSpace
static escapeWhiteSpace( $msg)
Definition: TableDiffFormatter.php:46
TableDiffFormatter\blockHeader
blockHeader( $xbeg, $xlen, $ybeg, $ylen)
Definition: TableDiffFormatter.php:62
DiffFormatter
Base class for diff formatters.
Definition: DiffFormatter.php:36
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Xml\tags
static tags( $element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
WordLevelDiff
Definition: DairikiDiff.php:970
TableDiffFormatter\contextLine
contextLine( $line)
HTML-escape parameter before calling this.
Definition: TableDiffFormatter.php:118
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
TableDiffFormatter
MediaWiki default table style diff formatter.
Definition: TableDiffFormatter.php:33
TableDiffFormatter\__construct
__construct()
Definition: TableDiffFormatter.php:35
TableDiffFormatter\addedLine
addedLine( $line)
HTML-escape parameter before calling this.
Definition: TableDiffFormatter.php:96
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
$lines
$lines
Definition: router.php:65
TableDiffFormatter\changed
changed( $orig, $closing)
Writes the two sets of lines to the output buffer, each enclosed in .
Definition: TableDiffFormatter.php:190
TableDiffFormatter\endBlock
endBlock()
Called at the end of a block of connected edits.
Definition: TableDiffFormatter.php:78
$line
$line
Definition: cdb.php:57
TableDiffFormatter\deletedLine
deletedLine( $line)
HTML-escape parameter before calling this.
Definition: TableDiffFormatter.php:107
TableDiffFormatter\added
added( $lines)
Writes all lines to the output buffer, each enclosed in .
Definition: TableDiffFormatter.php:150
TableDiffFormatter\startBlock
startBlock( $header)
Writes the header to the output buffer.
Definition: TableDiffFormatter.php:74
TableDiffFormatter\context
context( $lines)
Writes all lines to the output buffer, each enclosed in .
Definition: TableDiffFormatter.php:176
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
TableDiffFormatter\lines
lines( $lines, $prefix=' ', $color='white')
Definition: TableDiffFormatter.php:86
TableDiffFormatter\emptyLine
emptyLine()
Definition: TableDiffFormatter.php:141