OSDN Git Service

Moved face images from face/ to image/face. default.ini.php shows bracketted alt...
[pukiwiki/pukiwiki.git] / diff.php
index 014ba4f..9548f97 100644 (file)
--- a/diff.php
+++ b/diff.php
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id:
+// $Id: diff.php,v 1.7 2003/06/11 00:00:51 arino Exp $
 //
 //¾×ÆÍ»þ¤ËÂбþɽ¤ò½Ð¤¹
 define('DIFF_SHOW_TABLE',TRUE);
@@ -30,19 +30,44 @@ function do_update_diff($pagestr,$poststr,$original)
        
        $arr = $obj->arr_compare('all',$diff1,$diff2);
        
-       if (DIFF_SHOW_TABLE) {
+       if (DIFF_SHOW_TABLE)
+       {
                global $do_update_diff_table;
-               $do_update_diff_table = '<p>l : base ¢ª pagedata<br />r : base ¢ª postdata</p>'."\n";
-               $do_update_diff_table .= '<table border="1"><tr><th>l</th><th>r</th><th>text</th></tr>'."\n";
-               foreach ($arr as $_obj) {
-                       $do_update_diff_table .= '<tr><td>'.$_obj->get('left').'</td><td>'.$_obj->get('right').'</td><td>'.htmlspecialchars($_obj->text()).'</td></tr>'."\n";
+               
+               $do_update_diff_table = <<<EOD
+<p>l : between backup data and stored page data.<br />
+ r : between backup data and your post data.</p>
+<table class="style_table">
+ <tr>
+  <th>l</th>
+  <th>r</th>
+  <th>text</th>
+ </tr>
+EOD;
+               $tags = array('th','th','td');
+               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 = '&nbsp;';
+                               }
+                               $do_update_diff_table .= "<{$tags[$key]} class=\"style_{$tags[$key]}\">$text</{$tags[$key]}>";
+                       }
+                       $do_update_diff_table .= '</tr>'."\n";
                }
                $do_update_diff_table .= '</table>'."\n";
        }
        
        $body = '';
