<?php
// PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: diff.php,v 1.5 2005/04/30 05:21:00 henoheno Exp $
+// $Id: diff.php,v 1.6 2005/12/10 12:23:24 henoheno Exp $
// Copyright (C)
// 2003-2005 PukiWiki Developers Team
// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
-//¾×ÆÍ»þ¤ËÂбþɽ¤ò½Ð¤¹
-define('DIFF_SHOW_TABLE',TRUE);
-// º¹Ê¬¤ÎºîÀ®
+// Show more information when it conflicts
+define('PKWK_DIFF_SHOW_CONFLICT_DETAIL', 1);
+
+// Create diff-style data between arrays
function do_diff($strlines1, $strlines2)
{
$obj = new line_diff();
return $str;
}
-// º¹Ê¬¤ÎºîÀ®(¹¹¿·¤Î¾×ÆÍ)
+// Merge helper (when it conflicts)
function do_update_diff($pagestr, $poststr, $original)
{
$obj = new line_diff();
$arr = $obj->arr_compare('all', $diff1, $diff2);
- if (DIFF_SHOW_TABLE)
- {
+ if (PKWK_DIFF_SHOW_CONFLICT_DETAIL) {
global $do_update_diff_table;
$do_update_diff_table = <<<EOD
</tr>
EOD;
$tags = array('th', 'th', 'td');
- foreach ($arr as $_obj)
- {
+ foreach ($arr as $_obj) {
$do_update_diff_table .= '<tr>';
$params = array($_obj->get('left'), $_obj->get('right'), $_obj->text());
foreach ($params as $key=>$text) {
$text = htmlspecialchars($text);
if (trim($text) == '') $text = ' ';
- $do_update_diff_table .= "<{$tags[$key]} class=\"style_{$tags[$key]}\">$text</{$tags[$key]}>";
+ $do_update_diff_table .= '<' . $tags[$key] .
+ ' class="style_' . $tags[$key] . '">' . $text .
+ '</' . $tags[$key] . '>';
}
- $do_update_diff_table .= '</tr>'."\n";
+ $do_update_diff_table .= '</tr>' . "\n";
}
- $do_update_diff_table .= '</table>'."\n";
+ $do_update_diff_table .= '</table>' . "\n";
}
$body = '';
return array(rtrim($body) . "\n", $auto);
}
-/*
-line_diff¥¯¥é¥¹
-
-°Ê²¼¤Î¾ðÊó¤ò»²¹Í¤Ë¤·¤ÆºîÀ®¤·¤Þ¤·¤¿¡£
-
-S. Wu, <A HREF="http://www.cs.arizona.edu/people/gene/vita.html">
-E. Myers,</A> U. Manber, and W. Miller,
-<A HREF="http://www.cs.arizona.edu/people/gene/PAPERS/np_diff.ps">
-"An O(NP) Sequence Comparison Algorithm,"</A>
-Information Processing Letters 35, 6 (1990), 317-323.
-
-*/
+// References of this class:
+// S. Wu, <A HREF="http://www.cs.arizona.edu/people/gene/vita.html">
+// E. Myers,</A> U. Manber, and W. Miller,
+// <A HREF="http://www.cs.arizona.edu/people/gene/PAPERS/np_diff.ps">
+// "An O(NP) Sequence Comparison Algorithm,"</A>
+// Information Processing Letters 35, 6 (1990), 317-323.
class line_diff
{
var $arr1, $arr2, $m, $n, $pos, $key, $plus, $minus, $equal, $reverse;
$this->key = $key;
$this->arr1 = array();
$this->arr2 = array();
- $str1 = preg_replace("/\r/",'',$str1);
- $str2 = preg_replace("/\r/",'',$str2);
+ $str1 = str_replace("\r", '', $str1);
+ $str2 = str_replace("\r", '', $str2);
foreach (explode("\n", $str1) as $line) {
$this->arr1[] = new DiffLine($line);
}
$this->m = count($this->arr1);
$this->n = count($this->arr2);
- if ($this->m == 0 || $this->n == 0) { // no need compare.
+ if ($this->m == 0 || $this->n == 0) { // No need to compare
$this->result = array(array('x'=>0, 'y'=>0));
return;
}
- // sentinel
+ // Sentinel
array_unshift($this->arr1, new DiffLine(''));
$this->m++;
array_unshift($this->arr2, new DiffLine(''));
function toArray()
{
$arr = array();
- if ($this->reverse) { //¸È©¤Ê¡Ä
+ if ($this->reverse) { // ¸È©¤Ê¡Ä
$_x = 'y'; $_y = 'x'; $_m = $this->n; $arr1 =& $this->arr2; $arr2 =& $this->arr1;
} else {
$_x = 'x'; $_y = 'y'; $_m = $this->m; $arr1 =& $this->arr1; $arr2 =& $this->arr2;
function DiffLine($text)
{
- $this->text = "$text\n";
+ $this->text = $text . "\n";
$this->status = array();
}