MediaWiki  REL1_31
DairikiDiff.php
Go to the documentation of this file.
1 <?php
37 abstract class DiffOp {
38 
42  public $type;
43 
47  public $orig;
48 
52  public $closing;
53 
57  public function getType() {
58  return $this->type;
59  }
60 
64  public function getOrig() {
65  return $this->orig;
66  }
67 
72  public function getClosing( $i = null ) {
73  if ( $i === null ) {
74  return $this->closing;
75  }
76  if ( array_key_exists( $i, $this->closing ) ) {
77  return $this->closing[$i];
78  }
79  return null;
80  }
81 
82  abstract public function reverse();
83 
87  public function norig() {
88  return $this->orig ? count( $this->orig ) : 0;
89  }
90 
94  public function nclosing() {
95  return $this->closing ? count( $this->closing ) : 0;
96  }
97 }
98 
106 class DiffOpCopy extends DiffOp {
107  public $type = 'copy';
108 
109  public function __construct( $orig, $closing = false ) {
110  if ( !is_array( $closing ) ) {
111  $closing = $orig;
112  }
113  $this->orig = $orig;
114  $this->closing = $closing;
115  }
116 
120  public function reverse() {
121  return new DiffOpCopy( $this->closing, $this->orig );
122  }
123 }
124 
132 class DiffOpDelete extends DiffOp {
133  public $type = 'delete';
134 
135  public function __construct( $lines ) {
136  $this->orig = $lines;
137  $this->closing = false;
138  }
139 
143  public function reverse() {
144  return new DiffOpAdd( $this->orig );
145  }
146 }
147 
155 class DiffOpAdd extends DiffOp {
156  public $type = 'add';
157 
158  public function __construct( $lines ) {
159  $this->closing = $lines;
160  $this->orig = false;
161  }
162 
166  public function reverse() {
167  return new DiffOpDelete( $this->closing );
168  }
169 }
170 
178 class DiffOpChange extends DiffOp {
179  public $type = 'change';
180 
181  public function __construct( $orig, $closing ) {
182  $this->orig = $orig;
183  $this->closing = $closing;
184  }
185 
189  public function reverse() {
190  return new DiffOpChange( $this->closing, $this->orig );
191  }
192 }
193 
200 class Diff {
201 
205  public $edits;
206 
211  protected $bailoutComplexity = 0;
212 
221  public function __construct( $from_lines, $to_lines ) {
222  $eng = new DiffEngine;
223  $eng->setBailoutComplexity( $this->bailoutComplexity );
224  $this->edits = $eng->diff( $from_lines, $to_lines );
225  }
226 
230  public function getEdits() {
231  return $this->edits;
232  }
233 
245  public function reverse() {
246  $rev = $this;
247  $rev->edits = [];
249  foreach ( $this->edits as $edit ) {
250  $rev->edits[] = $edit->reverse();
251  }
252 
253  return $rev;
254  }
255 
261  public function isEmpty() {
262  foreach ( $this->edits as $edit ) {
263  if ( $edit->type != 'copy' ) {
264  return false;
265  }
266  }
267 
268  return true;
269  }
270 
278  public function lcs() {
279  $lcs = 0;
280  foreach ( $this->edits as $edit ) {
281  if ( $edit->type == 'copy' ) {
282  $lcs += count( $edit->orig );
283  }
284  }
285 
286  return $lcs;
287  }
288 
297  public function orig() {
298  $lines = [];
299 
300  foreach ( $this->edits as $edit ) {
301  if ( $edit->orig ) {
302  array_splice( $lines, count( $lines ), 0, $edit->orig );
303  }
304  }
305 
306  return $lines;
307  }
308 
317  public function closing() {
318  $lines = [];
319 
320  foreach ( $this->edits as $edit ) {
321  if ( $edit->closing ) {
322  array_splice( $lines, count( $lines ), 0, $edit->closing );
323  }
324  }
325 
326  return $lines;
327  }
328 }
329 
334 }
Diff\$edits
DiffOp[] $edits
Definition: DairikiDiff.php:205
DiffOp
The base class for all other DiffOp classes.
Definition: DairikiDiff.php:37
DiffOpChange\__construct
__construct( $orig, $closing)
Definition: DairikiDiff.php:181
DiffOpDelete
Extends DiffOp.
Definition: DairikiDiff.php:132
DiffOpCopy\$type
$type
Definition: DairikiDiff.php:107
Diff\closing
closing()
Get the closing set of lines.
Definition: DairikiDiff.php:317
DiffOpDelete\reverse
reverse()
Definition: DairikiDiff.php:143
Diff\lcs
lcs()
Compute the length of the Longest Common Subsequence (LCS).
Definition: DairikiDiff.php:278
Diff\reverse
reverse()
Compute reversed Diff.
Definition: DairikiDiff.php:245
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
DiffOpChange
Extends DiffOp.
Definition: DairikiDiff.php:178
DiffOp\getOrig
getOrig()
Definition: DairikiDiff.php:64
edits
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs which is used to update link tables of transcluding pages after edits
Definition: deferred.txt:17
DiffOpCopy
Extends DiffOp.
Definition: DairikiDiff.php:106
MediaWiki\Diff\WordAccumulator
Stores, escapes and formats the results of word-level diff.
Definition: WordAccumulator.php:34
DiffOpAdd
Extends DiffOp.
Definition: DairikiDiff.php:155
Diff\__construct
__construct( $from_lines, $to_lines)
Computes diff between sequences of strings.
Definition: DairikiDiff.php:221
DiffEngine\setBailoutComplexity
setBailoutComplexity( $value)
Sets the complexity (in comparison operations) that can't be exceeded.
Definition: DiffEngine.php:138
$lines
$lines
Definition: router.php:61
DiffOpAdd\$type
$type
Definition: DairikiDiff.php:156
Diff\orig
orig()
Get the original set of lines.
Definition: DairikiDiff.php:297
Diff\isEmpty
isEmpty()
Check for empty diff.
Definition: DairikiDiff.php:261
DiffOp\reverse
reverse()
DiffOp\$orig
string[] $orig
Definition: DairikiDiff.php:47
DiffOpDelete\$type
$type
Definition: DairikiDiff.php:133
DiffOpAdd\reverse
reverse()
Definition: DairikiDiff.php:166
Diff\getEdits
getEdits()
Definition: DairikiDiff.php:230
Diff\$bailoutComplexity
int $bailoutComplexity
If this diff complexity is exceeded, a ComplexityException is thrown 0 means no limit.
Definition: DairikiDiff.php:211
DiffOp\$type
string $type
Definition: DairikiDiff.php:42
DiffOpChange\$type
$type
Definition: DairikiDiff.php:179
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1777
HWLDFWordAccumulator
Definition: DairikiDiff.php:333
DiffEngine
This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which in turn...
Definition: DiffEngine.php:44
DiffOpChange\reverse
reverse()
Definition: DairikiDiff.php:189
DiffOp\$closing
string[] $closing
Definition: DairikiDiff.php:52
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
DiffOp\nclosing
nclosing()
Definition: DairikiDiff.php:94
DiffOpCopy\reverse
reverse()
Definition: DairikiDiff.php:120
DiffOp\getType
getType()
Definition: DairikiDiff.php:57
DiffOp\getClosing
getClosing( $i=null)
Definition: DairikiDiff.php:72
DiffOpDelete\__construct
__construct( $lines)
Definition: DairikiDiff.php:135
DiffOp\norig
norig()
Definition: DairikiDiff.php:87
DiffOpAdd\__construct
__construct( $lines)
Definition: DairikiDiff.php:158
Diff
Class representing a 'diff' between two sequences of strings.
Definition: DairikiDiff.php:200
DiffOpCopy\__construct
__construct( $orig, $closing=false)
Definition: DairikiDiff.php:109