MediaWiki
master
Toggle main menu visibility
Diff.php
Go to the documentation of this file.
1
<?php
12
13
namespace
Wikimedia\Diff;
14
20
class
Diff
{
21
25
public
$edits
;
26
31
protected
$bailoutComplexity
= 0;
32
44
public
function
__construct
( $from_lines, $to_lines ) {
45
$eng =
new
DiffEngine
;
46
$eng->
setBailoutComplexity
( $this->bailoutComplexity );
47
$this->edits = $eng->diff( $from_lines, $to_lines );
48
}
49
53
public
function
getEdits
() {
54
return
$this->edits
;
55
}
56
68
public
function
reverse
() {
69
$rev = $this;
70
$rev->edits = [];
72
foreach
( $this->edits as $edit ) {
73
$rev->edits[] = $edit->reverse();
74
}
75
76
return
$rev;
77
}
78
84
public
function
isEmpty
() {
85
foreach
( $this->edits as $edit ) {
86
if
( $edit->type !=
'copy'
) {
87
return
false
;
88
}
89
}
90
91
return
true
;
92
}
93
101
public
function
lcs
() {
102
$lcs = 0;
103
foreach
( $this->edits as $edit ) {
104
if
( $edit->type ==
'copy'
) {
105
$lcs += count( $edit->orig );
106
}
107
}
108
109
return
$lcs;
110
}
111
120
public
function
orig
() {
121
$lines = [];
122
123
foreach
( $this->edits as $edit ) {
124
if
( $edit->orig ) {
125
array_splice( $lines, count( $lines ), 0, $edit->orig );
126
}
127
}
128
129
return
$lines;
130
}
131
140
public
function
closing
() {
141
$lines = [];
142
143
foreach
( $this->edits as $edit ) {
144
if
( $edit->closing ) {
145
array_splice( $lines, count( $lines ), 0, $edit->closing );
146
}
147
}
148
149
return
$lines;
150
}
151
}
152
154
class_alias( Diff::class,
'Diff'
);
Wikimedia\Diff\DiffEngine
This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which in turn...
Definition
DiffEngine.php:34
Wikimedia\Diff\DiffEngine\setBailoutComplexity
setBailoutComplexity( $value)
Sets the complexity (in comparison operations) that can't be exceeded.
Definition
DiffEngine.php:145
Wikimedia\Diff\DiffOp
The base class for all other DiffOp classes.
Definition
DiffOp.php:24
Wikimedia\Diff\Diff
Class representing a 'diff' between two sequences of strings.
Definition
Diff.php:20
Wikimedia\Diff\Diff\__construct
__construct( $from_lines, $to_lines)
Computes diff between sequences of strings.
Definition
Diff.php:44
Wikimedia\Diff\Diff\isEmpty
isEmpty()
Check for empty diff.
Definition
Diff.php:84
Wikimedia\Diff\Diff\$edits
DiffOp[] $edits
Definition
Diff.php:25
Wikimedia\Diff\Diff\reverse
reverse()
Compute reversed Diff.
Definition
Diff.php:68
Wikimedia\Diff\Diff\$bailoutComplexity
int $bailoutComplexity
If this diff complexity is exceeded, a ComplexityException is thrown 0 means no limit.
Definition
Diff.php:31
Wikimedia\Diff\Diff\orig
orig()
Get the original set of lines.
Definition
Diff.php:120
Wikimedia\Diff\Diff\lcs
lcs()
Compute the length of the Longest Common Subsequence (LCS).
Definition
Diff.php:101
Wikimedia\Diff\Diff\closing
closing()
Get the closing set of lines.
Definition
Diff.php:140
Wikimedia\Diff\Diff\getEdits
getEdits()
Definition
Diff.php:53
includes
libs
Diff
Diff.php
Generated on
for MediaWiki by
1.18.0