MediaWiki  1.27.2
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  // '<!--LINE \d+ -->' get replaced by a localised line number
64  // in DifferenceEngine::localiseLineNumbers
65  $r = '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l' .
66  $xbeg .
67  '" ><!--LINE ' .
68  $xbeg .
69  "--></td>\n" .
70  '<td colspan="2" class="diff-lineno"><!--LINE ' .
71  $ybeg .
72  "--></td></tr>\n";
73 
74  return $r;
75  }
76 
82  protected function startBlock( $header ) {
83  $this->writeOutput( $header );
84  }
85 
86  protected function endBlock() {
87  }
88 
94  protected function lines( $lines, $prefix = ' ', $color = 'white' ) {
95  }
96 
104  protected function addedLine( $line ) {
105  return $this->wrapLine( '+', 'diff-addedline', $line );
106  }
107 
115  protected function deletedLine( $line ) {
116  return $this->wrapLine( '−', 'diff-deletedline', $line );
117  }
118 
126  protected function contextLine( $line ) {
127  return $this->wrapLine( '&#160;', 'diff-context', $line );
128  }
129 
137  protected function wrapLine( $marker, $class, $line ) {
138  if ( $line !== '' ) {
139  // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
140  $line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
141  }
142 
143  return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
144  }
145 
149  protected function emptyLine() {
150  return '<td colspan="2">&#160;</td>';
151  }
152 
158  protected function added( $lines ) {
159  foreach ( $lines as $line ) {
160  $this->writeOutput( '<tr>' . $this->emptyLine() .
161  $this->addedLine( '<ins class="diffchange">' .
162  htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n" );
163  }
164  }
165 
171  protected function deleted( $lines ) {
172  foreach ( $lines as $line ) {
173  $this->writeOutput( '<tr>' . $this->deletedLine( '<del class="diffchange">' .
174  htmlspecialchars( $line ) . '</del>' ) .
175  $this->emptyLine() . "</tr>\n" );
176  }
177  }
178 
184  protected function context( $lines ) {
185  foreach ( $lines as $line ) {
186  $this->writeOutput( '<tr>' .
187  $this->contextLine( htmlspecialchars( $line ) ) .
188  $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n" );
189  }
190  }
191 
198  protected function changed( $orig, $closing ) {
199 
200  $diff = new WordLevelDiff( $orig, $closing );
201  $del = $diff->orig();
202  $add = $diff->closing();
203 
204  # Notice that WordLevelDiff returns HTML-escaped output.
205  # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
206 
207  $ndel = count( $del );
208  $nadd = count( $add );
209  $n = max( $ndel, $nadd );
210  for ( $i = 0; $i < $n; $i++ ) {
211  $delLine = $i < $ndel ? $this->deletedLine( $del[$i] ) : $this->emptyLine();
212  $addLine = $i < $nadd ? $this->addedLine( $add[$i] ) : $this->emptyLine();
213  $this->writeOutput( "<tr>{$delLine}{$addLine}</tr>\n" );
214  }
215  }
216 
217 }
added($lines)
Writes all lines to the output buffer, each enclosed in .
lines($lines, $prefix= ' ', $color= 'white')
context($lines)
Writes all lines to the output buffer, each enclosed in .
MediaWiki default table style diff formatter.
writeOutput($text)
Writes a string to the output buffer.
static escapeWhiteSpace($msg)
blockHeader($xbeg, $xlen, $ybeg, $ylen)
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
changed($orig, $closing)
Writes the two sets of lines to the output buffer, each enclosed in .
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:35
static tags($element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
$lines
Definition: router.php:66
startBlock($header)
Writes the header to the output buffer.
addedLine($line)
HTML-escape parameter before calling this.
deletedLine($line)
HTML-escape parameter before calling this.
wrapLine($marker, $class, $line)
$line
Definition: cdb.php:59
contextLine($line)
HTML-escape parameter before calling this.
deleted($lines)
Writes all lines to the output buffer, each enclosed in .
Base class for diff formatters.