MediaWiki  master
Diff.php
Go to the documentation of this file.
1 <?php
32 class 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 }
closing()
Get the closing set of lines.
Definition: Diff.php:149
getEdits()
Definition: Diff.php:62
reverse()
Compute reversed Diff.
Definition: Diff.php:77
lcs()
Compute the length of the Longest Common Subsequence (LCS).
Definition: Diff.php:110
orig()
Get the original set of lines.
Definition: Diff.php:129
isEmpty()
Check for empty diff.
Definition: Diff.php:93
Class representing a &#39;diff&#39; between two sequences of strings.
Definition: Diff.php:32
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:11
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:1747
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
Definition: distributors.txt:9
This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which in turn...
Definition: DiffEngine.php:47
setBailoutComplexity( $value)
Sets the complexity (in comparison operations) that can&#39;t be exceeded.
Definition: DiffEngine.php:141
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:35
$lines
Definition: router.php:61
int $bailoutComplexity
If this diff complexity is exceeded, a ComplexityException is thrown 0 means no limit.
Definition: Diff.php:43
DiffOp [] $edits
Definition: Diff.php:37
__construct( $from_lines, $to_lines)
Computes diff between sequences of strings.
Definition: Diff.php:53