r39585 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39584‎ | r39585 | r39586 >
Date:13:48, 18 August 2008
Author:catrope
Status:old
Tags:
Comment:
Cleaned up HTMLDiff implementation for readability:
* Coding style consistency and indentation
* Removed unneccesary require_once(), the AutoLoader will load the right file automatically
* sizeof -> count, TRUE -> true, FALSE -> false, NULL -> null
* Use Xml:: functions
* Rename TagNode::splitUntill() to splitUntil() and $hasNotDeletedDescendant to $hasNonDeletedDescendant
* Flip TagNode::$blocks, TagToStringFactory::$containerTags and TagToStringFactory::$styleTags
* Merging if's in Node::getParentTree()
* Use a smart foreach() loop rather than two while()s and an if() in TagNode::splitUntil()
* Put all of TextNodeDiffer's members on top rather than scattering them between functions
* Use PHP's double-quoted string coolness rather than sprintf() or concatenation
* Use a smart foreach loop rather than array_keys() and a for() in TagToString::addAttributes()

TODO:
* Use interface messages rather than TagToString::$bundle so they can be translated
* Use constants for magic numbers like 1.35, 1000 and 2000 in calls to WikiDiff3::__construct()
Modified paths:
  • /trunk/phase3/includes/Diff.php (modified) (history)
  • /trunk/phase3/includes/DifferenceEngine.php (modified) (history)
  • /trunk/phase3/includes/HTMLDiff.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLDiff.php
@@ -18,15 +18,9 @@
1919 */
2020
2121 /**
22 - * The HTML differ depends on WikiDiff3
23 - */
24 -global $IP;
25 -require_once( "$IP/includes/Diff.php" );
26 -
27 -/**
2822 * Any element in the DOM tree of an HTML document.
2923 */
30 -class Node{
 24+class Node {
3125
3226 public $parent;
3327
@@ -36,23 +30,23 @@
3731
3832 public $whiteAfter = false;
3933
40 - function __construct($parent){
 34+ function __construct($parent) {
4135 $this->parent = $parent;
4236 }
4337
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)) {
4741 $this->parentTree = $this->parent->getParentTree();
4842 $this->parentTree[] = $this->parent;
49 - }else{
 43+ } else {
5044 $this->parentTree = array();
5145 }
5246 }
5347 return $this->parentTree;
5448 }
5549
56 - public function getLastCommonParent(Node $other){
 50+ public function getLastCommonParent(Node $other) {
5751 $result = new LastCommonParentResult();
5852
5953 $myParents = $this->getParentTree();
@@ -60,13 +54,13 @@
6155
6256 $i = 1;
6357 $isSame = true;
64 - $nbMyParents = sizeof($myParents);
65 - $nbOtherParents = sizeof($otherParents);
 58+ $nbMyParents = count($myParents);
 59+ $nbOtherParents = count($otherParents);
6660 while ($isSame && $i < $nbMyParents && $i < $nbOtherParents) {
6761 if (!$myParents[$i]->openingTag === $otherParents[$i]->openingTag) {
6862 $isSame = false;
6963 } 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
7165 $i++;
7266 }
7367 }
@@ -74,20 +68,13 @@
7569 $result->lastCommonParentDepth = $i - 1;
7670 $result->parent = $myParents[$i - 1];
7771
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
7975 $result->indexInLastCommonParent = $myParents[$i - 1]->getIndexOf($myParents[$i]);
8076 $result->splittingNeeded = true;
81 - } else if ($nbMyParents < $nbOtherParents) {
 77+ } else if ($nbMyParents <= $nbOtherParents) {
8278 $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 - }
9279 return $result;
9380 }
9481
@@ -110,7 +97,7 @@
11198 /**
11299 * Node that can contain other nodes. Represents an HTML tag.
113100 */
114 -class TagNode extends Node{
 101+class TagNode extends Node {
115102
116103 public $children = array();
117104
@@ -126,25 +113,21 @@
127114 foreach($attributes as $key => $value){
128115 $this->attributes[strtolower($key)] = $value;
129116 }
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);
135118 }
136119
137120 public function addChildAbsolute(Node $node, $index) {
138 - array_splice($this->children,$index,0,array($node));
 121+ array_splice($this->children, $index, 0, array($node));
139122 }
140123
141124 public function getIndexOf(Node $child) {
142125 // 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) {
145128 return $key;
146129 }
147130 }
148 - return NULL;
 131+ return null;
