MediaWiki  REL1_31
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', '&#160; ', $msg );
47  $msg = preg_replace( '/ $/m', ' &#160;', $msg );
48  $msg = preg_replace( '/ /', '&#160; ', $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( '&#160;', '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">&#160;</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 }
TableDiffFormatter\wrapLine
wrapLine( $marker, $class, $line)
Definition: TableDiffFormatter.php:136
TableDiffFormatter\deleted
deleted( $lines)
Writes all lines to the output buffer, each enclosed in .
Definition: TableDiffFormatter.php:170
TableDiffFormatter\escapeWhiteSpace
static escapeWhiteSpace( $msg)
Definition: TableDiffFormatter.php:45
TableDiffFormatter\blockHeader
blockHeader( $xbeg, $xlen, $ybeg, $ylen)
Definition: TableDiffFormatter.php:61
DiffFormatter
Base class for diff formatters.
Definition: DiffFormatter.php:36
Xml\tags
static tags( $element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
WordLevelDiff
Performs a word-level diff on several lines.
Definition: WordLevelDiff.php:34
TableDiffFormatter\contextLine
contextLine( $line)
HTML-escape parameter before calling this.
Definition: TableDiffFormatter.php:125
DiffFormatter\writeOutput
writeOutput( $text)
Writes a string to the output buffer.
Definition: DiffFormatter.php:159
TableDiffFormatter
MediaWiki default table style diff formatter.
Definition: TableDiffFormatter.php:33
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
TableDiffFormatter\__construct
__construct()
Definition: TableDiffFormatter.php:35
TableDiffFormatter\addedLine
addedLine( $line)
HTML-escape parameter before calling this.
Definition: TableDiffFormatter.php:103
$lines
$lines
Definition: router.php:61
TableDiffFormatter\changed
changed( $orig, $closing)
Writes the two sets of lines to the output buffer, each enclosed in .
Definition: TableDiffFormatter.php:197
TableDiffFormatter\endBlock
endBlock()
Called at the end of a block of connected edits.
Definition: TableDiffFormatter.php:85
$line
$line
Definition: cdb.php:59
TableDiffFormatter\deletedLine
deletedLine( $line)
HTML-escape parameter before calling this.
Definition: TableDiffFormatter.php:114
TableDiffFormatter\added
added( $lines)
Writes all lines to the output buffer, each enclosed in .
Definition: TableDiffFormatter.php:157
TableDiffFormatter\startBlock
startBlock( $header)
Writes the header to the output buffer.
Definition: TableDiffFormatter.php:81
$header
$header
Definition: updateCredits.php:35
TableDiffFormatter\context
context( $lines)
Writes all lines to the output buffer, each enclosed in .
Definition: TableDiffFormatter.php:183
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:22
TableDiffFormatter\lines
lines( $lines, $prefix=' ', $color='white')
Definition: TableDiffFormatter.php:93
TableDiffFormatter\emptyLine
emptyLine()
Definition: TableDiffFormatter.php:148