MediaWiki REL1_37
Diff.php
Go to the documentation of this file.
1<?php
32class Diff {
33
37 public $edits;
38
43 protected $bailoutComplexity = 0;
44
56 public function __construct( $from_lines, $to_lines ) {
57 $eng = new DiffEngine;
58 $eng->setBailoutComplexity( $this->bailoutComplexity );
59 $this->edits = $eng->diff( $from_lines, $to_lines );
60 }
61
65 public function getEdits() {
66 return $this->edits;
67 }
68
80 public function reverse() {
81 $rev = $this;
82 $rev->edits = [];
84 foreach ( $this->edits as $edit ) {
85 $rev->edits[] = $edit->reverse();
86 }
87
88 return $rev;
89 }
90
96 public function isEmpty() {
97 foreach ( $this->edits as $edit ) {
98 if ( $edit->type != 'copy' ) {
99 return false;
100 }
101 }
102
103 return true;
104 }
105
113 public function lcs() {
114 $lcs = 0;
115 foreach ( $this->edits as $edit ) {
116 if ( $edit->type == 'copy' ) {
117 $lcs += count( $edit->orig );
118 }
119 }
120
121 return $lcs;
122 }
123
132 public function orig() {
133 $lines = [];
134
135 foreach ( $this->edits as $edit ) {
136 if ( $edit->orig ) {
137 array_splice( $lines, count( $lines ), 0, $edit->orig );
138 }
139 }
140
141 return $lines;
142 }
143
152 public function closing() {
153 $lines = [];
154
155 foreach ( $this->edits as $edit ) {
156 if ( $edit->closing ) {
157 array_splice( $lines, count( $lines ), 0, $edit->closing );
158 }
159 }
160
161 return $lines;
162 }
163}
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:65
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:80
orig()
Get the original set of lines.
Definition Diff.php:132
isEmpty()
Check for empty diff.
Definition Diff.php:96
lcs()
Compute the length of the Longest Common Subsequence (LCS).
Definition Diff.php:113
closing()
Get the closing set of lines.
Definition Diff.php:152
DiffOp[] $edits
Definition Diff.php:37
__construct( $from_lines, $to_lines)
Computes diff between sequences of strings.
Definition Diff.php:56
if(!file_exists( $CREDITS)) $lines