3 # This diff plugin utilizes the external GNU diff program to show up
4 # differences between two versions of a WikiPage.
5 # The diff utility is commonly not part of the graphical OS simulators
6 # from Redmond, but you could install the Cygwin environment to make
11 $ewiki_plugins["action"]["diff"] = "ewiki_page_gnu_diff";
12 $ewiki_config["action_links"]["info"]["diff"] = "diff";
16 function ewiki_page_gnu_diff($id, &$data, $action) {
18 #-- different operation modes of GNU diff:
19 $OPTIONS = " -B -u -U 50 ";
22 # $OPTIONS = " --side-by-side ";
24 #-- fetch old wiki source
25 if (($old_ver = ($new_ver = $data["version"]) - 1) > 0)
26 $data0 = ewiki_db::GET($id, $old_ver);
28 $o = ewiki_make_title($id, "Differences between version $new_ver and $old_ver of »{$id}«");
30 #-- create temporary files from wikipages
31 $file0 = tempnam(EWIKI_TMP, "ewiki.diff.gnu.");
32 $f = fopen($file0, "w");
33 fwrite($f, $data0["content"]);
35 $file1 = tempnam(EWIKI_TMP, "ewiki.diff.gnu.");
36 $f = fopen($file1, "w");
37 fwrite($f, $data["content"]);
40 #-- parse thru GNU diff util
41 $fn = addslashes($id);
42 $OPTIONS .= " --label='$fn (version $old_ver)' --label='$fn (version $new_ver)' ";
43 $diff = shell_exec("diff $OPTIONS $file0 $file1");
45 #-- remove temporary files
49 #-- encolor diff output
50 foreach (explode("\n", $diff) as $dl) {
52 $str = substr($dl, 1);
54 switch (substr($dl, 0, 1)) {
57 $o .= "<b>-</b><font color=\"#990000\"> <tt>$str</tt></font><br />\n";
61 $o .= "<b>+</b><font color=\"#009900\"> <tt>$str</tt></font><br />\n";
67 $o .= "<small><tt>$dl</tt></small><br />";