MediaWiki  1.29.1
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 
222  public function __construct( $from_lines, $to_lines ) {
223  $eng = new DiffEngine;
224  $eng->setBailoutComplexity( $this->bailoutComplexity );
225  $this->edits = $eng->diff( $from_lines, $to_lines );
226  }
227 
231  public function getEdits() {
232  return $this->edits;
233  }
234 
246  public function reverse() {
247  $rev = $this;
248  $rev->edits = [];
250  foreach ( $this->edits as $edit ) {
251  $rev->edits[] = $edit->reverse();
252  }
253 
254  return $rev;
255  }
256 
262  public function isEmpty() {
263  foreach ( $this->edits as $edit ) {
264  if ( $edit->type != 'copy' ) {
265  return false;
266  }
267  }
268 
269  return true;
270  }
271 
279  public function lcs() {
280  $lcs = 0;
281  foreach ( $this->edits as $edit ) {
282  if ( $edit->type == 'copy' ) {
283  $lcs += count( $edit->orig );
284  }
285  }
286 
287  return $lcs;
288  }
289 
298  public function orig() {
299  $lines = [];
300 
301  foreach ( $this->edits as $edit ) {
302  if ( $edit->orig ) {
303  array_splice( $lines, count( $lines ), 0, $edit->orig );
304  }
305  }
306 
307  return $lines;
308  }
309 
318  public function closing() {
319  $lines = [];
320 
321  foreach ( $this->edits as $edit ) {
322  if ( $edit->closing ) {
323  array_splice( $lines, count( $lines ), 0, $edit->closing );
324  }
325  }
326 
327  return $lines;
328  }
329 }
330 
335 }
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
captcha-old.count
count
Definition: captcha-old.py:225
DiffOpCopy\$type
$type
Definition: DairikiDiff.php:107
Diff\closing
closing()
Get the closing set of lines.
Definition: DairikiDiff.php:318
DiffOpDelete\reverse
reverse()
Definition: DairikiDiff.php:143
Diff\lcs
lcs()
Compute the length of the Longest Common Subsequence (LCS).
Definition: DairikiDiff.php:279
Diff\reverse
reverse()
Compute reversed Diff.
Definition: DairikiDiff.php:246
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:35
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:11
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)
Constructor.
Definition: DairikiDiff.php:222
DiffEngine\setBailoutComplexity
setBailoutComplexity( $value)
Sets the complexity (in comparison operations) that can't be exceeded.
Definition: DiffEngine.php:139
$lines
$lines
Definition: router.php:67
DiffOpAdd\$type
$type
Definition: DairikiDiff.php:156
Diff\orig
orig()
Get the original set of lines.
Definition: DairikiDiff.php:298
Diff\isEmpty
isEmpty()
Check for empty diff.
Definition: DairikiDiff.php:262
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:231
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
HWLDFWordAccumulator
Definition: DairikiDiff.php:334
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
$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:1741
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
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