4 this is the "stupid diff", which shows up changes between two
5 saved versions of a WikiPage; even if working very unclean it
6 allows to see what has changed
7 it is accessible through the "info about page" action
12 $ewiki_plugins["action"]["diff"] = "ewiki_page_stupid_diff";
13 $ewiki_config["action_links"]["info"]["diff"] = "diff";
17 function ewiki_page_stupid_diff($id, $data, $action) {
20 if ($uu=$GLOBALS["ewiki_diff_versions"]) {
21 list($new_ver, $old_ver) = $uu;
22 $data = ewiki_db::GET($id, $new_ver);
25 $new_ver = $data["version"];
26 $old_ver = $new_ver - 1;
29 $data0 = ewiki_db::GET($id, $old_ver);
32 $o = ewiki_make_title($id, "Differences between version $new_ver and $old_ver of »{$id}«");
34 $o .= ewiki_stupid_diff($data["content"], $data0["content"]);
40 function ewiki_stupid_diff($new, $old, $show_unchanged=1, $informational=0) {
42 $old = preg_split("/\s*\n/", trim($old));
43 $new = preg_split("/\s*\n/", trim($new));
45 $diff_rm = array_diff($old, $new);
46 $diff_add = array_diff($new, $old);
48 $i = array_intersect($new, $old);
50 if (count($diff_add) >= (6.5 * count(array_unique($diff_rm)))) {
51 $o .= '<div class="note"><b>(overwritten with previous[?] content)</b></div>' . "\n";
55 $o .= '<div class="note"><b>(previous content completely removed)</b></div>' . "\n";
61 foreach ($new as $i=>$line) {
64 while ($rm = $diff_rm[$i2++]) {
65 $o .= '<div class="del"><b>-</b><font color="#990000"> <tt>' . htmlentities($rm) . "</tt></font></div>\n";
66 unset($diff_rm[$i2-1]);
69 if (in_array($line, $diff_add)) {
70 $o .= '<div class="add"><b>+</b><font color="#009900"> <tt>' . htmlentities($line) . "</tt></font></div>\n";
72 elseif ($show_unchanged) {
73 $o .= "<div><b> </b> " . htmlentities($line) . "</div>\n";
78 foreach ($diff_rm as $rm) {
79 $o .= '<div class="del"><b>-</b><font color="#990000"> <tt>' . htmlentities($rm) . "</tt></font></div>\n";
82 return('<div class="diff">' . $o . '</div>');