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
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:1777
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:61