Example #1
0
 function diff_local($from_lines, $to_lines)
 {
     global $wgExternalDiffEngine;
     wfProfileIn(__METHOD__);
     if ($wgExternalDiffEngine == 'wikidiff3') {
         // wikidiff3
         $wikidiff3 = new WikiDiff3();
         $wikidiff3->diff($from_lines, $to_lines);
         $this->xchanged = $wikidiff3->removed;
         $this->ychanged = $wikidiff3->added;
         unset($wikidiff3);
     } else {
         // old diff
         $n_from = sizeof($from_lines);
         $n_to = sizeof($to_lines);
         $this->xchanged = $this->ychanged = array();
         $this->xv = $this->yv = array();
         $this->xind = $this->yind = array();
         unset($this->seq);
         unset($this->in_seq);
         unset($this->lcs);
         // Skip leading common lines.
         for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) {
             if ($from_lines[$skip] !== $to_lines[$skip]) {
                 break;
             }
             $this->xchanged[$skip] = $this->ychanged[$skip] = false;
         }
         // Skip trailing common lines.
         $xi = $n_from;
         $yi = $n_to;
         for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) {
             if ($from_lines[$xi] !== $to_lines[$yi]) {
                 break;
             }
             $this->xchanged[$xi] = $this->ychanged[$yi] = false;
         }
         // Ignore lines which do not exist in both files.
         for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
             $xhash[$this->_line_hash($from_lines[$xi])] = 1;
         }
         for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
             $line = $to_lines[$yi];
             if ($this->ychanged[$yi] = empty($xhash[$this->_line_hash($line)])) {
                 continue;
             }
             $yhash[$this->_line_hash($line)] = 1;
             $this->yv[] = $line;
             $this->yind[] = $yi;
         }
         for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
             $line = $from_lines[$xi];
             if ($this->xchanged[$xi] = empty($yhash[$this->_line_hash($line)])) {
                 continue;
             }
             $this->xv[] = $line;
             $this->xind[] = $xi;
         }
         // Find the LCS.
         $this->_compareseq(0, sizeof($this->xv), 0, sizeof($this->yv));
     }
     wfProfileOut(__METHOD__);
 }
Example #2
0
 public function getResult(AncestorComparator $other)
 {
     $diffengine = new WikiDiff3(10000, 1.35);
     $differences = $diffengine->diff_range($other->ancestorsText, $this->ancestorsText);
     if (count($differences) == 0) {
         return null;
     }
     $changeTxt = new ChangeTextGenerator($this, $other);
     return $changeTxt->getChanged($differences)->toString();
 }