MediaWiki REL1_31
DairikiDiff.php
Go to the documentation of this file.
1<?php
37abstract 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
106class 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
132class 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
155class 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
178class 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
200class 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
This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which in turn...
setBailoutComplexity( $value)
Sets the complexity (in comparison operations) that can't be exceeded.
Extends DiffOp.
__construct( $lines)
Extends DiffOp.
__construct( $orig, $closing)
Extends DiffOp.
__construct( $orig, $closing=false)
Extends DiffOp.
__construct( $lines)
The base class for all other DiffOp classes.
string[] $orig
getClosing( $i=null)
string $type
string[] $closing
Class representing a 'diff' between two sequences of strings.
int $bailoutComplexity
If this diff complexity is exceeded, a ComplexityException is thrown 0 means no limit.
reverse()
Compute reversed Diff.
orig()
Get the original set of lines.
isEmpty()
Check for empty diff.
lcs()
Compute the length of the Longest Common Subsequence (LCS).
closing()
Get the closing set of lines.
DiffOp[] $edits
__construct( $from_lines, $to_lines)
Computes diff between sequences of strings.
Stores, escapes and formats the results of word-level diff.
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
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
$lines
Definition router.php:61