function _changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->_final();
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         $this->changedLine($line, $aline);
         $this->originalLineNum++;
         $this->finalLineNum++;
     }
     $this->_added($add);
     // If any leftovers
 }
 function _changed($orig, $closing)
 {
     wfProfileIn(__METHOD__);
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     # Notice that WordLevelDiff returns HTML-escaped output.
     # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         echo '<tr>' . $this->deletedLine($line) . $this->addedLine($aline) . "</tr>\n";
     }
     foreach ($add as $line) {
         # If any leftovers
         echo '<tr>' . $this->emptyLine() . $this->addedLine($line) . "</tr>\n";
     }
     wfProfileOut(__METHOD__);
 }
Beispiel #3
0
 /**
  * Compares to revisions of the page
  *
  * @param	int		$a_left		Nr of first revision
  * @param	int		$a_right	Nr of second revision
  */
 function compareVersion($a_left, $a_right)
 {
     // get page objects
     include_once "./Services/COPage/classes/class.ilPageObjectFactory.php";
     $l_page = ilPageObjectFactory::getInstance($this->getParentType(), $this->getId(), $a_left);
     $r_page = ilPageObjectFactory::getInstance($this->getParentType(), $this->getId(), $a_right);
     $l_hashes = $l_page->getPageContentsHashes();
     $r_hashes = $r_page->getPageContentsHashes();
     // determine all deleted and changed page elements
     foreach ($l_hashes as $pc_id => $h) {
         if (!isset($r_hashes[$pc_id])) {
             $l_hashes[$pc_id]["change"] = "Deleted";
         } else {
             if ($l_hashes[$pc_id]["hash"] != $r_hashes[$pc_id]["hash"]) {
                 $l_hashes[$pc_id]["change"] = "Modified";
                 $r_hashes[$pc_id]["change"] = "Modified";
                 include_once "./Services/COPage/mediawikidiff/class.WordLevelDiff.php";
                 // if modified element is a paragraph, highlight changes
                 if ($l_hashes[$pc_id]["content"] != "" && $r_hashes[$pc_id]["content"] != "") {
                     $new_left = str_replace("\n", "<br />", $l_hashes[$pc_id]["content"]);
                     $new_right = str_replace("\n", "<br />", $r_hashes[$pc_id]["content"]);
                     $wldiff = new WordLevelDiff(array($new_left), array($new_right));
                     $new_left = $wldiff->orig();
                     $new_right = $wldiff->closing();
                     $l_page->setParagraphContent($l_hashes[$pc_id]["hier_id"], $new_left[0]);
                     $r_page->setParagraphContent($l_hashes[$pc_id]["hier_id"], $new_right[0]);
                 }
             }
         }
     }
     // determine all new paragraphs
     foreach ($r_hashes as $pc_id => $h) {
         if (!isset($l_hashes[$pc_id])) {
             $r_hashes[$pc_id]["change"] = "New";
         }
     }
     $l_page->addChangeDivClasses($l_hashes);
     $r_page->addChangeDivClasses($r_hashes);
     return array("l_page" => $l_page, "r_page" => $r_page, "l_changes" => $l_hashes, "r_changes" => $r_hashes);
 }
Beispiel #4
0
 function _changed($orig, $final)
 {
     $diff = new WordLevelDiff($orig, $final);
     $this->_lines($diff->orig(), 'original', '-');
     $this->_lines($diff->_final(), 'final', '+');
 }
 public function _changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         print '<tr>' . $this->deletedLine($line) . $this->addedLine($aline) . "</tr>\n";
     }
     $this->_added($add);
     # If any leftovers
 }
Beispiel #6
0
 function _changed($orig, $final)
 {
     $diff = new WordLevelDiff($orig, $final);
     $div = '<div class="difftext">';
     foreach ($diff->orig() as $line) {
         $div .= "\n" . '<div class="original"><tt class="prefix">-</tt>' . $line . '</div>';
     }
     $this->result .= $div . "</div>\n";
     $div = '<div class="difftext">';
     foreach ($diff->_final() as $line) {
         $div .= "\n" . '<div class="final"><tt class="prefix">+</tt>' . $line . '</div>';
     }
     $this->result .= $div . "</div>\n";
 }
