3 # This plugin is a small modification of the original diff_gnu.php plugin.
4 # It allows use with safemode enabled.
5 # However it requires the directory where diff is located to be in the php ini
6 # This way you can still control what programs are executed by PHP and the programs
7 # can have root as owner.
8 # Of course its not smart to put the normal bin in your php settings, cause that
9 # would effectively disable safemode, just copying the diff utility works best.
11 # Example phpsettings entry:
12 # safe_mode_exec_dir = /usr/local/bin/ewiki
14 # With safemode disabled it should work without any special settings.
16 # Original plugin comment:
18 # This diff plugin utilizes the external GNU diff program to show up
19 # differences between two versions of a WikiPage.
20 # The diff utility is commonly not part of the graphical OS simulators
21 # from Redmond, but you could install the Cygwin environment to make
26 $ewiki_plugins["action"]["diff"] = "ewiki_page_gnu_diff_safemode";
27 $ewiki_config["action_links"]["info"]["diff"] = "diff";
31 function ewiki_page_gnu_diff_safemode($id, &$data, $action) {
33 #-- different operation modes of GNU diff:
34 $OPTIONS = " -B -u -U 50 ";
37 # $OPTIONS = " --side-by-side ";
39 #-- fetch old wiki source
40 if (($old_ver = ($new_ver = $data["version"]) - 1) > 0)
41 $data0 = ewiki_db::GET($id, $old_ver);
43 $o = ewiki_make_title($id, "Differences between version $new_ver and $old_ver of »{$id}«");
45 #-- create temporary files from wikipages
46 $file0 = tempnam(EWIKI_TMP, "ewiki.diff.gnu.");
47 $f = fopen($file0, "w");
48 fwrite($f, $data0["content"]);
50 $file1 = tempnam(EWIKI_TMP, "ewiki.diff.gnu.");
51 $f = fopen($file1, "w");
52 fwrite($f, $data["content"]);
55 #-- parse thru GNU diff util
56 $fn = addslashes($id);
57 $OPTIONS .= " --label='$fn (version $old_ver)' --label='$fn (version $new_ver)' ";
58 //following lines replace the original
59 //$diff = shell_exec("diff $OPTIONS $file0 $file1");
60 $dfd = popen("diff $OPTIONS $file0 $file1", "r");
63 $diff .= fread($dfd, 5000);
68 #-- remove temporary files
72 #-- encolor diff output
73 foreach (explode("\n", $diff) as $dl) {
75 $str = substr($dl, 1);
77 switch (substr($dl, 0, 1)) {
80 $o .= "<b>-</b><font color=\"#990000\"> <tt>$str</tt></font><br />\n";
84 $o .= "<b>+</b><font color=\"#009900\"> <tt>$str</tt></font><br />\n";
90 $o .= "<small><tt>$dl</tt></small><br />";