149132 }
150133
151134 public function getNbChildren() {
@@ -153,78 +136,79 @@
154137
155138 public function getMinimalDeletedSet($id, &$allDeleted, &$somethingDeleted) {
156139 $nodes = array();
157 - if (empty($this->children)){
158 - $allDeleted = false;
159 - $somethingDeleted = false;
160 - return $nodes;
161 - }
162140
163141 $allDeleted = false;
164142 $somethingDeleted = false;
165 - $hasNotDeletedDescendant = false;
 143+ $hasNonDeletedDescendant = false;
166144
 145+ if (empty($this->children)) {
 146+ return $nodes;
 147+ }
 148+
167149 foreach ($this->children as $child) {
 150+ $allDeleted_local = false;
 151+ $somethingDeleted_local = false;
168152 $childrenChildren = $child->getMinimalDeletedSet($id, $allDeleted_local, $somethingDeleted_local);
169 - if($somethingDeleted_local){
 153+ if ($somethingDeleted_local) {
170154 $nodes = array_merge($nodes, $childrenChildren);
171155 $somethingDeleted = true;
172156 }
173 - $hasNotDeletedDescendant |= !$allDeleted_local;
 157+ if (!$allDeleted_local) {
 158+ $hasNonDeletedDescendant = true;
 159+ }
174160 }
175 - if (!$hasNotDeletedDescendant) {
 161+ if (!$hasNonDeletedDescendant) {
176162 $nodes = array($this);
177163 $allDeleted = true;
178164 }
179165 return $nodes;
180166 }
181167
182 - public function splitUntill(TagNode $parent, Node $split, $includeLeft) {
 168+ public function splitUntil(TagNode $parent, Node $split, $includeLeft) {
183169 $splitOccured = false;
184170 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);
187173 $part1->setParent($this->parent);
188174 $part2->setParent($this->parent);
189175
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;
201186 } else {
202 - $this->children[$i]->setParent($part2);
203 - $part2->children[] = $this->children[$i];
 187+ $child->setParent($part2);
 188+ $part2->children[] = $child;
204189 }
205 - ++$i;
 190+ if ($onSplit) {
 191+ $onSplit = false;
 192+ $pastSplit = true;
 193+ }
206194 }
207 - while ($i < $nbChildren) {
208 - $this->children[$i]->setParent($part2);
209 - $part2->children[] = $this->children[$i];
210 - ++$i;
211 - }
212195 $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+ }
219202 if (!empty($part1->children) && !empty($part2->children)) {
220203 $splitOccured = true;
221204 }
222205
223206 $this->parent->removeChild($myindexinparent);
224207
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+ }
229213 }
230214 return $splitOccured;
231215
@@ -235,15 +219,15 @@
236220 $this->children = array_values($this->children);
237221 }
238222
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');
242226
243227 public function copyTree() {
244 - $newThis = new TagNode(NULL, $this->qName, $this->attributes);
 228+ $newThis = new TagNode(null, $this->qName, $this->attributes);
245229 $newThis->whiteBefore = $this->whiteBefore;
246230 $newThis->whiteAfter = $this->whiteAfter;
247 - foreach($this->children as $child) {
 231+ foreach ($this->children as $child) {
248232 $newChild = $child->copyTree();
249233 $newChild->setParent($newThis);
250234 $newThis->children[] = $newChild;
@@ -264,18 +248,18 @@
265249 for ($i = 0; $i < $nbOriginalChildren; ++$i) {
266250 $child = $this->children[$i + $shift];
267251
268 - if($child instanceof TagNode){
 252+ if ($child instanceof TagNode) {
269253 if (!$child->isPre()) {
270254 $child->expandWhiteSpace();
271255 }
272256 }
273257 if (!$spaceAdded && $child->whiteBefore) {
274 - $ws = new WhiteSpaceNode(NULL, ' ', $child->getLeftMostChild());
 258+ $ws = new WhiteSpaceNode(null, ' ', $child->getLeftMostChild());
275259 $ws->setParent($this);
276260 $this->addChildAbsolute($ws,$i + ($shift++));
277261 }
278262 if ($child->whiteAfter) {
279 - $ws = new WhiteSpaceNode(NULL, ' ', $child->getRightMostChild());
 263+ $ws = new WhiteSpaceNode(null, ' ', $child->getRightMostChild());
280264 $ws->setParent($this);
281265 $this->addChildAbsolute($ws,$i + 1 + ($shift++));
282266 $spaceAdded = true;
@@ -287,15 +271,16 @@
288272 }
289273
290274 public function getLeftMostChild() {
291 - if (empty($this->children))
292 - return $this;
 275+ if (empty($this->children)) {
 276+ return $this;
 277+ }
293278 return $this->children[0]->getLeftMostChild();
294 -
295279 }
296280
297281 public function getRightMostChild() {
298 - if (empty($this->children))
299 - return $this;
 282+ if (empty($this->children)) {
 283+ return $this;
 284+ }
300285 return $this->children[$this->getNbChildren() - 1]->getRightMostChild();
301286 }
302287
@@ -303,7 +288,7 @@
304289 return 0 == strcasecmp($this->qName,'pre');
305290 }
306291
307 - public static function toDiffLine(TagNode $node){
 292+ public static function toDiffLine(TagNode $node) {
308293 return $node->openingTag;
309294 }
310295 }
@@ -311,7 +296,7 @@
312297 /**
313298 * Represents a piece of text in the HTML file.
314299 */
315 -class TextNode extends Node{
 300+class TextNode extends Node {
316301
317302 public $text;
318303
@@ -325,7 +310,7 @@
326311
327312 public function copyTree() {
328313 $clone = clone $this;
329 - $clone->setParent(NULL);
 314+ $clone->setParent(null);
330315 return $clone;
331316 }
332317
@@ -339,7 +324,7 @@
340325
341326 public function getMinimalDeletedSet($id, &$allDeleted, &$somethingDeleted) {
342327 if ($this->modification->type == Modification::REMOVED
343 - && $this->modification->id == $id){
 328+ && $this->modification->id == $id){
344329 $somethingDeleted = true;
345330 $allDeleted = true;
346331 return array($this);
@@ -348,22 +333,22 @@
349334 }
350335
351336 public function isSameText($other) {
352 - if (is_null($other) || ! $other instanceof TextNode){
 337+ if (is_null($other) || ! $other instanceof TextNode) {
353338 return false;
354339 }
355340 return str_replace('\n', ' ',$this->text) === str_replace('\n', ' ',$other->text);
356341 }
357342
358 - public static function toDiffLine(TextNode $node){
 343+ public static function toDiffLine(TextNode $node) {
359344 return str_replace('\n', ' ',$node->text);
360345 }
361346 }
362347
363348 class WhiteSpaceNode extends TextNode {
364349
365 - function __construct($parent, $s, Node $like = NULL) {
 350+ function __construct($parent, $s, Node $like = null) {
366351 parent::__construct($parent, $s);
367 - if(!is_null($like) && $like instanceof TextNode){
 352+ if(!is_null($like) && $like instanceof TextNode) {
368353 $newModification = clone $like->modification;
369354 $newModification->firstOfID = false;
370355 $this->modification = $newModification;
@@ -377,7 +362,7 @@
378363 class BodyNode extends TagNode {
379364
380365 function __construct() {
381 - parent::__construct(NULL, 'body', array());
 366+ parent::__construct(null, 'body', array());
382367 }
383368
384369 public function copyTree() {
@@ -393,7 +378,8 @@
394379 public function getMinimalDeletedSet($id, &$allDeleted, &$somethingDeleted) {
395380 $nodes = array();
396381 foreach ($this->children as $child) {
397 - $childrenChildren = $child->getMinimalDeletedSet($id,$allDeleted,$somethingDeleted);
 382+ $childrenChildren = $child->getMinimalDeletedSet($id,
 383+ $allDeleted, $somethingDeleted);
398384 $nodes = array_merge($nodes, $childrenChildren);
399385 }
400386 return $nodes;
@@ -410,11 +396,11 @@
411397 private $attributes;
412398
413399 function __construct(TagNode $parent, /*array*/ $attrs) {
414 - if(!array_key_exists('src',$attrs)){
 400+ if(!array_key_exists('src', $attrs)) {
415401 //wfDebug('Image without a source:');
416 - foreach($attrs as $key => $value){
 402+ //foreach ($attrs as $key => $value) {
417403 //wfDebug("$key = $value");
418 - }
 404+ //}
419405 parent::__construct($parent, '<img></img>');
420406 }else{
421407 parent::__construct($parent, '<img>' . strtolower($attrs['src']) . '</img>');
@@ -423,16 +409,17 @@
424410 }
425411
426412 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+ }
429416 return $this->text === $other->text;
430417 }
431418
432419 }
433420
434 -class DummyNode extends Node{
 421+class DummyNode extends Node {
435422
436 - function __construct(){
 423+ function __construct() {
437424 // no op
438425 }
439426
@@ -480,8 +467,8 @@
481468 $this->type = $type;
482469 }
483470
484 - public static function typeToString($type){
485 - switch($type){
 471+ public static function typeToString($type) {
 472+ switch($type) {
486473 case self::NONE: return 'none';
487474 case self::REMOVED: return 'removed';
488475 case self::ADDED: return 'added';
@@ -510,7 +497,7 @@
511498
512499 private $notInPre = true;
513500
514 - function __construct(){
 501+ function __construct() {
515502 $this->bodyNode = $this->currentParent = new BodyNode();
516503 $this->lastSibling = new DummyNode();
517504 }
@@ -520,11 +507,11 @@
521508 */
522509 public function endDocument() {
523510 $this->endWord();
524 - //wfDebug(sizeof($this->textNodes) . ' text nodes in document.');
 511+ //wfDebug(count($this->textNodes) . ' text nodes in document.');
525512 }
526513
527514 public function startElement($parser, $name, /*array*/ $attributes) {
528 - if(!strcasecmp($name, 'body')==0){
 515+ if (strcasecmp($name, 'body') != 0) {
529516 //wfDebug("Starting $name node.");
530517 $this->endWord();
531518
@@ -532,18 +519,18 @@
533520 $this->currentParent->children[] = $newNode;
534521 $this->currentParent = $newNode;
535522 $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)) {
537524 $this->currentParent->whiteBefore = true;
538525 }
539526 $this->whiteSpaceBeforeThis = false;
540 - if(strcasecmp($name, 'pre')==0){
 527+ if(strcasecmp($name, 'pre') == 0) {
541528 $this->notInPre = false;
542529 }
543530 }
544531 }
545532
546533 public function endElement($parser, $name) {
547 - if(!strcasecmp($name, 'body')==0){
 534+ if(strcasecmp($name, 'body') != 0) {
548535 //wfDebug("Ending $name node.");
549536 if (0 == strcasecmp($name,'img')) {
550537 // Insert a dummy leaf for the image
@@ -554,17 +541,17 @@
555542 $this->textNodes[] = $img;
556543 }
557544 $this->endWord();
558 - if (!array_key_exists(strtolower($this->currentParent->qName),TagNode::$blocks)) {
 545+ if (!in_array(strtolower($this->currentParent->qName),TagNode::$blocks)) {
559546 $this->lastSibling = $this->currentParent;
560547 } else {
561548 $this->lastSibling = new DummyNode();
562549 }
563550 $this->currentParent = $this->currentParent->parent;
564551 $this->whiteSpaceBeforeThis = false;
565 - if(!$this->notInPre && strcasecmp($name, 'pre')==0){
 552+ if (!$this->notInPre && strcasecmp($name, 'pre') == 0) {
566553 $this->notInPre = true;
567554 }
568 - }else{
 555+ } else {
569556 $this->endDocument();
570557 }
571558 }
@@ -573,15 +560,15 @@
574561 const whitespace = '/^[\s]{1}$/';
575562 const delimiter = '/^[\s\.\,\"\\\'\(\)\?\:\;\!\{\}\-\+\*\=\_\[\]\&\|\$]{1}$/';
576563
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);
579566
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) {
582569 $this->endWord();
583570 $this->lastSibling->whiteAfter = true;
584571 $this->whiteSpaceBeforeThis = true;
585 - }else if(preg_match(self::delimiter, $word)){
 572+ } else if (preg_match(self::delimiter, $word)) {
586573 $this->endWord();
587574 $textNode = new TextNode($this->currentParent, $word);
588575 $this->currentParent->children[] = $textNode;
@@ -589,7 +576,7 @@
590577 $this->whiteSpaceBeforeThis = false;
591578 $this->lastSibling = $textNode;
592579 $this->textNodes[] = $textNode;
593 - }else{
 580+ } else {
594581 $this->newWord .= $word;
595582 }
596583 }
@@ -607,12 +594,12 @@
608595 }
609596 }
610597
611 - public function getDiffLines(){
 598+ public function getDiffLines() {
612599 return array_map(array('TextNode','toDiffLine'), $this->textNodes);
613600 }
614601 }
615602
616 -class TextNodeDiffer{
 603+class TextNodeDiffer {
617604
618605 private $textNodes;
619606 public $bodyNode;
@@ -621,7 +608,18 @@
622609 private $oldBodyNode;
623610
624611 private $lastModified = array();
 612+
 613+ private $newID = 0;
 614+
 615+ private $changedID = 0;
625616
 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+
626624 function __construct(DomTreeBuilder $tree, DomTreeBuilder $oldTree) {
627625 $this->textNodes = $tree->textNodes;
628626 $this->bodyNode = $tree->bodyNode;
@@ -629,21 +627,21 @@
630628 $this->oldBodyNode = $oldTree->bodyNode;
631629 }
632630
633 - private $newID = 0;
634 -
635631 public function markAsNew($start, $end) {
636 - if ($end <= $start)
637 - return;
 632+ if ($end <= $start) {
 633+ return;
 634+ }
638635
639 - if ($this->whiteAfterLastChangedPart)
640 - $this->textNodes[$start]->whiteBefore = false;
 636+ if ($this->whiteAfterLastChangedPart) {
 637+ $this->textNodes[$start]->whiteBefore = false;
 638+ }
641639
642640 $nextLastModified = array();
643641
644642 for ($i = $start; $i < $end; ++$i) {
645643 $mod = new Modification(Modification::ADDED);
646644 $mod->id = $this->newID;
647 - if (sizeof($this->lastModified) > 0) {
 645+ if (count($this->lastModified) > 0) {
648646 $mod->prevMod = $this->lastModified[0];
649647 if (is_null($this->lastModified[0]->nextMod )) {
650648 foreach ($this->lastModified as $lastMod) {
@@ -661,10 +659,6 @@
662660 $this->lastModified = $nextLastModified;
663661 }
664662
665 - private $changedID = 0;
666 -
667 - private $changedIDUsed = false;
668 -
669663 public function handlePossibleChangedPart($leftstart, $leftend, $rightstart, $rightend) {
670664 $i = $rightstart;
671665 $j = $leftstart;
@@ -683,20 +677,20 @@
684678 $result = $acthis->getResult($acother);
685679 unset($acthis, $acother);
686680
687 - $nbLastModified = sizeof($this->lastModified);
 681+ $nbLastModified = count($this->lastModified);
688682 if ($result->changed) {
689683 $mod = new Modification(Modification::CHANGED);
690684
691685 if (!$this->changedIDUsed) {
692686 $mod->firstOfID = true;
693 - if (sizeof($nextLastModified) > 0) {
 687+ if (count($nextLastModified) > 0) {
694688 $this->lastModified = $nextLastModified;
695689 $nextLastModified = array();
696690 }
697691 } else if (!is_null($result->changes) && $result->changes !== $this->changes) {
698692 ++$this->changedID;
699693 $mod->firstOfID = true;
700 - if (sizeof($nextLastModified) > 0) {
 694+ if (count($nextLastModified) > 0) {
701695 $this->lastModified = $nextLastModified;
702696 $nextLastModified = array();
703697 }
@@ -725,20 +719,16 @@
726720 ++$i;
727721 ++$j;
728722 }
729 - if (sizeof($nextLastModified) > 0){
 723+ if (count($nextLastModified) > 0) {
730724 $this->lastModified = $nextLastModified;
731725 }
732726 }
733727
734 - // used to remove the whitespace between a red and green block
735 - private $whiteAfterLastChangedPart = false;
736 -
737 - private $deletedID = 0;
738 -
739728 public function markAsDeleted($start, $end, $before) {
740729
741 - if ($end <= $start)
742 - return;
 730+ if ($end <= $start) {
 731+ return;
 732+ }
743733
744734 if ($before > 0 && $this->textNodes[$before - 1]->whiteAfter) {
745735 $this->whiteAfterLastChangedPart = true;
@@ -751,7 +741,7 @@
752742 for ($i = $start; $i < $end; ++$i) {
753743 $mod = new Modification(Modification::REMOVED);
754744 $mod->id = $this->deletedID;
755 - if (sizeof($this->lastModified) > 0) {
 745+ if (count($this->lastModified) > 0) {
756746 $mod->prevMod = $this->lastModified[0];
757747 if (is_null($this->lastModified[0]->nextMod )) {
758748 foreach ($this->lastModified as $lastMod) {
@@ -762,30 +752,30 @@
763753 $nextLastModified[] = $mod;
764754
765755 // oldTextNodes is used here because we're going to move its deleted
766 - // elements
767 - // to this tree!
 756+ // elements to this tree!
768757 $this->oldTextNodes[$i]->modification = $mod;
769758 }
770759 $this->oldTextNodes[$start]->modification->firstOfID = true;
771760
772761 $root = $this->oldTextNodes[$start]->getLastCommonParent($this->oldTextNodes[$end-1])->parent;
773762
 763+ $junk1 = $junk2 = null;
774764 $deletedNodes = $root->getMinimalDeletedSet($this->deletedID, $junk1, $junk2);
775765
776 - //wfDebug("Minimal set of deleted nodes of size " . sizeof($deletedNodes));
 766+ //wfDebug("Minimal set of deleted nodes of size " . count($deletedNodes));
777767
778768 // Set prevLeaf to the leaf after which the old HTML needs to be
779769 // inserted
780 - if ($before > 0){
 770+ if ($before > 0) {
781771 $prevLeaf = $this->textNodes[$before - 1];
782772 }
783773 // Set nextLeaf to the leaf before which the old HTML needs to be
784774 // inserted
785 - if ($before < sizeof($this->textNodes)){
 775+ if ($before < count($this->textNodes)) {
786776 $nextLeaf = $this->textNodes[$before];
787777 }
788778
789 - while (sizeof($deletedNodes) > 0) {
 779+ while (count($deletedNodes) > 0) {
790780 if (isset($prevLeaf)) {
791781 $prevResult = $prevLeaf->getLastCommonParent($deletedNodes[0]);
792782 } else {
@@ -794,7 +784,7 @@
795785 $prevResult->indexInLastCommonParent = 0;
796786 }
797787 if (isset($nextleaf)) {
798 - $nextResult = $nextLeaf->getLastCommonParent($deletedNodes[sizeof($deletedNodes) - 1]);
 788+ $nextResult = $nextLeaf->getLastCommonParent($deletedNodes[count($deletedNodes) - 1]);
799789 } else {
800790 $nextResult = new LastCommonParentResult();
801791 $nextResult->parent = $this->bodyNode;
@@ -803,15 +793,15 @@
804794
805795 if ($prevResult->lastCommonParentDepth == $nextResult->lastCommonParentDepth) {
806796 // 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) {
809799 // The difference is not in the parent
810800 $prevResult->lastCommonParentDepth = $prevResult->lastCommonParentDepth + 1;
811801 } else {
812802 // The difference is in the parent, so compare them
813803 // now THIS is tricky
814804 $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);
816806
817807 if ($distancePrev <= $distanceNext) {
818808 $prevResult->lastCommonParentDepth = $prevResult->lastCommonParentDepth + 1;
@@ -825,7 +815,7 @@
826816 if ($prevResult->lastCommonParentDepth > $nextResult->lastCommonParentDepth) {
827817 // Inserting at the front
828818 if ($prevResult->splittingNeeded) {
829 - $prevLeaf->parent->splitUntill($prevResult->parent, $prevLeaf, true);
 819+ $prevLeaf->parent->splitUntil($prevResult->parent, $prevLeaf, true);
830820 }
831821 $prevLeaf = $deletedNodes[0]->copyTree();
832822 unset($deletedNodes[0]);
@@ -835,20 +825,21 @@
836826 } else if ($prevResult->lastCommonParentDepth < $nextResult->lastCommonParentDepth) {
837827 // Inserting at the back
838828 if ($nextResult->splittingNeeded) {
839 - $splitOccured = $nextLeaf->parent->splitUntill($nextResult->parent, $nextLeaf, false);
 829+ $splitOccured = $nextLeaf->parent->splitUntil($nextResult->parent, $nextLeaf, false);
840830 if ($splitOccured) {
841831 // The place where to insert is shifted one place to the
842832 // right
843833 $nextResult->indexInLastCommonParent = $nextResult->indexInLastCommonParent + 1;
844834 }
845835 }
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]);
848838 $deletedNodes = array_values($deletedNodes);
849839 $nextLeaf->setParent($nextResult->parent);
850840 $nextResult->parent->addChildAbsolute($nextLeaf,$nextResult->indexInLastCommonParent);
851 - } else
852 - throw new Exception("Uh?");
 841+ } else {
 842+ throw new Exception("Uh?");
 843+ }
853844 }
854845 $this->lastModified = $nextLastModified;
855846 ++$this->deletedID;
@@ -859,23 +850,23 @@
860851 }
861852
862853 public function lengthNew(){
863 - return sizeof($this->textNodes);
 854+ return count($this->textNodes);
864855 }
865856
866857 public function lengthOld(){
867 - return sizeof($this->oldTextNodes);
 858+ return count($this->oldTextNodes);
868859 }
869860 }
870861
871 -class HTMLDiffer{
 862+class HTMLDiffer {
872863
873864 private $output;
874865
875 - function __construct($output){
 866+ function __construct($output) {
876867 $this->output = $output;
877868 }
878869
879 - function htmlDiff($from, $to){
 870+ function htmlDiff($from, $to) {
880871 wfProfileIn( __METHOD__ );
881872 // Create an XML parser
882873 $xml_parser = xml_parser_create('');
@@ -883,16 +874,18 @@
884875 $domfrom = new DomTreeBuilder();
885876
886877 // 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"));
888879
889880 // 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"));
891882
892883 //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");
897890 }
898891 xml_parser_free($xml_parser);
899892 unset($from);
@@ -902,25 +895,26 @@
903896 $domto = new DomTreeBuilder();
904897
905898 // 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"));
907900
908901 // 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"));
910903
911904 //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");
916911 }
917912 xml_parser_free($xml_parser);
918913 unset($to);
919914
920915 $diffengine = new WikiDiff3();
921916 $differences = $this->preProcess($diffengine->diff_range($domfrom->getDiffLines(), $domto->getDiffLines()));
922 - unset($xml_parser,$diffengine);
 917+ unset($xml_parser, $diffengine);
923918
924 -
925919 $domdiffer = new TextNodeDiffer($domto, $domfrom);
926920
927921 $currentIndexLeft = 0;
@@ -928,7 +922,7 @@
929923 foreach ($differences as $d) {
930924 if ($d->leftstart > $currentIndexLeft) {
931925 $domdiffer->handlePossibleChangedPart($currentIndexLeft, $d->leftstart,
932 - $currentIndexRight, $d->rightstart);
 926+ $currentIndexRight, $d->rightstart);
933927 }
934928 if ($d->leftlength > 0) {
935929 $domdiffer->markAsDeleted($d->leftstart, $d->leftend, $d->rightstart);
@@ -940,7 +934,7 @@
941935 }
942936 $oldLength = $domdiffer->lengthOld();
943937 if ($currentIndexLeft < $oldLength) {
944 - $domdiffer->handlePossibleChangedPart($currentIndexLeft,$oldLength, $currentIndexRight,$domdiffer->lengthNew());
 938+ $domdiffer->handlePossibleChangedPart($currentIndexLeft, $oldLength, $currentIndexRight, $domdiffer->lengthNew());
945939 }
946940 $domdiffer->expandWhiteSpace();
947941 $output = new HTMLOutput('htmldiff', $this->output);
@@ -948,10 +942,10 @@
949943 wfProfileOut( __METHOD__ );
950944 }
951945
952 - private function preProcess(/*array*/ $differences){
 946+ private function preProcess(/*array*/ $differences) {
953947 $newRanges = array();
954948
955 - $nbDifferences = sizeof($differences);
 949+ $nbDifferences = count($differences);
956950 for ($i = 0; $i < $nbDifferences; ++$i) {
957951 $leftStart = $differences[$i]->leftstart;
958952 $leftEnd = $differences[$i]->leftend;
@@ -961,8 +955,11 @@
962956 $leftLength = $leftEnd - $leftStart;
963957 $rightLength = $rightEnd - $rightStart;
964958
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)) {
967964 $leftEnd = $differences[$i + 1]->leftend;
968965 $rightEnd = $differences[$i + 1]->rightend;
969966 $leftLength = $leftEnd - $leftStart;
@@ -979,7 +976,7 @@
980977 */
981978 public static function score($ll, $nll, $rl, $nrl) {
982979 if (($ll == 0 && $nll == 0)
983 - || ($rl == 0 && $nrl == 0)){
 980+ || ($rl == 0 && $nrl == 0)) {
984981 return 0;
985982 }
986983 $numbers = array($ll, $nll, $rl, $nrl);
@@ -993,12 +990,12 @@
994991 $d += $number;
995992
996993 }
997 - return $d / (1.5 * sizeof($numbers));
 994+ return $d / (1.5 * count($numbers));
998995 }
999996
1000997 }
1001998
1002 -class TextOnlyComparator{
 999+class TextOnlyComparator {
10031000
10041001 public $leafs = array();
10051002
@@ -1018,13 +1015,13 @@
10191016 }
10201017
10211018 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);
10241021 if($nbOthers == 0 || $nbThis == 0){
10251022 return -log(0);
10261023 }
10271024
1028 - $diffengine = new WikiDiff3(25000,1.35);
 1025+ $diffengine = new WikiDiff3(25000, 1.35);
10291026 $diffengine->diff($this->leafs, $other->leafs);
10301027
10311028 $lcsLength = $diffengine->getLcsLength();
@@ -1045,7 +1042,7 @@
10461043 /**
10471044 * A comparator used when calculating the difference in ancestry of two Nodes.
10481045 */
1049 -class AncestorComparator{
 1046+class AncestorComparator {
10501047
10511048 public $ancestors;
10521049 public $ancestorsText;
@@ -1060,10 +1057,10 @@
10611058 public function getResult(AncestorComparator $other) {
10621059 $result = new AncestorComparatorResult();
10631060
1064 - $diffengine = new WikiDiff3(10000,1.35);
 1061+ $diffengine = new WikiDiff3(10000, 1.35);
10651062 $differences = $diffengine->diff_range($this->ancestorsText, $other->ancestorsText);
10661063
1067 - if (sizeof($differences) == 0){
 1064+ if (count($differences) == 0){
10681065 return $result;
10691066 }
10701067 $changeTxt = new ChangeTextGenerator($this, $other);
@@ -1093,12 +1090,12 @@
10941091
10951092 $rootlistopened = false;
10961093
1097 - if (sizeof($differences) > 1) {
 1094+ if (count($differences) > 1) {
10981095 $txt->addHtml('<ul class="changelist">');
10991096 $rootlistopened = true;
11001097 }
11011098
1102 - $nbDifferences = sizeof($differences);
 1099+ $nbDifferences = count($differences);
11031100 for ($j = 0; $j < $nbDifferences; ++$j) {
11041101 $d = $differences[$j];
11051102
@@ -1197,74 +1194,34 @@
11981195
11991196 class TagToStringFactory {
12001197
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');
12341205
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 -
12491206 const MOVED = 1;
12501207 const STYLE = 2;
12511208 const UNKNOWN = 4;
12521209
12531210 public function create(TagNode $node) {
12541211 $sem = $this->getChangeSemantic($node->qName);
1255 - if (0 == strcasecmp($node->qName,'a')){
 1212+ if (strcasecmp($node->qName,'a') == 0) {
12561213 return new AnchorToString($node, $sem);
12571214 }
1258 - if (0 == strcasecmp($node->qName,'img')){
 1215+ if (strcasecmp($node->qName,'img') == 0) {
12591216 return new NoContentTagToString($node, $sem);
12601217 }
12611218 return new TagToString($node, $sem);
12621219 }
12631220
12641221 protected function getChangeSemantic($qname) {
1265 - if (array_key_exists(strtolower($qname),self::$containerTags)){
 1222+ if (in_array(strtolower($qname),self::$containerTags)) {
12661223 return self::MOVED;
12671224 }
1268 - if (array_key_exists(strtolower($qname),self::$styleTags)){
 1225+ if (in_array(strtolower($qname),self::$styleTags)) {
12691226 return self::STYLE;
12701227 }
12711228 return self::UNKNOWN;
@@ -1353,24 +1310,31 @@
13541311 }
13551312
13561313 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;
13681316 }
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) {
13701334 $txt->addText(' '
13711335 . strtolower($this->getAnd())
13721336 . ' '
1373 - . $this->translateArgument($keys[sizeof($attributes) - 1]) . ' '
1374 - . $attributes[$keys[sizeof($attributes) - 1]]);
 1337+ . $this->translateArgument($lastKey) . ' '
 1338+ . $attributes[$lastKey]);
13751339 }
13761340 }
13771341
@@ -1383,12 +1347,15 @@
13841348 }
13851349
13861350 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+ }
13931360 return $name;
13941361 }
13951362
@@ -1408,92 +1375,93 @@
14091376 return $this->getString('diff-' . $this->node->qName . '-article');
14101377 }
14111378
 1379+ // FIXME: Use messages for this
14121380 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'
14981466 );
14991467
15001468 public function getString($key) {
@@ -1543,7 +1511,7 @@
15441512 }
15451513
15461514 protected function addAttributes(ChangeText $txt, array $attributes) {
1547 - if (array_key_exists('href',$attributes)) {
 1515+ if (array_key_exists('href', $attributes)) {
15481516 $txt->addText(' ' . strtolower($this->getWithDestination()) . ' ' . $attributes['href']);
15491517 unset($attributes['href']);
15501518 }
@@ -1572,7 +1540,7 @@
15731541 public function parse(TagNode $node) {
15741542 $handler = &$this->handler;
15751543
1576 - if (0 != strcasecmp($node->qName,'img') && 0 != strcasecmp($node->qName,'body')) {
 1544+ if (strcasecmp($node->qName, 'img') != 0 && strcasecmp($node->qName, 'body') != 0) {
15771545 $handler->startElement($node->qName, $node->attributes);
15781546 }
15791547
@@ -1600,7 +1568,8 @@
16011569 if ($newStarted && ($mod->type != Modification::ADDED || $mod->firstOfID)) {
16021570 $handler->endElement('span');
16031571 $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)) {
16051574 $handler->endElement('span');
16061575 $changeStarted = false;
16071576 } else if ($remStarted && ($mod->type != Modification::REMOVED || $mod ->firstOfID)) {
@@ -1611,25 +1580,25 @@
16121581 // no else because a removed part can just be closed and a new
16131582 // part can start
16141583 if (!$newStarted && $mod->type == Modification::ADDED) {
1615 - $attrs = array('class'=>'diff-html-added');
 1584+ $attrs = array('class' => 'diff-html-added');
16161585 if ($mod->firstOfID) {
1617 - $attrs['id'] = 'added-' . $this->prefix . '-' . $mod->id;
 1586+ $attrs['id'] = "added-{$this->prefix}-{$mod->id}";
16181587 }
16191588 $this->addAttributes($mod, $attrs);
16201589 $attrs['onclick'] = 'return tipA(constructToolTipA(this));';
16211590 $handler->startElement('span', $attrs);
16221591 $newStarted = true;
16231592 } else if (!$changeStarted && $mod->type == Modification::CHANGED) {
1624 - $attrs = array('class'=>'diff-html-changed');
 1593+ $attrs = array('class' => 'diff-html-changed');
16251594 if ($mod->firstOfID) {
1626 - $attrs['id'] = 'changed-' . $this->prefix . '-' . $mod->id;
 1595+ $attrs['id'] = "changed-{$this->prefix}-{$mod->id}";
16271596 }
16281597 $this->addAttributes($mod, $attrs);
16291598 $attrs['onclick'] = 'return tipC(constructToolTipC(this));';
16301599 $handler->startElement('span', $attrs);
16311600
16321601 //tooltip
1633 - $handler->startElement('span', array('class'=>'tip'));
 1602+ $handler->startElement('span', array('class' => 'tip'));
16341603 $handler->characters($mod->changes);
16351604 $handler->endElement('span');
16361605
@@ -1638,7 +1607,7 @@
16391608 } else if (!$remStarted && $mod->type == Modification::REMOVED) {
16401609 $attrs = array('class'=>'diff-html-removed');
16411610 if ($mod->firstOfID) {
1642 - $attrs['id'] = 'removed-' . $this->prefix . '-' . $mod->id;
 1611+ $attrs['id'] = "removed-{$this->prefix}-{$mod->id}";
16431612 }
16441613 $this->addAttributes($mod, $attrs);
16451614 $attrs['onclick'] = 'return tipR(constructToolTipR(this));';
@@ -1668,17 +1637,19 @@
16691638 $remStarted = false;
16701639 }
16711640
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+ }
16751645 }
16761646
1677 - private function writeImage(ImageNode $imgNode){
 1647+ private function writeImage(ImageNode $imgNode) {
16781648 $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+ }
16831654 $attrs['onload'] = 'updateOverlays()';
16841655 $attrs['onError'] = 'updateOverlays()';
16851656 $attrs['onAbort'] = 'updateOverlays()';
@@ -1690,36 +1661,33 @@
16911662 if (is_null($mod->prevMod)) {
16921663 $previous = 'first-' . $this->prefix;
16931664 } 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}";
16961667 }
16971668 $attrs['previous'] = $previous;
16981669
1699 - $changeId = Modification::typeToString($mod->type) . '-' + $this->prefix . '-' . $mod->id;
 1670+ $type = Modification::typeToString($mod->type);
 1671+ $changeId = "$type-{$this->prefix}-{$mod->id}";
17001672 $attrs['changeId'] = $changeId;
17011673
17021674 if (is_null($mod->nextMod )) {
1703 - $next = 'last-' . $this->prefix;
 1675+ $next = "last-{$this->prefix}";
17041676 } 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}";
17071679 }
17081680 $attrs['next'] = $next;
17091681 }
17101682 }
17111683
1712 -class EchoingContentHandler{
 1684+class EchoingContentHandler {
17131685
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);
17201688 }
17211689
17221690 function endElement($qname){
1723 - echo '</'.$qname.'>';
 1691+ echo Xml::closeElement($qname);
17241692 }
17251693
17261694 function characters($chars){
@@ -1728,28 +1696,23 @@
17291697
17301698 }
17311699
1732 -class DelegatingContentHandler{
 1700+class DelegatingContentHandler {
17331701
17341702 private $delegate;
17351703
1736 - function __construct($delegate){
1737 - $this->delegate=$delegate;
 1704+ function __construct($delegate) {
 1705+ $this->delegate = $delegate;
17381706 }
17391707
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));
17461710 }
17471711
17481712 function endElement($qname){
1749 - $this->delegate->addHtml('</'.$qname.'>');
 1713+ $this->delegate->addHtml(Xml::closeElement($qname));
17501714 }
17511715
17521716 function characters($chars){
1753 - $this->delegate->addHtml( $chars );
 1717+ $this->delegate->addHtml($chars);
17541718 }
1755 -
17561719 }
Index: trunk/phase3/includes/Diff.php
@@ -30,7 +30,7 @@
3131 * @author Guy Van den Broeck
3232 *
3333 */
34 -class WikiDiff3{
 34+class WikiDiff3 {
3535
3636 //Input variables
3737 private $from;
@@ -59,45 +59,45 @@
6060 public function diff(/*array*/ $from, /*array*/ $to){
6161 //remember initial lengths
6262 $m = sizeof($from);
63 - $n = sizeof($to);
 63+ $n = count($to);
6464
65 - $this->heuristicUsed = FALSE;
 65+ $this->heuristicUsed = false;
6666
6767 //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();
7070
7171 //reduce the complexity for the next step (intentionally done twice)
7272 //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]) {
7575 $removed[$i] = $added[$i] = false;
76 - unset($from[$i],$to[$i]);
 76+ unset($from[$i], $to[$i]);
7777 ++$i;
7878 }
7979
8080 //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]);
8585 ++$j;
8686 }
8787
8888 $this->from = $newFromIndex = $this->to = $newToIndex = array();
8989
9090 //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)) {
9494 //keep it
9595 $this->to[] = $el;
9696 $shared[$el] = true;
9797 $newToIndex[] = $index;
9898 }
9999 }
100 - foreach($from as $index => $el){
101 - if($shared[$el]){
 100+ foreach($from as $index => $el) {
 101+ if($shared[$el]) {
102102 //keep it
103103 $this->from[] = $el;
104104 $newFromIndex[] = $index;
@@ -106,15 +106,15 @@
107107
108108 unset($shared, $from, $to);
109109
110 - $this->m = sizeof($this->from);
111 - $this->n = sizeof($this->to);
 110+ $this->m = count($this->from);
 111+ $this->n = count($this->to);
112112
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();
115115
116116 if ($this->m == 0 || $this->n == 0) {
117117 $this->length = 0;
118 - }else{
 118+ } else {
119119 $this->maxDifferences = ceil(($this->m + $this->n) / 2.0);
120120 if ($this->m * $this->n > $this->tooLong) {
121121 // limit complexity to D^POW_LIMIT for long sequences
@@ -128,7 +128,8 @@
129129 */
130130 $max = min($this->m, $this->n);
131131 for ($forwardBound = 0; $forwardBound < $max
132 - && $this->from[$forwardBound]===$this->to[$forwardBound]; ++$forwardBound) {
 132+ && $this->from[$forwardBound] === $this->to[$forwardBound];
 133+ ++$forwardBound) {
133134 $this->removed[$forwardBound] = $this->added[$forwardBound] = false;
134135 }
135136
@@ -136,31 +137,31 @@
137138 $backBoundL2 = $this->n - 1;
138139
139140 while ($backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound
140 - && $this->from[$backBoundL1] === $this->to[$backBoundL2]) {
 141+ && $this->from[$backBoundL1] === $this->to[$backBoundL2]) {
141142 $this->removed[$backBoundL1--] = $this->added[$backBoundL2--] = false;
142143 }
143144
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);
147148
148149 $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);
151152 }
152153
153154 $this->m = $m;
154155 $this->n = $n;
155156
156 - $this->length += $i+$j-1;
 157+ $this->length += $i + $j - 1;
157158
158 - foreach($this->removed as $key => $removed_elem){
159 - if(!$removed_elem){
 159+ foreach($this->removed as $key => $removed_elem) {
 160+ if(!$removed_elem) {
160161 $removed[$newFromIndex[$key]] = false;
161162 }
162163 }
163 - foreach($this->added as $key => $added_elem){
164 - if(!$added_elem){
 164+ foreach($this->added as $key => $added_elem) {
 165+ if(!$added_elem) {
165166 $added[$newToIndex[$key]] = false;
166167 }
167168 }
@@ -168,7 +169,7 @@
169170 $this->added = $added;
170171 }
171172
172 - function diff_range ($from_lines, $to_lines){
 173+ function diff_range($from_lines, $to_lines) {
173174 // Diff and store locally
174175 $this->diff($from_lines, $to_lines);
175176 unset($from_lines, $to_lines);
@@ -177,24 +178,26 @@
178179 $xi = $yi = 0;
179180 while ($xi < $this->m || $yi < $this->n) {
180181 // 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]) {
183185 ++$xi;
184186 ++$yi;
185187 }
186188 // Find deletes & adds.
187189 $xstart = $xi;
188 - while ($xi < $this->m && $this->removed[$xi]){
 190+ while ($xi < $this->m && $this->removed[$xi]) {
189191 ++$xi;
190192 }
191193
192194 $ystart = $yi;
193 - while ($yi < $this->n && $this->added[$yi]){
 195+ while ($yi < $this->n && $this->added[$yi]) {
194196 ++$yi;
195197 }
196198
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);
199202 }
200203 }
201204 return $ranges;
@@ -206,10 +209,11 @@
207210 return 0;
208211 }
209212
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);
211215
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
214218 $len = $snake[2];
215219 $startx = $snake[0];
216220 $starty = $snake[1];
@@ -221,8 +225,10 @@
222226
223227 if ($d > 1) {
224228 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);
227233 } else if ($d == 1) {
228234 /*
229235 * In this case the sequences differ by exactly 1 line. We have
@@ -231,7 +237,8 @@
232238 */
233239 $max = min($startx - $bottoml1, $starty - $bottoml2);
234240 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;
236243 }
237244 return $max + $len;
238245 }
@@ -253,11 +260,10 @@
254261 $delta = $N - $M;
255262 $maxabsx = $N+$bottoml1;
256263 $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));
258265
259266 //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
262268 if (($M & 1) == 1) {
263269 $value_to_add_forward = 1;
264270 } else {
@@ -275,12 +281,12 @@
276282 $start_backward = -$N;
277283 $end_backward = $M;
278284
279 - $limit_min_1 = $limit-1;
280 - $limit_plus_1 = $limit+1;
 285+ $limit_min_1 = $limit - 1;
 286+ $limit_plus_1 = $limit + 1;
281287
282288 $V0[$limit_plus_1] = 0;
283289 $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));
285291
286292 if (($delta & 1) == 1) {
287293 for ($d = 0; $d <= $limit; ++$d) {
@@ -290,8 +296,8 @@
291297
292298 // compute forward furthest reaching paths
293299 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])) {
296302 $x = $V0[$limit_plus_1 + $k];
297303 } else {
298304 $x = $V0[$limit_min_1 + $k] + 1;
@@ -309,14 +315,14 @@
310316 $snake2 = $absx -$snake0;
311317 $V0[$limit + $k] = $x;
312318 if ($k >= $delta - $d + 1 && $k <= $delta + $d - 1
313 - && $x >= $V1[$limit + $k - $delta]) {
 319+ && $x >= $V1[$limit + $k - $delta]) {
314320 return 2 * $d - 1;
315321 }
316322
317323 // check to see if we can cut down the diagonal range
318324 if ($x >= $N && $end_forward > $k - 1) {
319325 $end_forward = $k - 1;
320 - } else if ($absy-$bottoml2 >= $M) {
 326+ } else if ($absy - $bottoml2 >= $M) {
321327 $start_forward = $k + 1;
322328 $value_to_add_forward = 0;
323329 }
@@ -407,7 +413,7 @@
408414
409415 $snake2 = 0;
410416 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]) {
412418 --$x;
413419 --$y;
414420 ++$snake2;
@@ -415,7 +421,7 @@
416422 $V1[$limit + $k] = $x;
417423
418424 if ($k >= -$delta - $d && $k <= $d - $delta
419 - && $x <= $V0[$limit + $k + $delta]) {
 425+ && $x <= $V0[$limit + $k + $delta]) {
420426 $snake0 = $bottoml1 + $x;
421427 $snake1 = $bottoml2 + $y;
422428 return 2 * $d;
@@ -472,11 +478,11 @@
473479
474480 $backward_end_diag = -min($M, $limit);
475481
476 - $temp = array(0,0,0);
 482+ $temp = array(0, 0, 0);
477483
478484
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);
481487 $num_progress = 0; // the 1st entry is current, it is initialized
482488 // with 0s
483489
@@ -560,9 +566,9 @@
561567 function __construct($leftstart, $leftend, $rightstart, $rightend){
562568 $this->leftstart = $leftstart;
563569 $this->leftend = $leftend;
564 - $this->leftlength = $leftend-$leftstart;
 570+ $this->leftlength = $leftend - $leftstart;
565571 $this->rightstart = $rightstart;
566572 $this->rightend = $rightend;
567 - $this->rightlength = $rightend-$rightstart;
 573+ $this->rightlength = $rightend - $rightstart;
568574 }
569575 }
Index: trunk/phase3/includes/DifferenceEngine.php
@@ -266,13 +266,13 @@
267267 '<div id="mw-diff-ntitle3">' . $newminor . $sk->revComment( $this->mNewRev, !$diffOnly, true ) . $rdel . "</div>" .
268268 '<div id="mw-diff-ntitle4">' . $nextlink . $patrol . '</div>';
269269
270 - if($wgEnableHtmlDiff){
 270+ if( $wgEnableHtmlDiff ) {
271271 $this->renderHtmlDiff();
272 - }else{
 272+ } else {
273273
274274 $this->showDiff( $oldHeader, $newHeader );
275275
276 - if ( !$diffOnly ){
 276+ if( !$diffOnly ) {
277277 $this->renderNewRevision();
278278 }
279279 }
@@ -327,7 +327,7 @@
328328
329329
330330 function renderHtmlDiff() {
331 - global $wgOut;
 331+ global $wgOut, $wgTitle, $wgParser;
332332 wfProfileIn( __METHOD__ );
333333
334334 $this->showDiffStyle();
@@ -345,38 +345,38 @@
346346
347347 $this->loadText();
348348
 349+ // Old revision
349350 if( is_object( $this->mOldRev ) ) {
350351 $wgOut->setRevisionId( $this->mOldRev->getId() );
351352 }
352353
353 - global $wgTitle, $wgParser, $wgTitle;
354354 $popts = $wgOut->parserOptions();
355 - $oldTidy = $popts->setTidy( TRUE );
 355+ $oldTidy = $popts->setTidy( true );
356356
357 - $parserOutput = $wgParser->parse($this->mOldtext, $wgTitle, $popts, TRUE, TRUE, $wgOut->mRevisionId );
 357+ $parserOutput = $wgParser->parse( $this->mOldtext, $wgTitle, $popts, true, true, $wgOut->getRevisionId() );
358358 $popts->setTidy( $oldTidy );
359359
360360 //only for new?
361361 //$wgOut->addParserOutputNoText( $parserOutput );
362 - $oldHtml = $parserOutput->getText();
363 - wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$oldHtml ) );
 362+ $oldHtml = $parserOutput->getText();
 363+ wfRunHooks( 'OutputPageBeforeHTML', array( &$wgOut, &$oldHtml ) );
364364
 365+ // New revision
365366 if( is_object( $this->mNewRev ) ) {
366367 $wgOut->setRevisionId( $this->mNewRev->getId() );
367368 }
368369
369370 $popts = $wgOut->parserOptions();
370 - $oldTidy = $popts->setTidy( TRUE );
 371+ $oldTidy = $popts->setTidy( true );
371372
372 - $parserOutput = $wgParser->parse($this->mNewtext, $wgTitle, $popts, TRUE, TRUE, $wgOut->mRevisionId );
 373+ $parserOutput = $wgParser->parse( $this->mNewtext, $wgTitle, $popts, true, true, $wgOut->getRevisionId() );
373374 $popts->setTidy( $oldTidy );
374375
375 - //only for new?
376376 $wgOut->addParserOutputNoText( $parserOutput );
377 - $newHtml = $parserOutput->getText();
378 - wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$newHtml ) );
 377+ $newHtml = $parserOutput->getText();
 378+ wfRunHooks( 'OutputPageBeforeHTML', array( &$wgOut, &$newHtml ) );
379379
380 - unset($parserOutput,$popts);
 380+ unset($parserOutput, $popts);
381381
382382 $differ = new HTMLDiffer(new DelegatingContentHandler($wgOut));
383383 $differ->htmlDiff($oldHtml, $newHtml);

Status & tagging log