Beispiel #7
0
 function _changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     // Notice that WordLevelDiff returns HTML-escaped output.
     // Hence, we will be calling addedLine/deletedLine without HTML-escaping.
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         $this->rows[] = array_merge($this->deletedLine($line), isset($aline) ? $this->addedLine($aline) : $this->emptyLine());
     }
     foreach ($add as $line) {
         // If any leftovers
         $this->rows[] = array_merge($this->emptyLine(), $this->addedLine($line));
     }
 }
 /**
  * Writes the two sets of lines to the output buffer, each enclosed in <tr>.
  *
  * @param string[] $orig
  * @param string[] $closing
  */
 protected function changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     # Notice that WordLevelDiff returns HTML-escaped output.
     # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
     $ndel = count($del);
     $nadd = count($add);
     $n = max($ndel, $nadd);
     for ($i = 0; $i < $n; $i++) {
         $delLine = $i < $ndel ? $this->deletedLine($del[$i]) : $this->emptyLine();
         $addLine = $i < $nadd ? $this->addedLine($add[$i]) : $this->emptyLine();
         $this->writeOutput("<tr>{$delLine}{$addLine}</tr>\n");
     }
 }
 function _changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->_final();
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         if ($this->type == 'sidebyside') {
             print '<tbody class="mod"><tr>' . $this->deletedLine($line, 'l') . $this->addedLine($aline, 'r') . "</tr></tbody>\n";
         } else {
             print '<tbody class="mod"><tr>' . $this->deletedLine($line, 'l') . "</tr></tbody>\n";
         }
     }
     $this->_added($add);
     // If any leftovers
 }
Beispiel #10
0
 /**
  * Writes the two sets of lines to the output buffer, each enclosed in <tr>.
  *
  * @param string[] $orig
  * @param string[] $closing
  */
 protected function changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     # Notice that WordLevelDiff returns HTML-escaped output.
     # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
     $line = array_shift($del);
     while ($line) {
         $aline = array_shift($add);
         $this->writeOutput('<tr>' . $this->deletedLine($line) . $this->addedLine($aline) . "</tr>\n");
         $line = array_shift($del);
     }
     foreach ($add as $line) {
         # If any leftovers
         $this->writeOutput('<tr>' . $this->emptyLine() . $this->addedLine($line) . "</tr>\n");
     }
 }
Beispiel #11
0
function fancy_diff($diff, $options = array())
{
    global $DBInfo;
    include_once "lib/difflib.php";
    $diff = str_replace("<", "&lt;", $diff);
    $lines = explode("\n", $diff);
    // trash the last empty line;
    $end = end($lines);
    //if (!isset($end[0])) array_pop($lines);
    $out = "";
    #unset($lines[0]); unset($lines[1]);
    $omarker = 0;
    $orig = array();
    $new = array();
    foreach ($lines as $line) {
        if (empty($omarker) and empty($line[0])) {
            continue;
        }
        $marker = $line[0];
        if (in_array($marker, array('-', '+', '@'))) {
            $line = substr($line, 1);
        }
        if ($marker == "@") {
            if (isset($out[0])) {
                $out .= '</div>';
            }
            $out .= '<div class="diff-sep">@' . "{$line}</div><div class='diff-highlight'>";
            continue;
        } else {
            if ($marker == "-") {
                $omarker = 1;
                $orig[] = $line;
                continue;
            } else {
                if ($marker == "+") {
                    $omarker = 1;
                    $new[] = $line;
                    continue;
                } else {
                    if ($marker == "\\") {
                        continue;
                    } else {
                        if ($omarker) {
                            $omarker = 0;
                            $buf = "";
                            $result = new WordLevelDiff($orig, $new, $DBInfo->charset);
                            if (empty($options['inline'])) {
                                foreach ($result->orig() as $ll) {
                                    $buf .= "<div class=\"diff-removed\">{$ll}</div>\n";
                                }
                                foreach ($result->_final() as $ll) {
                                    $buf .= "<div class=\"diff-added\">{$ll}</div>\n";
                                }
                            } else {
                                foreach ($result->all(null, '', false) as $ll) {
                                    $buf .= "<div class=\"diff\">{$ll}</div>\n";
                                }
                            }
                            $orig = array();
                            $new = array();
                            $line = $buf . $line . "<br />";
                        } else {
                            if ($marker == " " and !$omarker) {
                                $line .= "<br />";
                            } else {
                                $line .= "<br />";
                            }
                        }
                    }
                }
            }
        }
        $out .= $line . "\n";
    }
    $out .= '</div>';
    return $out;
}