-       foreach ($arr as $_obj) {
-               if ($_obj->get('left') != '-' and $_obj->get('right') != '-') {
+       foreach ($arr as $_obj)
+       {
+               if ($_obj->get('left') != '-' and $_obj->get('right') != '-')
+               {
                        $body .= $_obj->text();
                }
        }
@@ -87,14 +112,16 @@ class line_diff
        function set_str($key,$str1,$str2)
        {
                $this->key = $key;
-               $this->arr1 = array(new DiffLine(''));
-               $this->arr2 = array(new DiffLine(''));
+               $this->arr1 = array();
+               $this->arr2 = array();
                $str1 = preg_replace("/\r/",'',$str1);
                $str2 = preg_replace("/\r/",'',$str2);
-               foreach (explode("\n",$str1) as $line) {
+               foreach (explode("\n",$str1) as $line)
+               {
                        $this->arr1[] = new DiffLine($line);
                }
-               foreach (explode("\n",$str2) as $line) {
+               foreach (explode("\n",$str2) as $line)
+               {
                        $this->arr2[] = new DiffLine($line);
                }
        }
@@ -104,48 +131,61 @@ class line_diff
                $this->compare();
                
                $str = '';
-               foreach ($this->toArray() as $obj) {
+               foreach ($this->toArray() as $obj)
+               {
                        $str .= $obj->get('diff').$obj->text();
                }
                return $str;
        }
        function compare()
        {
-               $this->m = count($this->arr1) - 1;
-               $this->n = count($this->arr2) - 1;
+               $this->m = count($this->arr1);
+               $this->n = count($this->arr2);
+               
+               if ($this->m == 0 or $this->n == 0) // no need compare.
+               {
+                       $this->result = array(array('x'=>0,'y'=>0));
+                       return;
+               }
+               
+               // sentinel
+               array_unshift($this->arr1,new DiffLine(''));
+               $this->m++;
+               array_unshift($this->arr2,new DiffLine(''));
+               $this->n++;
+               
                $this->reverse = ($this->n < $this->m);
-               if ($this->reverse) { // swap
+               if ($this->reverse) // swap
+               {
                        $tmp = $this->m; $this->m = $this->n; $this->n = $tmp;
                        $tmp = $this->arr1; $this->arr1 = $this->arr2; $this->arr2 = $tmp;
                        unset($tmp);
                }
                
-               $sentinel = array('x'=>0,'y'=>0);
-               
-               if ($this->m <= 0) { // no need compare.
-                       $this->result = array($sentinel);
-                       return;
-               }
-               
                $delta = $this->n - $this->m; // must be >=0;
                
                $fp = array();
                $this->path = array();
                
-               for ($p = -($this->m + 1); $p <= $this->n + 1; $p++) {
+               for ($p = -($this->m + 1); $p <= ($this->n + 1); $p++)
+               {
                        $fp[$p] = -1;
                        $this->path[$p] = array();
                }
                
-               for ($p = 0;; $p++) {
-                       for ($k = -$p; $k <= $delta - 1; $k++) {
+               for ($p = 0;; $p++)
+               {
+                       for ($k = -$p; $k <= $delta - 1; $k++)
+                       {
                                $fp[$k] = $this->snake($k, $fp[$k - 1], $fp[$k + 1]);
                        }
-                       for ($k = $delta + $p; $k >= $delta + 1; $k--) {
+                       for ($k = $delta + $p; $k >= $delta + 1; $k--)
+                       {
                                $fp[$k] = $this->snake($k, $fp[$k - 1], $fp[$k + 1]);
                        }
                        $fp[$delta] = $this->snake($delta, $fp[$delta - 1], $fp[$delta + 1]);
-                       if ($fp[$delta] >= $this->n) {
+                       if ($fp[$delta] >= $this->n)
+                       {
                                $this->pos = $this->path[$delta]; // ·ÐÏ©¤ò·èÄê
                                return;
                        }
@@ -153,17 +193,21 @@ class line_diff
        }
        function snake($k, $y1, $y2)
        {
-               if ($y1 >= $y2) {
+               if ($y1 >= $y2)
+               {
                        $_k = $k - 1;
                        $y = $y1 + 1;
                }
-               else {
+               else
+               {
                        $_k = $k + 1;
                        $y = $y2;
                }
                $this->path[$k] = $this->path[$_k];// ¤³¤³¤Þ¤Ç¤Î·ÐÏ©¤ò¥³¥Ô¡¼
                $x = $y - $k;
-               while (($x < $this->m) and ($y < $this->n) and $this->arr1[$x + 1]->compare($this->arr2[$y + 1])) {
+               while ((($x + 1) < $this->m) and (($y + 1) < $this->n)
+                       and $this->arr1[$x + 1]->compare($this->arr2[$y + 1]))
+               {
                        $x++; $y++;
                        $this->path[$k][] = array('x'=>$x,'y'=>$y); // ·ÐÏ©¤òÄɲÃ
                }
@@ -172,30 +216,37 @@ class line_diff
        function toArray()
        {
                $arr = array();
-               if ($this->reverse) { //¸È©¤Ê¡Ä
+               if ($this->reverse) //¸È©¤Ê¡Ä
+               {
                        $_x = 'y'; $_y = 'x'; $_m = $this->n; $arr1 =& $this->arr2; $arr2 =& $this->arr1;
                }
-               else {
+               else
+               {
                        $_x = 'x'; $_y = 'y'; $_m = $this->m; $arr1 =& $this->arr1; $arr2 =& $this->arr2;
                }
                
                $x = $y = 1;
                $this->add_count = $this->delete_count = 0;
-               foreach ($this->pos as $pos) {
+               $this->pos[] = array('x'=>$this->m,'y'=>$this->n); // sentinel
+               foreach ($this->pos as $pos)
+               {
                        $this->delete_count += ($pos[$_x] - $x);
                        $this->add_count += ($pos[$_y] - $y);
                        
-                       while ($pos[$_x] > $x) {
+                       while ($pos[$_x] > $x)
+                       {
                                $arr1[$x]->set($this->key,$this->minus);
                                $arr[] = $arr1[$x++];
                        }
                        
-                       while ($pos[$_y] > $y) {
+                       while ($pos[$_y] > $y)
+                       {
                                $arr2[$y]->set($this->key,$this->plus);
                                $arr[] =  $arr2[$y++];
                        }
                        
-                       if ($x < $_m) {
+                       if ($x < $_m)
+                       {
                                $arr1[$x]->merge($arr2[$y]);
                                $arr1[$x]->set($this->key,$this->equal);
                                $arr[] = $arr1[$x];
@@ -230,7 +281,7 @@ class DiffLine
        }
        function merge($obj)
        {
-               $this->status = array_merge($this->status,$obj->status);
+               $this->status += $obj->status;
        }
        function text()
        {