MediaWiki REL1_34
Diff.php
Go to the documentation of this file.
1<?php
32class Diff {
33
37 public $edits;
38
43 protected $bailoutComplexity = 0;
44
53 public function __construct( $from_lines, $to_lines ) {
54 $eng = new DiffEngine;
55 $eng->setBailoutComplexity( $this->bailoutComplexity );
56 $this->edits = $eng->diff( $from_lines, $to_lines );
57 }
58
62 public function getEdits() {
63 return $this->edits;
64 }
65
77 public function reverse() {
78 $rev = $this;
79 $rev->edits = [];
81 foreach ( $this->edits as $edit ) {
82 $rev->edits[] = $edit->reverse();
83 }
84
85 return $rev;
86 }
87
93 public function isEmpty() {
94 foreach ( $this->edits as $edit ) {
95 if ( $edit->type != 'copy' ) {
96 return false;
97 }
98 }
99
100 return true;
101 }
102
110 public function lcs() {
111 $lcs = 0;
112 foreach ( $this->edits as $edit ) {
113 if ( $edit->type == 'copy' ) {
114 $lcs += count( $edit->orig );
115 }
116 }
117
118 return $lcs;
119 }
120
129 public function orig() {
130 $lines = [];
131
132 foreach ( $this->edits as $edit ) {
133 if ( $edit->orig ) {
134 array_splice( $lines, count( $lines ), 0, $edit->orig );
135 }
136 }
137
138 return $lines;
139 }
140
149 public function closing() {
150 $lines = [];
151
152 foreach ( $this->edits as $edit ) {
153 if ( $edit->closing ) {
154 array_splice( $lines, count( $lines ), 0, $edit->closing );
155 }
156 }
157
158 return $lines;
159 }
160}
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.
The base class for all other DiffOp classes.
Definition DiffOp.php:37
Class representing a 'diff' between two sequences of strings.
Definition Diff.php:32
getEdits()
Definition Diff.php:62
int $bailoutComplexity
If this diff complexity is exceeded, a ComplexityException is thrown 0 means no limit.
Definition Diff.php:43
reverse()
Compute reversed Diff.
Definition Diff.php:77
orig()
Get the original set of lines.
Definition Diff.php:129
isEmpty()
Check for empty diff.
Definition Diff.php:93
lcs()
Compute the length of the Longest Common Subsequence (LCS).
Definition Diff.php:110
closing()
Get the closing set of lines.
Definition Diff.php:149
DiffOp[] $edits
Definition Diff.php:37
__construct( $from_lines, $to_lines)
Computes diff between sequences of strings.
Definition Diff.php:53
$lines
Definition router.php:61