Index: trunk/phase3/includes/HTMLDiff.php |
— | — | @@ -18,15 +18,9 @@ |
19 | 19 | */ |
20 | 20 | |
21 | 21 | /** |
22 | | - * The HTML differ depends on WikiDiff3 |
23 | | - */ |
24 | | -global $IP; |
25 | | -require_once( "$IP/includes/Diff.php" ); |
26 | | - |
27 | | -/** |
28 | 22 | * Any element in the DOM tree of an HTML document. |
29 | 23 | */ |
30 | | -class Node{ |
| 24 | +class Node { |
31 | 25 | |
32 | 26 | public $parent; |
33 | 27 | |
— | — | @@ -36,23 +30,23 @@ |
37 | 31 | |
38 | 32 | public $whiteAfter = false; |
39 | 33 | |
40 | | - function __construct($parent){ |
| 34 | + function __construct($parent) { |
41 | 35 | $this->parent = $parent; |
42 | 36 | } |
43 | 37 | |
44 | | - public function getParentTree(){ |
45 | | - if(!isset($this->parentTree)){ |
46 | | - if(!is_null($this->parent)){ |
| 38 | + public function getParentTree() { |
| 39 | + if (!isset($this->parentTree)) { |
| 40 | + if (!is_null($this->parent)) { |
47 | 41 | $this->parentTree = $this->parent->getParentTree(); |
48 | 42 | $this->parentTree[] = $this->parent; |
49 | | - }else{ |
| 43 | + } else { |
50 | 44 | $this->parentTree = array(); |
51 | 45 | } |
52 | 46 | } |
53 | 47 | return $this->parentTree; |
54 | 48 | } |
55 | 49 | |
56 | | - public function getLastCommonParent(Node $other){ |
| 50 | + public function getLastCommonParent(Node $other) { |
57 | 51 | $result = new LastCommonParentResult(); |
58 | 52 | |
59 | 53 | $myParents = $this->getParentTree(); |
— | — | @@ -60,13 +54,13 @@ |
61 | 55 | |
62 | 56 | $i = 1; |
63 | 57 | $isSame = true; |
64 | | - $nbMyParents = sizeof($myParents); |
65 | | - $nbOtherParents = sizeof($otherParents); |
| 58 | + $nbMyParents = count($myParents); |
| 59 | + $nbOtherParents = count($otherParents); |
66 | 60 | while ($isSame && $i < $nbMyParents && $i < $nbOtherParents) { |
67 | 61 | if (!$myParents[$i]->openingTag === $otherParents[$i]->openingTag) { |
68 | 62 | $isSame = false; |
69 | 63 | } else { |
70 | | - // After the while, the index i-1 must be the last common parent |
| 64 | + // After a while, the index i-1 must be the last common parent |
71 | 65 | $i++; |
72 | 66 | } |
73 | 67 | } |
— | — | @@ -74,20 +68,13 @@ |
75 | 69 | $result->lastCommonParentDepth = $i - 1; |
76 | 70 | $result->parent = $myParents[$i - 1]; |
77 | 71 | |
78 | | - if (!$isSame) { |
| 72 | + if (!$isSame || $nbMyParents > $nbOtherParents) { |
| 73 | + // Not all tags matched, or all tags matched but |
| 74 | + // there are tags left in this tree |
79 | 75 | $result->indexInLastCommonParent = $myParents[$i - 1]->getIndexOf($myParents[$i]); |
80 | 76 | $result->splittingNeeded = true; |
81 | | - } else if ($nbMyParents < $nbOtherParents) { |
| 77 | + } else if ($nbMyParents <= $nbOtherParents) { |
82 | 78 | $result->indexInLastCommonParent = $myParents[$i - 1]->getIndexOf($this); |
83 | | - } else if ($nbMyParents > $nbOtherParents) { |
84 | | - // All tags matched but there are tags left in this tree |
85 | | - $result->indexInLastCommonParent = $myParents[$i - 1]->getIndexOf($myParents[$i]); |
86 | | - $result->splittingNeeded = true; |
87 | | - } else { |
88 | | - // All tags matched untill the very last one in both trees |
89 | | - // or there were no tags besides the BODY |
90 | | - $result->indexInLastCommonParent = $myParents[$i - 1]->getIndexOf($this); |
91 | | - } |
92 | 79 | return $result; |
93 | 80 | } |
94 | 81 | |
— | — | @@ -110,7 +97,7 @@ |
111 | 98 | /** |
112 | 99 | * Node that can contain other nodes. Represents an HTML tag. |
113 | 100 | */ |
114 | | -class TagNode extends Node{ |
| 101 | +class TagNode extends Node { |
115 | 102 | |
116 | 103 | public $children = array(); |
117 | 104 | |
— | — | @@ -126,25 +113,21 @@ |
127 | 114 | foreach($attributes as $key => $value){ |
128 | 115 | $this->attributes[strtolower($key)] = $value; |
129 | 116 | } |
130 | | - $this->openingTag = '<'.$this->qName; |
131 | | - foreach ($this->attributes as $attribute => $value) { |
132 | | - $this->openingTag .= ' ' . $attribute . '="' . $value . '"'; |
133 | | - } |
134 | | - return $this->openingTag .= '>'; |
| 117 | + return $this->openingTag = Xml::openElement($this->qName, $this->attributes); |
135 | 118 | } |
136 | 119 | |
137 | 120 | public function addChildAbsolute(Node $node, $index) { |
138 | | - array_splice($this->children,$index,0,array($node)); |
| 121 | + array_splice($this->children, $index, 0, array($node)); |
139 | 122 | } |
140 | 123 | |
141 | 124 | public function getIndexOf(Node $child) { |
142 | 125 | // don't trust array_search with objects |
143 | | - foreach($this->children as $key=>$value){ |
144 | | - if($value === $child){ |
| 126 | + foreach ($this->children as $key => $value){ |
| 127 | + if ($value === $child) { |
145 | 128 | return $key; |
146 | 129 | } |
147 | 130 | } |
148 | | - return NULL; |
| 131 | + return null; |
149 | 132 | } |
150 | 133 | |
151 | 134 | public function getNbChildren() { |
— | — | @@ -153,78 +136,79 @@ |
154 | 137 | |
155 | 138 | public function getMinimalDeletedSet($id, &$allDeleted, &$somethingDeleted) { |
156 | 139 | $nodes = array(); |
157 | | - if (empty($this->children)){ |
158 | | - $allDeleted = false; |
159 | | - $somethingDeleted = false; |
160 | | - return $nodes; |
161 | | - } |
162 | 140 | |
163 | 141 | $allDeleted = false; |
164 | 142 | $somethingDeleted = false; |
165 | | - $hasNotDeletedDescendant = false; |
| 143 | + $hasNonDeletedDescendant = false; |
166 | 144 | |
| 145 | + if (empty($this->children)) { |
| 146 | + return $nodes; |
| 147 | + } |
| 148 | + |
167 | 149 | foreach ($this->children as $child) { |
| 150 | + $allDeleted_local = false; |
| 151 | + $somethingDeleted_local = false; |
168 | 152 | $childrenChildren = $child->getMinimalDeletedSet($id, $allDeleted_local, $somethingDeleted_local); |
169 | | - if($somethingDeleted_local){ |
| 153 | + if ($somethingDeleted_local) { |
170 | 154 | $nodes = array_merge($nodes, $childrenChildren); |
171 | 155 | $somethingDeleted = true; |
172 | 156 | } |
173 | | - $hasNotDeletedDescendant |= !$allDeleted_local; |
| 157 | + if (!$allDeleted_local) { |
| 158 | + $hasNonDeletedDescendant = true; |
| 159 | + } |
174 | 160 | } |
175 | | - if (!$hasNotDeletedDescendant) { |
| 161 | + if (!$hasNonDeletedDescendant) { |
176 | 162 | $nodes = array($this); |
177 | 163 | $allDeleted = true; |
178 | 164 | } |
179 | 165 | return $nodes; |
180 | 166 | } |
181 | 167 | |
182 | | - public function splitUntill(TagNode $parent, Node $split, $includeLeft) { |
| 168 | + public function splitUntil(TagNode $parent, Node $split, $includeLeft) { |
183 | 169 | $splitOccured = false; |
184 | 170 | if ($parent !== $this) { |
185 | | - $part1 = new TagNode(NULL, $this->qName, $this->attributes); |
186 | | - $part2 = new TagNode(NULL, $this->qName, $this->attributes); |
| 171 | + $part1 = new TagNode(null, $this->qName, $this->attributes); |
| 172 | + $part2 = new TagNode(null, $this->qName, $this->attributes); |
187 | 173 | $part1->setParent($this->parent); |
188 | 174 | $part2->setParent($this->parent); |
189 | 175 | |
190 | | - $i = 0; |
191 | | - $nbChildren = $this->getNbChildren(); |
192 | | - while ($i < $nbChildren && $this->children[$i] !== $split) { |
193 | | - $this->children[$i]->setParent($part1); |
194 | | - $part1->children[] = $this->children[$i]; |
195 | | - ++$i; |
196 | | - } |
197 | | - if ($i < $nbChildren) { |
198 | | - if ($includeLeft) { |
199 | | - $this->children[$i]->setParent($part1); |
200 | | - $part1->children[] = $this->children[$i]; |
| 176 | + $onSplit = false; |
| 177 | + $pastSplit = false; |
| 178 | + foreach ($this->children as &$child) |
| 179 | + { |
| 180 | + if ($child === $split) { |
| 181 | + $onSplit = true; |
| 182 | + } |
| 183 | + if(!$pastSplit || ($onSplit && $includeLeft)) { |
| 184 | + $child->setParent($part1); |
| 185 | + $part1->children[] = $child; |
201 | 186 | } else { |
202 | | - $this->children[$i]->setParent($part2); |
203 | | - $part2->children[] = $this->children[$i]; |
| 187 | + $child->setParent($part2); |
| 188 | + $part2->children[] = $child; |
204 | 189 | } |
205 | | - ++$i; |
| 190 | + if ($onSplit) { |
| 191 | + $onSplit = false; |
| 192 | + $pastSplit = true; |
| 193 | + } |
206 | 194 | } |
207 | | - while ($i < $nbChildren) { |
208 | | - $this->children[$i]->setParent($part2); |
209 | | - $part2->children[] = $this->children[$i]; |
210 | | - ++$i; |
211 | | - } |
212 | 195 | $myindexinparent = $this->parent->getIndexOf($this); |
213 | | - if (!empty($part1->children)) |
214 | | - $this->parent->addChildAbsolute($part1,$myindexinparent); |
215 | | - |
216 | | - if (!empty($part2->children)) |
217 | | - $this->parent->addChildAbsolute($part2,$myindexinparent); |
218 | | - |
| 196 | + if (!empty($part1->children)) { |
| 197 | + $this->parent->addChildAbsolute($part1, $myindexinparent); |
| 198 | + } |
| 199 | + if (!empty($part2->children)) { |
| 200 | + $this->parent->addChildAbsolute($part2, $myindexinparent); |
| 201 | + } |
219 | 202 | if (!empty($part1->children) && !empty($part2->children)) { |
220 | 203 | $splitOccured = true; |
221 | 204 | } |
222 | 205 | |
223 | 206 | $this->parent->removeChild($myindexinparent); |
224 | 207 | |
225 | | - if ($includeLeft) |
226 | | - $this->parent->splitUntill($parent, $part1, $includeLeft); |
227 | | - else |
228 | | - $this->parent->splitUntill($parent, $part2, $includeLeft); |
| 208 | + if ($includeLeft) { |
| 209 | + $this->parent->splitUntil($parent, $part1, $includeLeft); |
| 210 | + } else { |
| 211 | + $this->parent->splitUntil($parent, $part2, $includeLeft); |
| 212 | + } |
229 | 213 | } |
230 | 214 | return $splitOccured; |
231 | 215 | |
— | — | @@ -235,15 +219,15 @@ |
236 | 220 | $this->children = array_values($this->children); |
237 | 221 | } |
238 | 222 | |
239 | | - public static $blocks = array('html'=>TRUE,'body'=>TRUE,'p'=>TRUE,'blockquote'=>TRUE, |
240 | | - 'h1'=>TRUE,'h2'=>TRUE,'h3'=>TRUE,'h4'=>TRUE,'h5'=>TRUE,'pre'=>TRUE,'div'=>TRUE,'ul'=>TRUE,'ol'=>TRUE,'li'=>TRUE, |
241 | | - 'table'=>TRUE,'tbody'=>TRUE,'tr'=>TRUE,'td'=>TRUE,'th'=>TRUE,'br'=>TRUE); |
| 223 | + public static $blocks = array('html', 'body','p','blockquote', 'h1', |
| 224 | + 'h2', 'h3', 'h4', 'h5', 'pre', 'div', 'ul', 'ol', 'li', 'table', |
| 225 | + 'tbody', 'tr', 'td', 'th', 'br'); |
242 | 226 | |
243 | 227 | public function copyTree() { |
244 | | - $newThis = new TagNode(NULL, $this->qName, $this->attributes); |
| 228 | + $newThis = new TagNode(null, $this->qName, $this->attributes); |
245 | 229 | $newThis->whiteBefore = $this->whiteBefore; |
246 | 230 | $newThis->whiteAfter = $this->whiteAfter; |
247 | | - foreach($this->children as $child) { |
| 231 | + foreach ($this->children as $child) { |
248 | 232 | $newChild = $child->copyTree(); |
249 | 233 | $newChild->setParent($newThis); |
250 | 234 | $newThis->children[] = $newChild; |
— | — | @@ -264,18 +248,18 @@ |
265 | 249 | for ($i = 0; $i < $nbOriginalChildren; ++$i) { |
266 | 250 | $child = $this->children[$i + $shift]; |
267 | 251 | |
268 | | - if($child instanceof TagNode){ |
| 252 | + if ($child instanceof TagNode) { |
269 | 253 | if (!$child->isPre()) { |
270 | 254 | $child->expandWhiteSpace(); |
271 | 255 | } |
272 | 256 | } |
273 | 257 | if (!$spaceAdded && $child->whiteBefore) { |
274 | | - $ws = new WhiteSpaceNode(NULL, ' ', $child->getLeftMostChild()); |
| 258 | + $ws = new WhiteSpaceNode(null, ' ', $child->getLeftMostChild()); |
275 | 259 | $ws->setParent($this); |
276 | 260 | $this->addChildAbsolute($ws,$i + ($shift++)); |
277 | 261 | } |
278 | 262 | if ($child->whiteAfter) { |
279 | | - $ws = new WhiteSpaceNode(NULL, ' ', $child->getRightMostChild()); |
| 263 | + $ws = new WhiteSpaceNode(null, ' ', $child->getRightMostChild()); |
280 | 264 | $ws->setParent($this); |
281 | 265 | $this->addChildAbsolute($ws,$i + 1 + ($shift++)); |
282 | 266 | $spaceAdded = true; |
— | — | @@ -287,15 +271,16 @@ |
288 | 272 | } |
289 | 273 | |
290 | 274 | public function getLeftMostChild() { |
291 | | - if (empty($this->children)) |
292 | | - return $this; |
| 275 | + if (empty($this->children)) { |
| 276 | + return $this; |
| 277 | + } |
293 | 278 | return $this->children[0]->getLeftMostChild(); |
294 | | - |
295 | 279 | } |
296 | 280 | |
297 | 281 | public function getRightMostChild() { |
298 | | - if (empty($this->children)) |
299 | | - return $this; |
| 282 | + if (empty($this->children)) { |
| 283 | + return $this; |
| 284 | + } |
300 | 285 | return $this->children[$this->getNbChildren() - 1]->getRightMostChild(); |
301 | 286 | } |
302 | 287 | |
— | — | @@ -303,7 +288,7 @@ |
304 | 289 | return 0 == strcasecmp($this->qName,'pre'); |
305 | 290 | } |
306 | 291 | |
307 | | - public static function toDiffLine(TagNode $node){ |
| 292 | + public static function toDiffLine(TagNode $node) { |
308 | 293 | return $node->openingTag; |
309 | 294 | } |
310 | 295 | } |
— | — | @@ -311,7 +296,7 @@ |
312 | 297 | /** |
313 | 298 | * Represents a piece of text in the HTML file. |
314 | 299 | */ |
315 | | -class TextNode extends Node{ |
| 300 | +class TextNode extends Node { |
316 | 301 | |
317 | 302 | public $text; |
318 | 303 | |
— | — | @@ -325,7 +310,7 @@ |
326 | 311 | |
327 | 312 | public function copyTree() { |
328 | 313 | $clone = clone $this; |
329 | | - $clone->setParent(NULL); |
| 314 | + $clone->setParent(null); |
330 | 315 | return $clone; |
331 | 316 | } |
332 | 317 | |
— | — | @@ -339,7 +324,7 @@ |
340 | 325 | |
341 | 326 | public function getMinimalDeletedSet($id, &$allDeleted, &$somethingDeleted) { |
342 | 327 | if ($this->modification->type == Modification::REMOVED |
343 | | - && $this->modification->id == $id){ |
| 328 | + && $this->modification->id == $id){ |
344 | 329 | $somethingDeleted = true; |
345 | 330 | $allDeleted = true; |
346 | 331 | return array($this); |
— | — | @@ -348,22 +333,22 @@ |
349 | 334 | } |
350 | 335 | |
351 | 336 | public function isSameText($other) { |
352 | | - if (is_null($other) || ! $other instanceof TextNode){ |
| 337 | + if (is_null($other) || ! $other instanceof TextNode) { |
353 | 338 | return false; |
354 | 339 | } |
355 | 340 | return str_replace('\n', ' ',$this->text) === str_replace('\n', ' ',$other->text); |
356 | 341 | } |
357 | 342 | |
358 | | - public static function toDiffLine(TextNode $node){ |
| 343 | + public static function toDiffLine(TextNode $node) { |
359 | 344 | return str_replace('\n', ' ',$node->text); |
360 | 345 | } |
361 | 346 | } |
362 | 347 | |
363 | 348 | class WhiteSpaceNode extends TextNode { |
364 | 349 | |
365 | | - function __construct($parent, $s, Node $like = NULL) { |
| 350 | + function __construct($parent, $s, Node $like = null) { |
366 | 351 | parent::__construct($parent, $s); |
367 | | - if(!is_null($like) && $like instanceof TextNode){ |
| 352 | + if(!is_null($like) && $like instanceof TextNode) { |
368 | 353 | $newModification = clone $like->modification; |
369 | 354 | $newModification->firstOfID = false; |
370 | 355 | $this->modification = $newModification; |
— | — | @@ -377,7 +362,7 @@ |
378 | 363 | class BodyNode extends TagNode { |
379 | 364 | |
380 | 365 | function __construct() { |
381 | | - parent::__construct(NULL, 'body', array()); |
| 366 | + parent::__construct(null, 'body', array()); |
382 | 367 | } |
383 | 368 | |
384 | 369 | public function copyTree() { |
— | — | @@ -393,7 +378,8 @@ |
394 | 379 | public function getMinimalDeletedSet($id, &$allDeleted, &$somethingDeleted) { |
395 | 380 | $nodes = array(); |
396 | 381 | foreach ($this->children as $child) { |
397 | | - $childrenChildren = $child->getMinimalDeletedSet($id,$allDeleted,$somethingDeleted); |
| 382 | + $childrenChildren = $child->getMinimalDeletedSet($id, |
| 383 | + $allDeleted, $somethingDeleted); |
398 | 384 | $nodes = array_merge($nodes, $childrenChildren); |
399 | 385 | } |
400 | 386 | return $nodes; |
— | — | @@ -410,11 +396,11 @@ |
411 | 397 | private $attributes; |
412 | 398 | |
413 | 399 | function __construct(TagNode $parent, /*array*/ $attrs) { |
414 | | - if(!array_key_exists('src',$attrs)){ |
| 400 | + if(!array_key_exists('src', $attrs)) { |
415 | 401 | //wfDebug('Image without a source:'); |
416 | | - foreach($attrs as $key => $value){ |
| 402 | + //foreach ($attrs as $key => $value) { |
417 | 403 | //wfDebug("$key = $value"); |
418 | | - } |
| 404 | + //} |
419 | 405 | parent::__construct($parent, '<img></img>'); |
420 | 406 | }else{ |
421 | 407 | parent::__construct($parent, '<img>' . strtolower($attrs['src']) . '</img>'); |
— | — | @@ -423,16 +409,17 @@ |
424 | 410 | } |
425 | 411 | |
426 | 412 | public function isSameText($other) { |
427 | | - if (is_null($other) || ! $other instanceof ImageNode) |
428 | | - return false; |
| 413 | + if (is_null($other) || ! $other instanceof ImageNode) { |
| 414 | + return false; |
| 415 | + } |
429 | 416 | return $this->text === $other->text; |
430 | 417 | } |
431 | 418 | |
432 | 419 | } |
433 | 420 | |
434 | | -class DummyNode extends Node{ |
| 421 | +class DummyNode extends Node { |
435 | 422 | |
436 | | - function __construct(){ |
| 423 | + function __construct() { |
437 | 424 | // no op |
438 | 425 | } |
439 | 426 | |
— | — | @@ -480,8 +467,8 @@ |
481 | 468 | $this->type = $type; |
482 | 469 | } |
483 | 470 | |
484 | | - public static function typeToString($type){ |
485 | | - switch($type){ |
| 471 | + public static function typeToString($type) { |
| 472 | + switch($type) { |
486 | 473 | case self::NONE: return 'none'; |
487 | 474 | case self::REMOVED: return 'removed'; |
488 | 475 | case self::ADDED: return 'added'; |
— | — | @@ -510,7 +497,7 @@ |
511 | 498 | |
512 | 499 | private $notInPre = true; |
513 | 500 | |
514 | | - function __construct(){ |
| 501 | + function __construct() { |
515 | 502 | $this->bodyNode = $this->currentParent = new BodyNode(); |
516 | 503 | $this->lastSibling = new DummyNode(); |
517 | 504 | } |
— | — | @@ -520,11 +507,11 @@ |
521 | 508 | */ |
522 | 509 | public function endDocument() { |
523 | 510 | $this->endWord(); |
524 | | - //wfDebug(sizeof($this->textNodes) . ' text nodes in document.'); |
| 511 | + //wfDebug(count($this->textNodes) . ' text nodes in document.'); |
525 | 512 | } |
526 | 513 | |
527 | 514 | public function startElement($parser, $name, /*array*/ $attributes) { |
528 | | - if(!strcasecmp($name, 'body')==0){ |
| 515 | + if (strcasecmp($name, 'body') != 0) { |
529 | 516 | //wfDebug("Starting $name node."); |
530 | 517 | $this->endWord(); |
531 | 518 | |
— | — | @@ -532,18 +519,18 @@ |
533 | 520 | $this->currentParent->children[] = $newNode; |
534 | 521 | $this->currentParent = $newNode; |
535 | 522 | $this->lastSibling = new DummyNode(); |
536 | | - if ($this->whiteSpaceBeforeThis && !array_key_exists(strtolower($this->currentParent->qName),TagNode::$blocks)) { |
| 523 | + if ($this->whiteSpaceBeforeThis && !in_array(strtolower($this->currentParent->qName),TagNode::$blocks)) { |
537 | 524 | $this->currentParent->whiteBefore = true; |
538 | 525 | } |
539 | 526 | $this->whiteSpaceBeforeThis = false; |
540 | | - if(strcasecmp($name, 'pre')==0){ |
| 527 | + if(strcasecmp($name, 'pre') == 0) { |
541 | 528 | $this->notInPre = false; |
542 | 529 | } |
543 | 530 | } |
544 | 531 | } |
545 | 532 | |
546 | 533 | public function endElement($parser, $name) { |
547 | | - if(!strcasecmp($name, 'body')==0){ |
| 534 | + if(strcasecmp($name, 'body') != 0) { |
548 | 535 | //wfDebug("Ending $name node."); |
549 | 536 | if (0 == strcasecmp($name,'img')) { |
550 | 537 | // Insert a dummy leaf for the image |
— | — | @@ -554,17 +541,17 @@ |
555 | 542 | $this->textNodes[] = $img; |
556 | 543 | } |
557 | 544 | $this->endWord(); |
558 | | - if (!array_key_exists(strtolower($this->currentParent->qName),TagNode::$blocks)) { |
| 545 | + if (!in_array(strtolower($this->currentParent->qName),TagNode::$blocks)) { |
559 | 546 | $this->lastSibling = $this->currentParent; |
560 | 547 | } else { |
561 | 548 | $this->lastSibling = new DummyNode(); |
562 | 549 | } |
563 | 550 | $this->currentParent = $this->currentParent->parent; |
564 | 551 | $this->whiteSpaceBeforeThis = false; |
565 | | - if(!$this->notInPre && strcasecmp($name, 'pre')==0){ |
| 552 | + if (!$this->notInPre && strcasecmp($name, 'pre') == 0) { |
566 | 553 | $this->notInPre = true; |
567 | 554 | } |
568 | | - }else{ |
| 555 | + } else { |
569 | 556 | $this->endDocument(); |
570 | 557 | } |
571 | 558 | } |
— | — | @@ -573,15 +560,15 @@ |
574 | 561 | const whitespace = '/^[\s]{1}$/'; |
575 | 562 | const delimiter = '/^[\s\.\,\"\\\'\(\)\?\:\;\!\{\}\-\+\*\=\_\[\]\&\|\$]{1}$/'; |
576 | 563 | |
577 | | - public function characters($parser, $data){ |
578 | | - $matches = preg_split(self::regex,$data,-1,PREG_SPLIT_DELIM_CAPTURE); |
| 564 | + public function characters($parser, $data) { |
| 565 | + $matches = preg_split(self::regex, $data, -1, PREG_SPLIT_DELIM_CAPTURE); |
579 | 566 | |
580 | | - foreach($matches as $word){ |
581 | | - if(preg_match(self::whitespace, $word) && $this->notInPre){ |
| 567 | + foreach($matches as $word) { |
| 568 | + if (preg_match(self::whitespace, $word) && $this->notInPre) { |
582 | 569 | $this->endWord(); |
583 | 570 | $this->lastSibling->whiteAfter = true; |
584 | 571 | $this->whiteSpaceBeforeThis = true; |
585 | | - }else if(preg_match(self::delimiter, $word)){ |
| 572 | + } else if (preg_match(self::delimiter, $word)) { |
586 | 573 | $this->endWord(); |
587 | 574 | $textNode = new TextNode($this->currentParent, $word); |
588 | 575 | $this->currentParent->children[] = $textNode; |
— | — | @@ -589,7 +576,7 @@ |
590 | 577 | $this->whiteSpaceBeforeThis = false; |
591 | 578 | $this->lastSibling = $textNode; |
592 | 579 | $this->textNodes[] = $textNode; |
593 | | - }else{ |
| 580 | + } else { |
594 | 581 | $this->newWord .= $word; |
595 | 582 | } |
596 | 583 | } |
— | — | @@ -607,12 +594,12 @@ |
608 | 595 | } |
609 | 596 | } |
610 | 597 | |
611 | | - public function getDiffLines(){ |
| 598 | + public function getDiffLines() { |
612 | 599 | return array_map(array('TextNode','toDiffLine'), $this->textNodes); |
613 | 600 | } |
614 | 601 | } |
615 | 602 | |
616 | | -class TextNodeDiffer{ |
| 603 | +class TextNodeDiffer { |
617 | 604 | |
618 | 605 | private $textNodes; |
619 | 606 | public $bodyNode; |
— | — | @@ -621,7 +608,18 @@ |
622 | 609 | private $oldBodyNode; |
623 | 610 | |
624 | 611 | private $lastModified = array(); |
| 612 | + |
| 613 | + private $newID = 0; |
| 614 | + |
| 615 | + private $changedID = 0; |
625 | 616 | |
| 617 | + private $changedIDUsed = false; |
| 618 | + |
| 619 | + // used to remove the whitespace between a red and green block |
| 620 | + private $whiteAfterLastChangedPart = false; |
| 621 | + |
| 622 | + private $deletedID = 0; |
| 623 | + |
626 | 624 | function __construct(DomTreeBuilder $tree, DomTreeBuilder $oldTree) { |
627 | 625 | $this->textNodes = $tree->textNodes; |
628 | 626 | $this->bodyNode = $tree->bodyNode; |
— | — | @@ -629,21 +627,21 @@ |
630 | 628 | $this->oldBodyNode = $oldTree->bodyNode; |
631 | 629 | } |
632 | 630 | |
633 | | - private $newID = 0; |
634 | | - |
635 | 631 | public function markAsNew($start, $end) { |
636 | | - if ($end <= $start) |
637 | | - return; |
| 632 | + if ($end <= $start) { |
| 633 | + return; |
| 634 | + } |
638 | 635 | |
639 | | - if ($this->whiteAfterLastChangedPart) |
640 | | - $this->textNodes[$start]->whiteBefore = false; |
| 636 | + if ($this->whiteAfterLastChangedPart) { |
| 637 | + $this->textNodes[$start]->whiteBefore = false; |
| 638 | + } |
641 | 639 | |
642 | 640 | $nextLastModified = array(); |
643 | 641 | |
644 | 642 | for ($i = $start; $i < $end; ++$i) { |
645 | 643 | $mod = new Modification(Modification::ADDED); |
646 | 644 | $mod->id = $this->newID; |
647 | | - if (sizeof($this->lastModified) > 0) { |
| 645 | + if (count($this->lastModified) > 0) { |
648 | 646 | $mod->prevMod = $this->lastModified[0]; |
649 | 647 | if (is_null($this->lastModified[0]->nextMod )) { |
650 | 648 | foreach ($this->lastModified as $lastMod) { |
— | — | @@ -661,10 +659,6 @@ |
662 | 660 | $this->lastModified = $nextLastModified; |
663 | 661 | } |
664 | 662 | |
665 | | - private $changedID = 0; |
666 | | - |
667 | | - private $changedIDUsed = false; |
668 | | - |
669 | 663 | public function handlePossibleChangedPart($leftstart, $leftend, $rightstart, $rightend) { |
670 | 664 | $i = $rightstart; |
671 | 665 | $j = $leftstart; |
— | — | @@ -683,20 +677,20 @@ |
684 | 678 | $result = $acthis->getResult($acother); |
685 | 679 | unset($acthis, $acother); |
686 | 680 | |
687 | | - $nbLastModified = sizeof($this->lastModified); |
| 681 | + $nbLastModified = count($this->lastModified); |
688 | 682 | if ($result->changed) { |
689 | 683 | $mod = new Modification(Modification::CHANGED); |
690 | 684 | |
691 | 685 | if (!$this->changedIDUsed) { |
692 | 686 | $mod->firstOfID = true; |
693 | | - if (sizeof($nextLastModified) > 0) { |
| 687 | + if (count($nextLastModified) > 0) { |
694 | 688 | $this->lastModified = $nextLastModified; |
695 | 689 | $nextLastModified = array(); |
696 | 690 | } |
697 | 691 | } else if (!is_null($result->changes) && $result->changes !== $this->changes) { |
698 | 692 | ++$this->changedID; |
699 | 693 | $mod->firstOfID = true; |
700 | | - if (sizeof($nextLastModified) > 0) { |
| 694 | + if (count($nextLastModified) > 0) { |
701 | 695 | $this->lastModified = $nextLastModified; |
702 | 696 | $nextLastModified = array(); |
703 | 697 | } |
— | — | @@ -725,20 +719,16 @@ |
726 | 720 | ++$i; |
727 | 721 | ++$j; |
728 | 722 | } |
729 | | - if (sizeof($nextLastModified) > 0){ |
| 723 | + if (count($nextLastModified) > 0) { |
730 | 724 | $this->lastModified = $nextLastModified; |
731 | 725 | } |
732 | 726 | } |
733 | 727 | |
734 | | - // used to remove the whitespace between a red and green block |
735 | | - private $whiteAfterLastChangedPart = false; |
736 | | - |
737 | | - private $deletedID = 0; |
738 | | - |
739 | 728 | public function markAsDeleted($start, $end, $before) { |
740 | 729 | |
741 | | - if ($end <= $start) |
742 | | - return; |
| 730 | + if ($end <= $start) { |
| 731 | + return; |
| 732 | + } |
743 | 733 | |
744 | 734 | if ($before > 0 && $this->textNodes[$before - 1]->whiteAfter) { |
745 | 735 | $this->whiteAfterLastChangedPart = true; |
— | — | @@ -751,7 +741,7 @@ |
752 | 742 | for ($i = $start; $i < $end; ++$i) { |
753 | 743 | $mod = new Modification(Modification::REMOVED); |
754 | 744 | $mod->id = $this->deletedID; |
755 | | - if (sizeof($this->lastModified) > 0) { |
| 745 | + if (count($this->lastModified) > 0) { |
756 | 746 | $mod->prevMod = $this->lastModified[0]; |
757 | 747 | if (is_null($this->lastModified[0]->nextMod )) { |
758 | 748 | foreach ($this->lastModified as $lastMod) { |
— | — | @@ -762,30 +752,30 @@ |
763 | 753 | $nextLastModified[] = $mod; |
764 | 754 | |
765 | 755 | // oldTextNodes is used here because we're going to move its deleted |
766 | | - // elements |
767 | | - // to this tree! |
| 756 | + // elements to this tree! |
768 | 757 | $this->oldTextNodes[$i]->modification = $mod; |
769 | 758 | } |
770 | 759 | $this->oldTextNodes[$start]->modification->firstOfID = true; |
771 | 760 | |
772 | 761 | $root = $this->oldTextNodes[$start]->getLastCommonParent($this->oldTextNodes[$end-1])->parent; |
773 | 762 | |
| 763 | + $junk1 = $junk2 = null; |
774 | 764 | $deletedNodes = $root->getMinimalDeletedSet($this->deletedID, $junk1, $junk2); |
775 | 765 | |
776 | | - //wfDebug("Minimal set of deleted nodes of size " . sizeof($deletedNodes)); |
| 766 | + //wfDebug("Minimal set of deleted nodes of size " . count($deletedNodes)); |
777 | 767 | |
778 | 768 | // Set prevLeaf to the leaf after which the old HTML needs to be |
779 | 769 | // inserted |
780 | | - if ($before > 0){ |
| 770 | + if ($before > 0) { |
781 | 771 | $prevLeaf = $this->textNodes[$before - 1]; |
782 | 772 | } |
783 | 773 | // Set nextLeaf to the leaf before which the old HTML needs to be |
784 | 774 | // inserted |
785 | | - if ($before < sizeof($this->textNodes)){ |
| 775 | + if ($before < count($this->textNodes)) { |
786 | 776 | $nextLeaf = $this->textNodes[$before]; |
787 | 777 | } |
788 | 778 | |
789 | | - while (sizeof($deletedNodes) > 0) { |
| 779 | + while (count($deletedNodes) > 0) { |
790 | 780 | if (isset($prevLeaf)) { |
791 | 781 | $prevResult = $prevLeaf->getLastCommonParent($deletedNodes[0]); |
792 | 782 | } else { |
— | — | @@ -794,7 +784,7 @@ |
795 | 785 | $prevResult->indexInLastCommonParent = 0; |
796 | 786 | } |
797 | 787 | if (isset($nextleaf)) { |
798 | | - $nextResult = $nextLeaf->getLastCommonParent($deletedNodes[sizeof($deletedNodes) - 1]); |
| 788 | + $nextResult = $nextLeaf->getLastCommonParent($deletedNodes[count($deletedNodes) - 1]); |
799 | 789 | } else { |
800 | 790 | $nextResult = new LastCommonParentResult(); |
801 | 791 | $nextResult->parent = $this->bodyNode; |
— | — | @@ -803,15 +793,15 @@ |
804 | 794 | |
805 | 795 | if ($prevResult->lastCommonParentDepth == $nextResult->lastCommonParentDepth) { |
806 | 796 | // We need some metric to choose which way to add-... |
807 | | - if ($deletedNodes[0]->parent === $deletedNodes[sizeof($deletedNodes) - 1]->parent |
808 | | - && $prevResult->parent === $nextResult->parent) { |
| 797 | + if ($deletedNodes[0]->parent === $deletedNodes[count($deletedNodes) - 1]->parent |
| 798 | + && $prevResult->parent === $nextResult->parent) { |
809 | 799 | // The difference is not in the parent |
810 | 800 | $prevResult->lastCommonParentDepth = $prevResult->lastCommonParentDepth + 1; |
811 | 801 | } else { |
812 | 802 | // The difference is in the parent, so compare them |
813 | 803 | // now THIS is tricky |
814 | 804 | $distancePrev = $deletedNodes[0]->parent->getMatchRatio($prevResult->parent); |
815 | | - $distanceNext = $deletedNodes[sizeof($deletedNodes) - 1]->parent->getMatchRatio($nextResult->parent); |
| 805 | + $distanceNext = $deletedNodes[count($deletedNodes) - 1]->parent->getMatchRatio($nextResult->parent); |
816 | 806 | |
817 | 807 | if ($distancePrev <= $distanceNext) { |
818 | 808 | $prevResult->lastCommonParentDepth = $prevResult->lastCommonParentDepth + 1; |
— | — | @@ -825,7 +815,7 @@ |
826 | 816 | if ($prevResult->lastCommonParentDepth > $nextResult->lastCommonParentDepth) { |
827 | 817 | // Inserting at the front |
828 | 818 | if ($prevResult->splittingNeeded) { |
829 | | - $prevLeaf->parent->splitUntill($prevResult->parent, $prevLeaf, true); |
| 819 | + $prevLeaf->parent->splitUntil($prevResult->parent, $prevLeaf, true); |
830 | 820 | } |
831 | 821 | $prevLeaf = $deletedNodes[0]->copyTree(); |
832 | 822 | unset($deletedNodes[0]); |
— | — | @@ -835,20 +825,21 @@ |
836 | 826 | } else if ($prevResult->lastCommonParentDepth < $nextResult->lastCommonParentDepth) { |
837 | 827 | // Inserting at the back |
838 | 828 | if ($nextResult->splittingNeeded) { |
839 | | - $splitOccured = $nextLeaf->parent->splitUntill($nextResult->parent, $nextLeaf, false); |
| 829 | + $splitOccured = $nextLeaf->parent->splitUntil($nextResult->parent, $nextLeaf, false); |
840 | 830 | if ($splitOccured) { |
841 | 831 | // The place where to insert is shifted one place to the |
842 | 832 | // right |
843 | 833 | $nextResult->indexInLastCommonParent = $nextResult->indexInLastCommonParent + 1; |
844 | 834 | } |
845 | 835 | } |
846 | | - $nextLeaf = $deletedNodes[sizeof(deletedNodes) - 1]->copyTree(); |
847 | | - unset($deletedNodes[sizeof(deletedNodes) - 1]); |
| 836 | + $nextLeaf = $deletedNodes[count(deletedNodes) - 1]->copyTree(); |
| 837 | + unset($deletedNodes[count(deletedNodes) - 1]); |
848 | 838 | $deletedNodes = array_values($deletedNodes); |
849 | 839 | $nextLeaf->setParent($nextResult->parent); |
850 | 840 | $nextResult->parent->addChildAbsolute($nextLeaf,$nextResult->indexInLastCommonParent); |
851 | | - } else |
852 | | - throw new Exception("Uh?"); |
| 841 | + } else { |
| 842 | + throw new Exception("Uh?"); |
| 843 | + } |
853 | 844 | } |
854 | 845 | $this->lastModified = $nextLastModified; |
855 | 846 | ++$this->deletedID; |
— | — | @@ -859,23 +850,23 @@ |
860 | 851 | } |
861 | 852 | |
862 | 853 | public function lengthNew(){ |
863 | | - return sizeof($this->textNodes); |
| 854 | + return count($this->textNodes); |
864 | 855 | } |
865 | 856 | |
866 | 857 | public function lengthOld(){ |
867 | | - return sizeof($this->oldTextNodes); |
| 858 | + return count($this->oldTextNodes); |
868 | 859 | } |
869 | 860 | } |
870 | 861 | |
871 | | -class HTMLDiffer{ |
| 862 | +class HTMLDiffer { |
872 | 863 | |
873 | 864 | private $output; |
874 | 865 | |
875 | | - function __construct($output){ |
| 866 | + function __construct($output) { |
876 | 867 | $this->output = $output; |
877 | 868 | } |
878 | 869 | |
879 | | - function htmlDiff($from, $to){ |
| 870 | + function htmlDiff($from, $to) { |
880 | 871 | wfProfileIn( __METHOD__ ); |
881 | 872 | // Create an XML parser |
882 | 873 | $xml_parser = xml_parser_create(''); |
— | — | @@ -883,16 +874,18 @@ |
884 | 875 | $domfrom = new DomTreeBuilder(); |
885 | 876 | |
886 | 877 | // Set the functions to handle opening and closing tags |
887 | | - xml_set_element_handler($xml_parser, array($domfrom,"startElement"), array($domfrom,"endElement")); |
| 878 | + xml_set_element_handler($xml_parser, array($domfrom, "startElement"), array($domfrom, "endElement")); |
888 | 879 | |
889 | 880 | // Set the function to handle blocks of character data |
890 | | - xml_set_character_data_handler($xml_parser, array($domfrom,"characters")); |
| 881 | + xml_set_character_data_handler($xml_parser, array($domfrom, "characters")); |
891 | 882 | |
892 | 883 | //wfDebug('Parsing '.strlen($from)." characters worth of HTML\n"); |
893 | | - if (!xml_parse($xml_parser, '<?xml version="1.0" encoding="UTF-8"?>'.Sanitizer::hackDocType().'<body>', FALSE) |
894 | | - || !xml_parse($xml_parser, $from, FALSE) |
895 | | - || !xml_parse($xml_parser, '</body>', TRUE)){ |
896 | | - wfDebug(sprintf("XML error: %s at line %d\n",xml_error_string(xml_get_error_code($xml_parser)),xml_get_current_line_number($xml_parser))); |
| 884 | + if (!xml_parse($xml_parser, '<?xml version="1.0" encoding="UTF-8"?>'.Sanitizer::hackDocType().'<body>', false) |
| 885 | + || !xml_parse($xml_parser, $from, false) |
| 886 | + || !xml_parse($xml_parser, '</body>', true)){ |
| 887 | + $error = xml_error_string(xml_get_error_code($xml_parser)); |
| 888 | + $line = xml_get_current_line_number($xml_parser); |
| 889 | + wfDebug("XML error: $error at line $line\n"); |
897 | 890 | } |
898 | 891 | xml_parser_free($xml_parser); |
899 | 892 | unset($from); |
— | — | @@ -902,25 +895,26 @@ |
903 | 896 | $domto = new DomTreeBuilder(); |
904 | 897 | |
905 | 898 | // Set the functions to handle opening and closing tags |
906 | | - xml_set_element_handler($xml_parser, array($domto,"startElement"), array($domto,"endElement")); |
| 899 | + xml_set_element_handler($xml_parser, array($domto, "startElement"), array($domto, "endElement")); |
907 | 900 | |
908 | 901 | // Set the function to handle blocks of character data |
909 | | - xml_set_character_data_handler($xml_parser, array($domto,"characters")); |
| 902 | + xml_set_character_data_handler($xml_parser, array($domto, "characters")); |
910 | 903 | |
911 | 904 | //wfDebug('Parsing '.strlen($to)." characters worth of HTML\n"); |
912 | | - if (!xml_parse($xml_parser, '<?xml version="1.0" encoding="UTF-8"?>'.Sanitizer::hackDocType().'<body>', FALSE) |
913 | | - || !xml_parse($xml_parser, $to, FALSE) |
914 | | - || !xml_parse($xml_parser, '</body>', TRUE)){ |
915 | | - wfDebug(sprintf("XML error in HTML diff: %s at line %d\n",xml_error_string(xml_get_error_code($xml_parser)),xml_get_current_line_number($xml_parser))); |
| 905 | + if (!xml_parse($xml_parser, '<?xml version="1.0" encoding="UTF-8"?>'.Sanitizer::hackDocType().'<body>', false) |
| 906 | + || !xml_parse($xml_parser, $to, false) |
| 907 | + || !xml_parse($xml_parser, '</body>', true)){ |
| 908 | + $error = xml_error_string(xml_get_error_code($xml_parser)); |
| 909 | + $line = xml_get_current_line_number($xml_parser); |
| 910 | + wfDebug("XML error: $error at line $line\n"); |
916 | 911 | } |
917 | 912 | xml_parser_free($xml_parser); |
918 | 913 | unset($to); |
919 | 914 | |
920 | 915 | $diffengine = new WikiDiff3(); |
921 | 916 | $differences = $this->preProcess($diffengine->diff_range($domfrom->getDiffLines(), $domto->getDiffLines())); |
922 | | - unset($xml_parser,$diffengine); |
| 917 | + unset($xml_parser, $diffengine); |
923 | 918 | |
924 | | - |
925 | 919 | $domdiffer = new TextNodeDiffer($domto, $domfrom); |
926 | 920 | |
927 | 921 | $currentIndexLeft = 0; |
— | — | @@ -928,7 +922,7 @@ |
929 | 923 | foreach ($differences as $d) { |
930 | 924 | if ($d->leftstart > $currentIndexLeft) { |
931 | 925 | $domdiffer->handlePossibleChangedPart($currentIndexLeft, $d->leftstart, |
932 | | - $currentIndexRight, $d->rightstart); |
| 926 | + $currentIndexRight, $d->rightstart); |
933 | 927 | } |
934 | 928 | if ($d->leftlength > 0) { |
935 | 929 | $domdiffer->markAsDeleted($d->leftstart, $d->leftend, $d->rightstart); |
— | — | @@ -940,7 +934,7 @@ |
941 | 935 | } |
942 | 936 | $oldLength = $domdiffer->lengthOld(); |
943 | 937 | if ($currentIndexLeft < $oldLength) { |
944 | | - $domdiffer->handlePossibleChangedPart($currentIndexLeft,$oldLength, $currentIndexRight,$domdiffer->lengthNew()); |
| 938 | + $domdiffer->handlePossibleChangedPart($currentIndexLeft, $oldLength, $currentIndexRight, $domdiffer->lengthNew()); |
945 | 939 | } |
946 | 940 | $domdiffer->expandWhiteSpace(); |
947 | 941 | $output = new HTMLOutput('htmldiff', $this->output); |
— | — | @@ -948,10 +942,10 @@ |
949 | 943 | wfProfileOut( __METHOD__ ); |
950 | 944 | } |
951 | 945 | |
952 | | - private function preProcess(/*array*/ $differences){ |
| 946 | + private function preProcess(/*array*/ $differences) { |
953 | 947 | $newRanges = array(); |
954 | 948 | |
955 | | - $nbDifferences = sizeof($differences); |
| 949 | + $nbDifferences = count($differences); |
956 | 950 | for ($i = 0; $i < $nbDifferences; ++$i) { |
957 | 951 | $leftStart = $differences[$i]->leftstart; |
958 | 952 | $leftEnd = $differences[$i]->leftend; |
— | — | @@ -961,8 +955,11 @@ |
962 | 956 | $leftLength = $leftEnd - $leftStart; |
963 | 957 | $rightLength = $rightEnd - $rightStart; |
964 | 958 | |
965 | | - while ($i + 1 < $nbDifferences && self::score($leftLength, $differences[$i + 1]->leftlength, |
966 | | - $rightLength, $differences[$i + 1]->rightlength) > ($differences[$i + 1]->leftstart - $leftEnd)) { |
| 959 | + while ($i + 1 < $nbDifferences && self::score($leftLength, |
| 960 | + $differences[$i + 1]->leftlength, |
| 961 | + $rightLength, |
| 962 | + $differences[$i + 1]->rightlength) |
| 963 | + > ($differences[$i + 1]->leftstart - $leftEnd)) { |
967 | 964 | $leftEnd = $differences[$i + 1]->leftend; |
968 | 965 | $rightEnd = $differences[$i + 1]->rightend; |
969 | 966 | $leftLength = $leftEnd - $leftStart; |
— | — | @@ -979,7 +976,7 @@ |
980 | 977 | */ |
981 | 978 | public static function score($ll, $nll, $rl, $nrl) { |
982 | 979 | if (($ll == 0 && $nll == 0) |
983 | | - || ($rl == 0 && $nrl == 0)){ |
| 980 | + || ($rl == 0 && $nrl == 0)) { |
984 | 981 | return 0; |
985 | 982 | } |
986 | 983 | $numbers = array($ll, $nll, $rl, $nrl); |
— | — | @@ -993,12 +990,12 @@ |
994 | 991 | $d += $number; |
995 | 992 | |
996 | 993 | } |
997 | | - return $d / (1.5 * sizeof($numbers)); |
| 994 | + return $d / (1.5 * count($numbers)); |
998 | 995 | } |
999 | 996 | |
1000 | 997 | } |
1001 | 998 | |
1002 | | -class TextOnlyComparator{ |
| 999 | +class TextOnlyComparator { |
1003 | 1000 | |
1004 | 1001 | public $leafs = array(); |
1005 | 1002 | |
— | — | @@ -1018,13 +1015,13 @@ |
1019 | 1016 | } |
1020 | 1017 | |
1021 | 1018 | public function getMatchRatio(TextOnlyComparator $other) { |
1022 | | - $nbOthers = sizeof($other->leafs); |
1023 | | - $nbThis = sizeof($this->leafs); |
| 1019 | + $nbOthers = count($other->leafs); |
| 1020 | + $nbThis = count($this->leafs); |
1024 | 1021 | if($nbOthers == 0 || $nbThis == 0){ |
1025 | 1022 | return -log(0); |
1026 | 1023 | } |
1027 | 1024 | |
1028 | | - $diffengine = new WikiDiff3(25000,1.35); |
| 1025 | + $diffengine = new WikiDiff3(25000, 1.35); |
1029 | 1026 | $diffengine->diff($this->leafs, $other->leafs); |
1030 | 1027 | |
1031 | 1028 | $lcsLength = $diffengine->getLcsLength(); |
— | — | @@ -1045,7 +1042,7 @@ |
1046 | 1043 | /** |
1047 | 1044 | * A comparator used when calculating the difference in ancestry of two Nodes. |
1048 | 1045 | */ |
1049 | | -class AncestorComparator{ |
| 1046 | +class AncestorComparator { |
1050 | 1047 | |
1051 | 1048 | public $ancestors; |
1052 | 1049 | public $ancestorsText; |
— | — | @@ -1060,10 +1057,10 @@ |
1061 | 1058 | public function getResult(AncestorComparator $other) { |
1062 | 1059 | $result = new AncestorComparatorResult(); |
1063 | 1060 | |
1064 | | - $diffengine = new WikiDiff3(10000,1.35); |
| 1061 | + $diffengine = new WikiDiff3(10000, 1.35); |
1065 | 1062 | $differences = $diffengine->diff_range($this->ancestorsText, $other->ancestorsText); |
1066 | 1063 | |
1067 | | - if (sizeof($differences) == 0){ |
| 1064 | + if (count($differences) == 0){ |
1068 | 1065 | return $result; |
1069 | 1066 | } |
1070 | 1067 | $changeTxt = new ChangeTextGenerator($this, $other); |
— | — | @@ -1093,12 +1090,12 @@ |
1094 | 1091 | |
1095 | 1092 | $rootlistopened = false; |
1096 | 1093 | |
1097 | | - if (sizeof($differences) > 1) { |
| 1094 | + if (count($differences) > 1) { |
1098 | 1095 | $txt->addHtml('<ul class="changelist">'); |
1099 | 1096 | $rootlistopened = true; |
1100 | 1097 | } |
1101 | 1098 | |
1102 | | - $nbDifferences = sizeof($differences); |
| 1099 | + $nbDifferences = count($differences); |
1103 | 1100 | for ($j = 0; $j < $nbDifferences; ++$j) { |
1104 | 1101 | $d = $differences[$j]; |
1105 | 1102 | |
— | — | @@ -1197,74 +1194,34 @@ |
1198 | 1195 | |
1199 | 1196 | class TagToStringFactory { |
1200 | 1197 | |
1201 | | - private static $containerTags = array( |
1202 | | - 'html' => TRUE, |
1203 | | - 'body' => TRUE, |
1204 | | - 'p' => TRUE, |
1205 | | - 'blockquote' => TRUE, |
1206 | | - 'h1' => TRUE, |
1207 | | - 'h2' => TRUE, |
1208 | | - 'h3' => TRUE, |
1209 | | - 'h4' => TRUE, |
1210 | | - 'h5' => TRUE, |
1211 | | - 'pre' => TRUE, |
1212 | | - 'div' => TRUE, |
1213 | | - 'ul' => TRUE, |
1214 | | - 'ol' => TRUE, |
1215 | | - 'li' => TRUE, |
1216 | | - 'table' => TRUE, |
1217 | | - 'tbody' => TRUE, |
1218 | | - 'tr' => TRUE, |
1219 | | - 'td' => TRUE, |
1220 | | - 'th' => TRUE, |
1221 | | - 'br' => TRUE, |
1222 | | - 'hr' => TRUE, |
1223 | | - 'code' => TRUE, |
1224 | | - 'dl' => TRUE, |
1225 | | - 'dt' => TRUE, |
1226 | | - 'dd' => TRUE, |
1227 | | - 'input' => TRUE, |
1228 | | - 'form' => TRUE, |
1229 | | - 'img' => TRUE, |
1230 | | - // in-line tags that can be considered containers not styles |
1231 | | - 'span' => TRUE, |
1232 | | - 'a' => TRUE |
1233 | | - ); |
| 1198 | + private static $containerTags = array('html', 'body', 'p', 'blockquote', |
| 1199 | + 'h1', 'h2', 'h3', 'h4', 'h5', 'pre', 'div', 'ul', 'ol', 'li', |
| 1200 | + 'table', 'tbody', 'tr', 'td', 'th', 'br', 'hr', 'code', 'dl', |
| 1201 | + 'dt', 'dd', 'input', 'form', 'img', 'span', 'a'); |
| 1202 | + |
| 1203 | + private static $styleTags = array('i', 'b', 'strong', 'em', 'font', |
| 1204 | + 'big', 'del', 'tt', 'sub', 'sup', 'strike'); |
1234 | 1205 | |
1235 | | - private static $styleTags = array( |
1236 | | - 'i' => TRUE, |
1237 | | - 'b' => TRUE, |
1238 | | - 'strong' => TRUE, |
1239 | | - 'em' => TRUE, |
1240 | | - 'font' => TRUE, |
1241 | | - 'big' => TRUE, |
1242 | | - 'del' => TRUE, |
1243 | | - 'tt' => TRUE, |
1244 | | - 'sub' => TRUE, |
1245 | | - 'sup' => TRUE, |
1246 | | - 'strike' => TRUE |
1247 | | - ); |
1248 | | - |
1249 | 1206 | const MOVED = 1; |
1250 | 1207 | const STYLE = 2; |
1251 | 1208 | const UNKNOWN = 4; |
1252 | 1209 | |
1253 | 1210 | public function create(TagNode $node) { |
1254 | 1211 | $sem = $this->getChangeSemantic($node->qName); |
1255 | | - if (0 == strcasecmp($node->qName,'a')){ |
| 1212 | + if (strcasecmp($node->qName,'a') == 0) { |
1256 | 1213 | return new AnchorToString($node, $sem); |
1257 | 1214 | } |
1258 | | - if (0 == strcasecmp($node->qName,'img')){ |
| 1215 | + if (strcasecmp($node->qName,'img') == 0) { |
1259 | 1216 | return new NoContentTagToString($node, $sem); |
1260 | 1217 | } |
1261 | 1218 | return new TagToString($node, $sem); |
1262 | 1219 | } |
1263 | 1220 | |
1264 | 1221 | protected function getChangeSemantic($qname) { |
1265 | | - if (array_key_exists(strtolower($qname),self::$containerTags)){ |
| 1222 | + if (in_array(strtolower($qname),self::$containerTags)) { |
1266 | 1223 | return self::MOVED; |
1267 | 1224 | } |
1268 | | - if (array_key_exists(strtolower($qname),self::$styleTags)){ |
| 1225 | + if (in_array(strtolower($qname),self::$styleTags)) { |
1269 | 1226 | return self::STYLE; |
1270 | 1227 | } |
1271 | 1228 | return self::UNKNOWN; |
— | — | @@ -1353,24 +1310,31 @@ |
1354 | 1311 | } |
1355 | 1312 | |
1356 | 1313 | protected function addAttributes(ChangeText $txt, array $attributes) { |
1357 | | - if (sizeof($attributes) < 1) |
1358 | | - return; |
1359 | | - |
1360 | | - $keys = array_keys($attributes); |
1361 | | - |
1362 | | - $txt->addText(' ' . strtolower($this->getWith()) . ' ' |
1363 | | - . $this->translateArgument($keys[0]) . ' ' |
1364 | | - . $attributes[$keys[0]]); |
1365 | | - for ($i = 1; $i < sizeof($attributes) - 1; $i++) { |
1366 | | - $txt->addText(', ' . $this->translateArgument($keys[$i]) . ' ' |
1367 | | - . $attributes[$keys[$i]]); |
| 1314 | + if (count($attributes) < 1) { |
| 1315 | + return; |
1368 | 1316 | } |
1369 | | - if (sizeof($attributes) > 1) { |
| 1317 | + |
| 1318 | + $firstOne = true; |
| 1319 | + $lastKey = null; |
| 1320 | + foreach ($attributes as $key => $attr) { |
| 1321 | + $lastKey = $key; |
| 1322 | + if($firstOne) { |
| 1323 | + $firstOne = false; |
| 1324 | + $txt->addText(' ' . strtolower($this->getWith()) |
| 1325 | + . ' ' . $this->translateArgument($key) . ' ' |
| 1326 | + . $attr); |
| 1327 | + continue; |
| 1328 | + } |
| 1329 | + $txt->addText(', ' . $this->translateArgument($key) . ' ' |
| 1330 | + . $attr); |
| 1331 | + } |
| 1332 | + |
| 1333 | + if (count($attributes) > 1) { |
1370 | 1334 | $txt->addText(' ' |
1371 | 1335 | . strtolower($this->getAnd()) |
1372 | 1336 | . ' ' |
1373 | | - . $this->translateArgument($keys[sizeof($attributes) - 1]) . ' ' |
1374 | | - . $attributes[$keys[sizeof($attributes) - 1]]); |
| 1337 | + . $this->translateArgument($lastKey) . ' ' |
| 1338 | + . $attributes[$lastKey]); |
1375 | 1339 | } |
1376 | 1340 | } |
1377 | 1341 | |
— | — | @@ -1383,12 +1347,15 @@ |
1384 | 1348 | } |
1385 | 1349 | |
1386 | 1350 | protected function translateArgument($name) { |
1387 | | - if (0 == strcasecmp($name,'src')) |
1388 | | - return strtolower($this->getSource()); |
1389 | | - if (0 == strcasecmp($name,'width')) |
1390 | | - return strtolower($this->getWidth()); |
1391 | | - if (0 == strcasecmp($name,'height')) |
1392 | | - return strtolower($this->getHeight()); |
| 1351 | + if (strcasecmp($name, 'src') == 0) { |
| 1352 | + return strtolower($this->getSource()); |
| 1353 | + } |
| 1354 | + if (strcasecmp($name, 'width') == 0) { |
| 1355 | + return strtolower($this->getWidth()); |
| 1356 | + } |
| 1357 | + if (strcasecmp($name, 'height') == 0) { |
| 1358 | + return strtolower($this->getHeight()); |
| 1359 | + } |
1393 | 1360 | return $name; |
1394 | 1361 | } |
1395 | 1362 | |
— | — | @@ -1408,92 +1375,93 @@ |
1409 | 1376 | return $this->getString('diff-' . $this->node->qName . '-article'); |
1410 | 1377 | } |
1411 | 1378 | |
| 1379 | + // FIXME: Use messages for this |
1412 | 1380 | public static $bundle = array( |
1413 | | - 'diff-movedto' => 'Moved to', |
1414 | | - 'diff-styleadded' => 'Style added', |
1415 | | - 'diff-added' => 'Added', |
1416 | | - 'diff-changedto' => 'Changed to', |
1417 | | - 'diff-movedoutof' => 'Moved out of', |
1418 | | - 'diff-styleremoved' => 'Style removed', |
1419 | | - 'diff-removed' => 'Removed', |
1420 | | - 'diff-changedfrom' => 'Changed from', |
1421 | | - 'diff-source' => 'Source', |
1422 | | - 'diff-withdestination' => 'With destination', |
1423 | | - 'diff-and' => 'And', |
1424 | | - 'diff-with' => 'With', |
1425 | | - 'diff-width' => 'Width', |
1426 | | - 'diff-height' => 'Height', |
1427 | | - 'diff-html-article' => 'A', |
1428 | | - 'diff-html' => 'Html page', |
1429 | | - 'diff-body-article' => 'A', |
1430 | | - 'diff-body' => 'Html document', |
1431 | | - 'diff-p-article' => 'A', |
1432 | | - 'diff-p' => 'Paragraph', |
1433 | | - 'diff-blockquote-article' => 'A', |
1434 | | - 'diff-blockquote' => 'Quote', |
1435 | | - 'diff-h1-article' => 'A', |
1436 | | - 'diff-h1' => 'Heading (level 1)', |
1437 | | - 'diff-h2-article' => 'A', |
1438 | | - 'diff-h2' => 'Heading (level 2)', |
1439 | | - 'diff-h3-article' => 'A', |
1440 | | - 'diff-h3' => 'Heading (level 3)', |
1441 | | - 'diff-h4-article' => 'A', |
1442 | | - 'diff-h4' => 'Heading (level 4)', |
1443 | | - 'diff-h5-article' => 'A', |
1444 | | - 'diff-h5' => 'Heading (level 5)', |
1445 | | - 'diff-pre-article' => 'A', |
1446 | | - 'diff-pre' => 'Preformatted block', |
1447 | | - 'diff-div-article' => 'A', |
1448 | | - 'diff-div' => 'Division', |
1449 | | - 'diff-ul-article' => 'An', |
1450 | | - 'diff-ul' => 'Unordered list', |
1451 | | - 'diff-ol-article' => 'An', |
1452 | | - 'diff-ol' => 'Ordered list', |
1453 | | - 'diff-li-article' => 'A', |
1454 | | - 'diff-li' => 'List item', |
1455 | | - 'diff-table-article' => 'A', |
1456 | | - 'diff-table' => 'Table', |
1457 | | - 'diff-tbody-article' => 'A', |
1458 | | - 'diff-tbody' => "Table's content", |
1459 | | - 'diff-tr-article' => 'A', |
1460 | | - 'diff-tr' => 'Row', |
1461 | | - 'diff-td-article' => 'A', |
1462 | | - 'diff-td' => 'Cell', |
1463 | | - 'diff-th-article' => 'A', |
1464 | | - 'diff-th' => 'Header', |
1465 | | - 'diff-br-article' => 'A', |
1466 | | - 'diff-br' => 'Break', |
1467 | | - 'diff-hr-article' => 'A', |
1468 | | - 'diff-hr' => 'Horizontal rule', |
1469 | | - 'diff-code-article' => 'A', |
1470 | | - 'diff-code' => 'Computer code block', |
1471 | | - 'diff-dl-article' => 'A', |
1472 | | - 'diff-dl' => 'Definition list', |
1473 | | - 'diff-dt-article' => 'A', |
1474 | | - 'diff-dt' => 'Definition term', |
1475 | | - 'diff-dd-article' => 'A', |
1476 | | - 'diff-dd' => 'Definition', |
1477 | | - 'diff-input-article' => 'An', |
1478 | | - 'diff-input' => 'Input', |
1479 | | - 'diff-form-article' => 'A', |
1480 | | - 'diff-form' => 'Form', |
1481 | | - 'diff-img-article' => 'An', |
1482 | | - 'diff-img' => 'Image', |
1483 | | - 'diff-span-article' => 'A', |
1484 | | - 'diff-span' => 'Span', |
1485 | | - 'diff-a-article' => 'A', |
1486 | | - 'diff-a' => 'Link', |
1487 | | - 'diff-i' => 'Italics', |
1488 | | - 'diff-b' => 'Bold', |
1489 | | - 'diff-strong' => 'Strong', |
1490 | | - 'diff-em' => 'Emphasis', |
1491 | | - 'diff-font' => 'Font', |
1492 | | - 'diff-big' => 'Big', |
1493 | | - 'diff-del' => 'Deleted', |
1494 | | - 'diff-tt' => 'Fixed width', |
1495 | | - 'diff-sub' => 'Subscript', |
1496 | | - 'diff-sup' => 'Superscript', |
1497 | | - 'diff-strike' => 'Strikethrough' |
| 1381 | + 'diff-movedto' => 'Moved to', |
| 1382 | + 'diff-styleadded' => 'Style added', |
| 1383 | + 'diff-added' => 'Added', |
| 1384 | + 'diff-changedto' => 'Changed to', |
| 1385 | + 'diff-movedoutof' => 'Moved out of', |
| 1386 | + 'diff-styleremoved' => 'Style removed', |
| 1387 | + 'diff-removed' => 'Removed', |
| 1388 | + 'diff-changedfrom' => 'Changed from', |
| 1389 | + 'diff-source' => 'Source', |
| 1390 | + 'diff-withdestination' => 'With destination', |
| 1391 | + 'diff-and' => 'And', |
| 1392 | + 'diff-with' => 'With', |
| 1393 | + 'diff-width' => 'Width', |
| 1394 | + 'diff-height' => 'Height', |
| 1395 | + 'diff-html-article' => 'A', |
| 1396 | + 'diff-html' => 'Html page', |
| 1397 | + 'diff-body-article' => 'A', |
| 1398 | + 'diff-body' => 'Html document', |
| 1399 | + 'diff-p-article' => 'A', |
| 1400 | + 'diff-p' => 'Paragraph', |
| 1401 | + 'diff-blockquote-article' => 'A', |
| 1402 | + 'diff-blockquote' => 'Quote', |
| 1403 | + 'diff-h1-article' => 'A', |
| 1404 | + 'diff-h1' => 'Heading (level 1)', |
| 1405 | + 'diff-h2-article' => 'A', |
| 1406 | + 'diff-h2' => 'Heading (level 2)', |
| 1407 | + 'diff-h3-article' => 'A', |
| 1408 | + 'diff-h3' => 'Heading (level 3)', |
| 1409 | + 'diff-h4-article' => 'A', |
| 1410 | + 'diff-h4' => 'Heading (level 4)', |
| 1411 | + 'diff-h5-article' => 'A', |
| 1412 | + 'diff-h5' => 'Heading (level 5)', |
| 1413 | + 'diff-pre-article' => 'A', |
| 1414 | + 'diff-pre' => 'Preformatted block', |
| 1415 | + 'diff-div-article' => 'A', |
| 1416 | + 'diff-div' => 'Division', |
| 1417 | + 'diff-ul-article' => 'An', |
| 1418 | + 'diff-ul' => 'Unordered list', |
| 1419 | + 'diff-ol-article' => 'An', |
| 1420 | + 'diff-ol' => 'Ordered list', |
| 1421 | + 'diff-li-article' => 'A', |
| 1422 | + 'diff-li' => 'List item', |
| 1423 | + 'diff-table-article' => 'A', |
| 1424 | + 'diff-table' => 'Table', |
| 1425 | + 'diff-tbody-article' => 'A', |
| 1426 | + 'diff-tbody' => "Table's content", |
| 1427 | + 'diff-tr-article' => 'A', |
| 1428 | + 'diff-tr' => 'Row', |
| 1429 | + 'diff-td-article' => 'A', |
| 1430 | + 'diff-td' => 'Cell', |
| 1431 | + 'diff-th-article' => 'A', |
| 1432 | + 'diff-th' => 'Header', |
| 1433 | + 'diff-br-article' => 'A', |
| 1434 | + 'diff-br' => 'Break', |
| 1435 | + 'diff-hr-article' => 'A', |
| 1436 | + 'diff-hr' => 'Horizontal rule', |
| 1437 | + 'diff-code-article' => 'A', |
| 1438 | + 'diff-code' => 'Computer code block', |
| 1439 | + 'diff-dl-article' => 'A', |
| 1440 | + 'diff-dl' => 'Definition list', |
| 1441 | + 'diff-dt-article' => 'A', |
| 1442 | + 'diff-dt' => 'Definition term', |
| 1443 | + 'diff-dd-article' => 'A', |
| 1444 | + 'diff-dd' => 'Definition', |
| 1445 | + 'diff-input-article' => 'An', |
| 1446 | + 'diff-input' => 'Input', |
| 1447 | + 'diff-form-article' => 'A', |
| 1448 | + 'diff-form' => 'Form', |
| 1449 | + 'diff-img-article' => 'An', |
| 1450 | + 'diff-img' => 'Image', |
| 1451 | + 'diff-span-article' => 'A', |
| 1452 | + 'diff-span' => 'Span', |
| 1453 | + 'diff-a-article' => 'A', |
| 1454 | + 'diff-a' => 'Link', |
| 1455 | + 'diff-i' => 'Italics', |
| 1456 | + 'diff-b' => 'Bold', |
| 1457 | + 'diff-strong' => 'Strong', |
| 1458 | + 'diff-em' => 'Emphasis', |
| 1459 | + 'diff-font' => 'Font', |
| 1460 | + 'diff-big' => 'Big', |
| 1461 | + 'diff-del' => 'Deleted', |
| 1462 | + 'diff-tt' => 'Fixed width', |
| 1463 | + 'diff-sub' => 'Subscript', |
| 1464 | + 'diff-sup' => 'Superscript', |
| 1465 | + 'diff-strike' => 'Strikethrough' |
1498 | 1466 | ); |
1499 | 1467 | |
1500 | 1468 | public function getString($key) { |
— | — | @@ -1543,7 +1511,7 @@ |
1544 | 1512 | } |
1545 | 1513 | |
1546 | 1514 | protected function addAttributes(ChangeText $txt, array $attributes) { |
1547 | | - if (array_key_exists('href',$attributes)) { |
| 1515 | + if (array_key_exists('href', $attributes)) { |
1548 | 1516 | $txt->addText(' ' . strtolower($this->getWithDestination()) . ' ' . $attributes['href']); |
1549 | 1517 | unset($attributes['href']); |
1550 | 1518 | } |
— | — | @@ -1572,7 +1540,7 @@ |
1573 | 1541 | public function parse(TagNode $node) { |
1574 | 1542 | $handler = &$this->handler; |
1575 | 1543 | |
1576 | | - if (0 != strcasecmp($node->qName,'img') && 0 != strcasecmp($node->qName,'body')) { |
| 1544 | + if (strcasecmp($node->qName, 'img') != 0 && strcasecmp($node->qName, 'body') != 0) { |
1577 | 1545 | $handler->startElement($node->qName, $node->attributes); |
1578 | 1546 | } |
1579 | 1547 | |
— | — | @@ -1600,7 +1568,8 @@ |
1601 | 1569 | if ($newStarted && ($mod->type != Modification::ADDED || $mod->firstOfID)) { |
1602 | 1570 | $handler->endElement('span'); |
1603 | 1571 | $newStarted = false; |
1604 | | - } else if ($changeStarted && ($mod->type != Modification::CHANGED || $mod->changes != $changeTXT || $mod->firstOfID)) { |
| 1572 | + } else if ($changeStarted && ($mod->type != Modification::CHANGED |
| 1573 | + || $mod->changes != $changeTXT || $mod->firstOfID)) { |
1605 | 1574 | $handler->endElement('span'); |
1606 | 1575 | $changeStarted = false; |
1607 | 1576 | } else if ($remStarted && ($mod->type != Modification::REMOVED || $mod ->firstOfID)) { |
— | — | @@ -1611,25 +1580,25 @@ |
1612 | 1581 | // no else because a removed part can just be closed and a new |
1613 | 1582 | // part can start |
1614 | 1583 | if (!$newStarted && $mod->type == Modification::ADDED) { |
1615 | | - $attrs = array('class'=>'diff-html-added'); |
| 1584 | + $attrs = array('class' => 'diff-html-added'); |
1616 | 1585 | if ($mod->firstOfID) { |
1617 | | - $attrs['id'] = 'added-' . $this->prefix . '-' . $mod->id; |
| 1586 | + $attrs['id'] = "added-{$this->prefix}-{$mod->id}"; |
1618 | 1587 | } |
1619 | 1588 | $this->addAttributes($mod, $attrs); |
1620 | 1589 | $attrs['onclick'] = 'return tipA(constructToolTipA(this));'; |
1621 | 1590 | $handler->startElement('span', $attrs); |
1622 | 1591 | $newStarted = true; |
1623 | 1592 | } else if (!$changeStarted && $mod->type == Modification::CHANGED) { |
1624 | | - $attrs = array('class'=>'diff-html-changed'); |
| 1593 | + $attrs = array('class' => 'diff-html-changed'); |
1625 | 1594 | if ($mod->firstOfID) { |
1626 | | - $attrs['id'] = 'changed-' . $this->prefix . '-' . $mod->id; |
| 1595 | + $attrs['id'] = "changed-{$this->prefix}-{$mod->id}"; |
1627 | 1596 | } |
1628 | 1597 | $this->addAttributes($mod, $attrs); |
1629 | 1598 | $attrs['onclick'] = 'return tipC(constructToolTipC(this));'; |
1630 | 1599 | $handler->startElement('span', $attrs); |
1631 | 1600 | |
1632 | 1601 | //tooltip |
1633 | | - $handler->startElement('span', array('class'=>'tip')); |
| 1602 | + $handler->startElement('span', array('class' => 'tip')); |
1634 | 1603 | $handler->characters($mod->changes); |
1635 | 1604 | $handler->endElement('span'); |
1636 | 1605 | |
— | — | @@ -1638,7 +1607,7 @@ |
1639 | 1608 | } else if (!$remStarted && $mod->type == Modification::REMOVED) { |
1640 | 1609 | $attrs = array('class'=>'diff-html-removed'); |
1641 | 1610 | if ($mod->firstOfID) { |
1642 | | - $attrs['id'] = 'removed-' . $this->prefix . '-' . $mod->id; |
| 1611 | + $attrs['id'] = "removed-{$this->prefix}-{$mod->id}"; |
1643 | 1612 | } |
1644 | 1613 | $this->addAttributes($mod, $attrs); |
1645 | 1614 | $attrs['onclick'] = 'return tipR(constructToolTipR(this));'; |
— | — | @@ -1668,17 +1637,19 @@ |
1669 | 1638 | $remStarted = false; |
1670 | 1639 | } |
1671 | 1640 | |
1672 | | - if (0 != strcasecmp($node->qName,'img') |
1673 | | - && 0 != strcasecmp($node->qName,'body')) |
1674 | | - $handler->endElement($node->qName); |
| 1641 | + if (strcasecmp($node->qName, 'img') != 0 |
| 1642 | + && strcasecmp($node->qName, 'body') != 0) { |
| 1643 | + $handler->endElement($node->qName); |
| 1644 | + } |
1675 | 1645 | } |
1676 | 1646 | |
1677 | | - private function writeImage(ImageNode $imgNode){ |
| 1647 | + private function writeImage(ImageNode $imgNode) { |
1678 | 1648 | $attrs = $imgNode->attributes; |
1679 | | - if ($imgNode->modification->type == Modification::REMOVED) |
1680 | | - $attrs['changeType']='diff-removed-image'; |
1681 | | - else if ($imgNode->modification->type == Modification::ADDED) |
1682 | | - $attrs['changeType'] = 'diff-added-image'; |
| 1649 | + if ($imgNode->modification->type == Modification::REMOVED) { |
| 1650 | + $attrs['changeType']='diff-removed-image'; |
| 1651 | + } else if ($imgNode->modification->type == Modification::ADDED) { |
| 1652 | + $attrs['changeType'] = 'diff-added-image'; |
| 1653 | + } |
1683 | 1654 | $attrs['onload'] = 'updateOverlays()'; |
1684 | 1655 | $attrs['onError'] = 'updateOverlays()'; |
1685 | 1656 | $attrs['onAbort'] = 'updateOverlays()'; |
— | — | @@ -1690,36 +1661,33 @@ |
1691 | 1662 | if (is_null($mod->prevMod)) { |
1692 | 1663 | $previous = 'first-' . $this->prefix; |
1693 | 1664 | } else { |
1694 | | - $previous = Modification::typeToString($mod->prevMod->type) . '-' . $this->prefix . '-' |
1695 | | - . $mod->prevMod->id; |
| 1665 | + $type = Modification::typeToString($mod->prevMod->type); |
| 1666 | + $previous = "$type-{$this->prefix}-{$mod->prevMod->id}"; |
1696 | 1667 | } |
1697 | 1668 | $attrs['previous'] = $previous; |
1698 | 1669 | |
1699 | | - $changeId = Modification::typeToString($mod->type) . '-' + $this->prefix . '-' . $mod->id; |
| 1670 | + $type = Modification::typeToString($mod->type); |
| 1671 | + $changeId = "$type-{$this->prefix}-{$mod->id}"; |
1700 | 1672 | $attrs['changeId'] = $changeId; |
1701 | 1673 | |
1702 | 1674 | if (is_null($mod->nextMod )) { |
1703 | | - $next = 'last-' . $this->prefix; |
| 1675 | + $next = "last-{$this->prefix}"; |
1704 | 1676 | } else { |
1705 | | - $next = Modification::typeToString($mod->nextMod ->type) . '-' . $this->prefix . '-' |
1706 | | - . $mod->nextMod ->id; |
| 1677 | + $type = Modification::typeToString($mod->nextMod->type); |
| 1678 | + $next = "$type-{$this->prefix}-{$mod->nextMod->id}"; |
1707 | 1679 | } |
1708 | 1680 | $attrs['next'] = $next; |
1709 | 1681 | } |
1710 | 1682 | } |
1711 | 1683 | |
1712 | | -class EchoingContentHandler{ |
| 1684 | +class EchoingContentHandler { |
1713 | 1685 | |
1714 | | - function startElement($qname, /*array*/ $arguments){ |
1715 | | - echo '<'.$qname; |
1716 | | - foreach($arguments as $key => $value){ |
1717 | | - echo ' '.$key.'="'.Sanitizer::encodeAttribute($value).'"'; |
1718 | | - } |
1719 | | - echo '>'; |
| 1686 | + function startElement($qname, /*array*/ $arguments) { |
| 1687 | + echo Xml::openElement($qname, $arguments); |
1720 | 1688 | } |
1721 | 1689 | |
1722 | 1690 | function endElement($qname){ |
1723 | | - echo '</'.$qname.'>'; |
| 1691 | + echo Xml::closeElement($qname); |
1724 | 1692 | } |
1725 | 1693 | |
1726 | 1694 | function characters($chars){ |
— | — | @@ -1728,28 +1696,23 @@ |
1729 | 1697 | |
1730 | 1698 | } |
1731 | 1699 | |
1732 | | -class DelegatingContentHandler{ |
| 1700 | +class DelegatingContentHandler { |
1733 | 1701 | |
1734 | 1702 | private $delegate; |
1735 | 1703 | |
1736 | | - function __construct($delegate){ |
1737 | | - $this->delegate=$delegate; |
| 1704 | + function __construct($delegate) { |
| 1705 | + $this->delegate = $delegate; |
1738 | 1706 | } |
1739 | 1707 | |
1740 | | - function startElement($qname, /*array*/ $arguments){ |
1741 | | - $this->delegate->addHtml('<'.$qname) ; |
1742 | | - foreach($arguments as $key => $value){ |
1743 | | - $this->delegate->addHtml(' '.$key.'="'. Sanitizer::encodeAttribute($value) .'"'); |
1744 | | - } |
1745 | | - $this->delegate->addHtml('>'); |
| 1708 | + function startElement($qname, /*array*/ $arguments) { |
| 1709 | + $this->delegate->addHtml(Xml::openElement($qname, $arguments)); |
1746 | 1710 | } |
1747 | 1711 | |
1748 | 1712 | function endElement($qname){ |
1749 | | - $this->delegate->addHtml('</'.$qname.'>'); |
| 1713 | + $this->delegate->addHtml(Xml::closeElement($qname)); |
1750 | 1714 | } |
1751 | 1715 | |
1752 | 1716 | function characters($chars){ |
1753 | | - $this->delegate->addHtml( $chars ); |
| 1717 | + $this->delegate->addHtml($chars); |
1754 | 1718 | } |
1755 | | - |
1756 | 1719 | } |
Index: trunk/phase3/includes/Diff.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | * @author Guy Van den Broeck |
32 | 32 | * |
33 | 33 | */ |
34 | | -class WikiDiff3{ |
| 34 | +class WikiDiff3 { |
35 | 35 | |
36 | 36 | //Input variables |
37 | 37 | private $from; |
— | — | @@ -59,45 +59,45 @@ |
60 | 60 | public function diff(/*array*/ $from, /*array*/ $to){ |
61 | 61 | //remember initial lengths |
62 | 62 | $m = sizeof($from); |
63 | | - $n = sizeof($to); |
| 63 | + $n = count($to); |
64 | 64 | |
65 | | - $this->heuristicUsed = FALSE; |
| 65 | + $this->heuristicUsed = false; |
66 | 66 | |
67 | 67 | //output |
68 | | - $removed = $m>0?array_fill(0,$m,true):array(); |
69 | | - $added = $n>0?array_fill(0,$n,true):array(); |
| 68 | + $removed = $m > 0 ? array_fill(0, $m, true) : array(); |
| 69 | + $added = $n > 0 ? array_fill(0, $n, true) : array(); |
70 | 70 | |
71 | 71 | //reduce the complexity for the next step (intentionally done twice) |
72 | 72 | //remove common tokens at the start |
73 | | - $i=0; |
74 | | - while($i<$m && $i<$n && $from[$i]===$to[$i]){ |
| 73 | + $i = 0; |
| 74 | + while($i < $m && $i < $n && $from[$i] === $to[$i]) { |
75 | 75 | $removed[$i] = $added[$i] = false; |
76 | | - unset($from[$i],$to[$i]); |
| 76 | + unset($from[$i], $to[$i]); |
77 | 77 | ++$i; |
78 | 78 | } |
79 | 79 | |
80 | 80 | //remove common tokens at the end |
81 | | - $j=1; |
82 | | - while($i+$j<=$m && $i+$j<=$n && $from[$m-$j]===$to[$n-$j]){ |
83 | | - $removed[$m-$j] = $added[$n-$j] = false; |
84 | | - unset($from[$m-$j],$to[$n-$j]); |
| 81 | + $j = 1; |
| 82 | + while($i + $j <= $m && $i + $j <= $n && $from[$m - $j] === $to[$n - $j]) { |
| 83 | + $removed[$m - $j] = $added[$n - $j] = false; |
| 84 | + unset($from[$m - $j], $to[$n - $j]); |
85 | 85 | ++$j; |
86 | 86 | } |
87 | 87 | |
88 | 88 | $this->from = $newFromIndex = $this->to = $newToIndex = array(); |
89 | 89 | |
90 | 90 | //remove tokens not in both sequences |
91 | | - $shared = array_fill_keys($from,false); |
92 | | - foreach($to as $index => $el){ |
93 | | - if(array_key_exists($el,$shared)){ |
| 91 | + $shared = array_fill_keys($from, false); |
| 92 | + foreach($to as $index => $el) { |
| 93 | + if(array_key_exists($el, $shared)) { |
94 | 94 | //keep it |
95 | 95 | $this->to[] = $el; |
96 | 96 | $shared[$el] = true; |
97 | 97 | $newToIndex[] = $index; |
98 | 98 | } |
99 | 99 | } |
100 | | - foreach($from as $index => $el){ |
101 | | - if($shared[$el]){ |
| 100 | + foreach($from as $index => $el) { |
| 101 | + if($shared[$el]) { |
102 | 102 | //keep it |
103 | 103 | $this->from[] = $el; |
104 | 104 | $newFromIndex[] = $index; |
— | — | @@ -106,15 +106,15 @@ |
107 | 107 | |
108 | 108 | unset($shared, $from, $to); |
109 | 109 | |
110 | | - $this->m = sizeof($this->from); |
111 | | - $this->n = sizeof($this->to); |
| 110 | + $this->m = count($this->from); |
| 111 | + $this->n = count($this->to); |
112 | 112 | |
113 | | - $this->removed = $this->m>0?array_fill(0,$this->m,true):array(); |
114 | | - $this->added = $this->n>0?array_fill(0,$this->n,true):array(); |
| 113 | + $this->removed = $this->m > 0 ? array_fill(0, $this->m, true) : array(); |
| 114 | + $this->added = $this->n > 0 ? array_fill(0, $this->n, true) : array(); |
115 | 115 | |
116 | 116 | if ($this->m == 0 || $this->n == 0) { |
117 | 117 | $this->length = 0; |
118 | | - }else{ |
| 118 | + } else { |
119 | 119 | $this->maxDifferences = ceil(($this->m + $this->n) / 2.0); |
120 | 120 | if ($this->m * $this->n > $this->tooLong) { |
121 | 121 | // limit complexity to D^POW_LIMIT for long sequences |
— | — | @@ -128,7 +128,8 @@ |
129 | 129 | */ |
130 | 130 | $max = min($this->m, $this->n); |
131 | 131 | for ($forwardBound = 0; $forwardBound < $max |
132 | | - && $this->from[$forwardBound]===$this->to[$forwardBound]; ++$forwardBound) { |
| 132 | + && $this->from[$forwardBound] === $this->to[$forwardBound]; |
| 133 | + ++$forwardBound) { |
133 | 134 | $this->removed[$forwardBound] = $this->added[$forwardBound] = false; |
134 | 135 | } |
135 | 136 | |
— | — | @@ -136,31 +137,31 @@ |
137 | 138 | $backBoundL2 = $this->n - 1; |
138 | 139 | |
139 | 140 | while ($backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound |
140 | | - && $this->from[$backBoundL1] === $this->to[$backBoundL2]) { |
| 141 | + && $this->from[$backBoundL1] === $this->to[$backBoundL2]) { |
141 | 142 | $this->removed[$backBoundL1--] = $this->added[$backBoundL2--] = false; |
142 | 143 | } |
143 | 144 | |
144 | | - $temp = array_fill(0,$this->m + $this->n + 1, 0); |
145 | | - $V = array($temp,$temp); |
146 | | - $snake = array(0,0,0); |
| 145 | + $temp = array_fill(0, $this->m + $this->n + 1, 0); |
| 146 | + $V = array($temp, $temp); |
| 147 | + $snake = array(0, 0, 0); |
147 | 148 | |
148 | 149 | $this->length = $forwardBound + $this->m - $backBoundL1 - 1 |
149 | | - + $this->lcs_rec($forwardBound, $backBoundL1, $forwardBound, $backBoundL2, |
150 | | - $V, $snake); |
| 150 | + + $this->lcs_rec($forwardBound, $backBoundL1, |
| 151 | + $forwardBound, $backBoundL2, $V, $snake); |
151 | 152 | } |
152 | 153 | |
153 | 154 | $this->m = $m; |
154 | 155 | $this->n = $n; |
155 | 156 | |
156 | | - $this->length += $i+$j-1; |
| 157 | + $this->length += $i + $j - 1; |
157 | 158 | |
158 | | - foreach($this->removed as $key => $removed_elem){ |
159 | | - if(!$removed_elem){ |
| 159 | + foreach($this->removed as $key => $removed_elem) { |
| 160 | + if(!$removed_elem) { |
160 | 161 | $removed[$newFromIndex[$key]] = false; |
161 | 162 | } |
162 | 163 | } |
163 | | - foreach($this->added as $key => $added_elem){ |
164 | | - if(!$added_elem){ |
| 164 | + foreach($this->added as $key => $added_elem) { |
| 165 | + if(!$added_elem) { |
165 | 166 | $added[$newToIndex[$key]] = false; |
166 | 167 | } |
167 | 168 | } |
— | — | @@ -168,7 +169,7 @@ |
169 | 170 | $this->added = $added; |
170 | 171 | } |
171 | 172 | |
172 | | - function diff_range ($from_lines, $to_lines){ |
| 173 | + function diff_range($from_lines, $to_lines) { |
173 | 174 | // Diff and store locally |
174 | 175 | $this->diff($from_lines, $to_lines); |
175 | 176 | unset($from_lines, $to_lines); |
— | — | @@ -177,24 +178,26 @@ |
178 | 179 | $xi = $yi = 0; |
179 | 180 | while ($xi < $this->m || $yi < $this->n) { |
180 | 181 | // Matching "snake". |
181 | | - while ( $xi < $this->m && $yi < $this->n |
182 | | - && !$this->removed[$xi] && !$this->added[$yi]) { |
| 182 | + while ($xi < $this->m && $yi < $this->n |
| 183 | + && !$this->removed[$xi] |
| 184 | + && !$this->added[$yi]) { |
183 | 185 | ++$xi; |
184 | 186 | ++$yi; |
185 | 187 | } |
186 | 188 | // Find deletes & adds. |
187 | 189 | $xstart = $xi; |
188 | | - while ($xi < $this->m && $this->removed[$xi]){ |
| 190 | + while ($xi < $this->m && $this->removed[$xi]) { |
189 | 191 | ++$xi; |
190 | 192 | } |
191 | 193 | |
192 | 194 | $ystart = $yi; |
193 | | - while ($yi < $this->n && $this->added[$yi]){ |
| 195 | + while ($yi < $this->n && $this->added[$yi]) { |
194 | 196 | ++$yi; |
195 | 197 | } |
196 | 198 | |
197 | | - if ($xi>$xstart || $yi>$ystart){ |
198 | | - $ranges[] = new RangeDifference($xstart,$xi,$ystart,$yi); |
| 199 | + if ($xi > $xstart || $yi > $ystart) { |
| 200 | + $ranges[] = new RangeDifference($xstart, $xi, |
| 201 | + $ystart, $yi); |
199 | 202 | } |
200 | 203 | } |
201 | 204 | return $ranges; |
— | — | @@ -206,10 +209,11 @@ |
207 | 210 | return 0; |
208 | 211 | } |
209 | 212 | |
210 | | - $d = $this->find_middle_snake($bottoml1, $topl1, $bottoml2, $topl2, $V, $snake); |
| 213 | + $d = $this->find_middle_snake($bottoml1, $topl1, $bottoml2, |
| 214 | + $topl2, $V, $snake); |
211 | 215 | |
212 | | - // need to store these so we don't lose them when they're overwritten by |
213 | | - // the recursion |
| 216 | + // need to store these so we don't lose them when they're |
| 217 | + // overwritten by the recursion |
214 | 218 | $len = $snake[2]; |
215 | 219 | $startx = $snake[0]; |
216 | 220 | $starty = $snake[1]; |
— | — | @@ -221,8 +225,10 @@ |
222 | 226 | |
223 | 227 | if ($d > 1) { |
224 | 228 | return $len |
225 | | - + $this->lcs_rec($bottoml1, $startx - 1, $bottoml2, $starty - 1, $V, $snake) |
226 | | - + $this->lcs_rec($startx + $len, $topl1, $starty + $len, $topl2, $V, $snake); |
| 229 | + + $this->lcs_rec($bottoml1, $startx - 1, $bottoml2, |
| 230 | + $starty - 1, $V, $snake) |
| 231 | + + $this->lcs_rec($startx + $len, $topl1, $starty + $len, |
| 232 | + $topl2, $V, $snake); |
227 | 233 | } else if ($d == 1) { |
228 | 234 | /* |
229 | 235 | * In this case the sequences differ by exactly 1 line. We have |
— | — | @@ -231,7 +237,8 @@ |
232 | 238 | */ |
233 | 239 | $max = min($startx - $bottoml1, $starty - $bottoml2); |
234 | 240 | for ($i = 0; $i < $max; ++$i) { |
235 | | - $this->removed[$bottoml1 + $i] = $this->added[$bottoml2 + $i] = false; |
| 241 | + $this->removed[$bottoml1 + $i] = |
| 242 | + $this->added[$bottoml2 + $i] = false; |
236 | 243 | } |
237 | 244 | return $max + $len; |
238 | 245 | } |
— | — | @@ -253,11 +260,10 @@ |
254 | 261 | $delta = $N - $M; |
255 | 262 | $maxabsx = $N+$bottoml1; |
256 | 263 | $maxabsy = $M+$bottoml2; |
257 | | - $limit = min($this->maxDifferences, ceil(($N + $M ) / 2)); // ceil((N+M)/2) |
| 264 | + $limit = min($this->maxDifferences, ceil(($N + $M ) / 2)); |
258 | 265 | |
259 | 266 | //value_to_add_forward: a 0 or 1 that we add to the start |
260 | | - // offset |
261 | | - // to make it odd/even |
| 267 | + // offset to make it odd/even |
262 | 268 | if (($M & 1) == 1) { |
263 | 269 | $value_to_add_forward = 1; |
264 | 270 | } else { |
— | — | @@ -275,12 +281,12 @@ |
276 | 282 | $start_backward = -$N; |
277 | 283 | $end_backward = $M; |
278 | 284 | |
279 | | - $limit_min_1 = $limit-1; |
280 | | - $limit_plus_1 = $limit+1; |
| 285 | + $limit_min_1 = $limit - 1; |
| 286 | + $limit_plus_1 = $limit + 1; |
281 | 287 | |
282 | 288 | $V0[$limit_plus_1] = 0; |
283 | 289 | $V1[$limit_min_1] = $N; |
284 | | - $limit = min($this->maxDifferences, ceil(($N + $M ) / 2)); // ceil((N+M)/2) |
| 290 | + $limit = min($this->maxDifferences, ceil(($N + $M ) / 2)); |
285 | 291 | |
286 | 292 | if (($delta & 1) == 1) { |
287 | 293 | for ($d = 0; $d <= $limit; ++$d) { |
— | — | @@ -290,8 +296,8 @@ |
291 | 297 | |
292 | 298 | // compute forward furthest reaching paths |
293 | 299 | for ($k = $start_diag; $k <= $end_diag; $k += 2) { |
294 | | - if ($k == -$d |
295 | | - || ($k < $d && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k])) { |
| 300 | + if ($k == -$d || ($k < $d |
| 301 | + && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k])) { |
296 | 302 | $x = $V0[$limit_plus_1 + $k]; |
297 | 303 | } else { |
298 | 304 | $x = $V0[$limit_min_1 + $k] + 1; |
— | — | @@ -309,14 +315,14 @@ |
310 | 316 | $snake2 = $absx -$snake0; |
311 | 317 | $V0[$limit + $k] = $x; |
312 | 318 | if ($k >= $delta - $d + 1 && $k <= $delta + $d - 1 |
313 | | - && $x >= $V1[$limit + $k - $delta]) { |
| 319 | + && $x >= $V1[$limit + $k - $delta]) { |
314 | 320 | return 2 * $d - 1; |
315 | 321 | } |
316 | 322 | |
317 | 323 | // check to see if we can cut down the diagonal range |
318 | 324 | if ($x >= $N && $end_forward > $k - 1) { |
319 | 325 | $end_forward = $k - 1; |
320 | | - } else if ($absy-$bottoml2 >= $M) { |
| 326 | + } else if ($absy - $bottoml2 >= $M) { |
321 | 327 | $start_forward = $k + 1; |
322 | 328 | $value_to_add_forward = 0; |
323 | 329 | } |
— | — | @@ -407,7 +413,7 @@ |
408 | 414 | |
409 | 415 | $snake2 = 0; |
410 | 416 | while ($x > 0 && $y > 0 |
411 | | - && $from[$x +$bottoml1_min_1] === $to[$y + $bottoml2_min_1]) { |
| 417 | + && $from[$x +$bottoml1_min_1] === $to[$y + $bottoml2_min_1]) { |
412 | 418 | --$x; |
413 | 419 | --$y; |
414 | 420 | ++$snake2; |
— | — | @@ -415,7 +421,7 @@ |
416 | 422 | $V1[$limit + $k] = $x; |
417 | 423 | |
418 | 424 | if ($k >= -$delta - $d && $k <= $d - $delta |
419 | | - && $x <= $V0[$limit + $k + $delta]) { |
| 425 | + && $x <= $V0[$limit + $k + $delta]) { |
420 | 426 | $snake0 = $bottoml1 + $x; |
421 | 427 | $snake1 = $bottoml2 + $y; |
422 | 428 | return 2 * $d; |
— | — | @@ -472,11 +478,11 @@ |
473 | 479 | |
474 | 480 | $backward_end_diag = -min($M, $limit); |
475 | 481 | |
476 | | - $temp = array(0,0,0); |
| 482 | + $temp = array(0, 0, 0); |
477 | 483 | |
478 | 484 | |
479 | | - $max_progress = array_fill(0,ceil(max($forward_end_diag |
480 | | - - $forward_start_diag, $backward_end_diag - $backward_start_diag) / 2), $temp); |
| 485 | + $max_progress = array_fill(0, ceil(max($forward_end_diag - $forward_start_diag, |
| 486 | + $backward_end_diag - $backward_start_diag) / 2), $temp); |
481 | 487 | $num_progress = 0; // the 1st entry is current, it is initialized |
482 | 488 | // with 0s |
483 | 489 | |
— | — | @@ -560,9 +566,9 @@ |
561 | 567 | function __construct($leftstart, $leftend, $rightstart, $rightend){ |
562 | 568 | $this->leftstart = $leftstart; |
563 | 569 | $this->leftend = $leftend; |
564 | | - $this->leftlength = $leftend-$leftstart; |
| 570 | + $this->leftlength = $leftend - $leftstart; |
565 | 571 | $this->rightstart = $rightstart; |
566 | 572 | $this->rightend = $rightend; |
567 | | - $this->rightlength = $rightend-$rightstart; |
| 573 | + $this->rightlength = $rightend - $rightstart; |
568 | 574 | } |
569 | 575 | } |
Index: trunk/phase3/includes/DifferenceEngine.php |
— | — | @@ -266,13 +266,13 @@ |
267 | 267 | '<div id="mw-diff-ntitle3">' . $newminor . $sk->revComment( $this->mNewRev, !$diffOnly, true ) . $rdel . "</div>" . |
268 | 268 | '<div id="mw-diff-ntitle4">' . $nextlink . $patrol . '</div>'; |
269 | 269 | |
270 | | - if($wgEnableHtmlDiff){ |
| 270 | + if( $wgEnableHtmlDiff ) { |
271 | 271 | $this->renderHtmlDiff(); |
272 | | - }else{ |
| 272 | + } else { |
273 | 273 | |
274 | 274 | $this->showDiff( $oldHeader, $newHeader ); |
275 | 275 | |
276 | | - if ( !$diffOnly ){ |
| 276 | + if( !$diffOnly ) { |
277 | 277 | $this->renderNewRevision(); |
278 | 278 | } |
279 | 279 | } |
— | — | @@ -327,7 +327,7 @@ |
328 | 328 | |
329 | 329 | |
330 | 330 | function renderHtmlDiff() { |
331 | | - global $wgOut; |
| 331 | + global $wgOut, $wgTitle, $wgParser; |
332 | 332 | wfProfileIn( __METHOD__ ); |
333 | 333 | |
334 | 334 | $this->showDiffStyle(); |
— | — | @@ -345,38 +345,38 @@ |
346 | 346 | |
347 | 347 | $this->loadText(); |
348 | 348 | |
| 349 | + // Old revision |
349 | 350 | if( is_object( $this->mOldRev ) ) { |
350 | 351 | $wgOut->setRevisionId( $this->mOldRev->getId() ); |
351 | 352 | } |
352 | 353 | |
353 | | - global $wgTitle, $wgParser, $wgTitle; |
354 | 354 | $popts = $wgOut->parserOptions(); |
355 | | - $oldTidy = $popts->setTidy( TRUE ); |
| 355 | + $oldTidy = $popts->setTidy( true ); |
356 | 356 | |
357 | | - $parserOutput = $wgParser->parse($this->mOldtext, $wgTitle, $popts, TRUE, TRUE, $wgOut->mRevisionId ); |
| 357 | + $parserOutput = $wgParser->parse( $this->mOldtext, $wgTitle, $popts, true, true, $wgOut->getRevisionId() ); |
358 | 358 | $popts->setTidy( $oldTidy ); |
359 | 359 | |
360 | 360 | //only for new? |
361 | 361 | //$wgOut->addParserOutputNoText( $parserOutput ); |
362 | | - $oldHtml = $parserOutput->getText(); |
363 | | - wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$oldHtml ) ); |
| 362 | + $oldHtml = $parserOutput->getText(); |
| 363 | + wfRunHooks( 'OutputPageBeforeHTML', array( &$wgOut, &$oldHtml ) ); |
364 | 364 | |
| 365 | + // New revision |
365 | 366 | if( is_object( $this->mNewRev ) ) { |
366 | 367 | $wgOut->setRevisionId( $this->mNewRev->getId() ); |
367 | 368 | } |
368 | 369 | |
369 | 370 | $popts = $wgOut->parserOptions(); |
370 | | - $oldTidy = $popts->setTidy( TRUE ); |
| 371 | + $oldTidy = $popts->setTidy( true ); |
371 | 372 | |
372 | | - $parserOutput = $wgParser->parse($this->mNewtext, $wgTitle, $popts, TRUE, TRUE, $wgOut->mRevisionId ); |
| 373 | + $parserOutput = $wgParser->parse( $this->mNewtext, $wgTitle, $popts, true, true, $wgOut->getRevisionId() ); |
373 | 374 | $popts->setTidy( $oldTidy ); |
374 | 375 | |
375 | | - //only for new? |
376 | 376 | $wgOut->addParserOutputNoText( $parserOutput ); |
377 | | - $newHtml = $parserOutput->getText(); |
378 | | - wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$newHtml ) ); |
| 377 | + $newHtml = $parserOutput->getText(); |
| 378 | + wfRunHooks( 'OutputPageBeforeHTML', array( &$wgOut, &$newHtml ) ); |
379 | 379 | |
380 | | - unset($parserOutput,$popts); |
| 380 | + unset($parserOutput, $popts); |
381 | 381 | |
382 | 382 | $differ = new HTMLDiffer(new DelegatingContentHandler($wgOut)); |
383 | 383 | $differ->htmlDiff($oldHtml, $newHtml); |