MediaWiki REL1_28
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
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
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)
Constructor.
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
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
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:1734
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
$lines
Definition router.php:67