4 This plugin catches concurrent edits of a page, and lets the 'patch'
5 and 'diff' utilities try to merge the different versions. This will
6 often prevent the "This page version was already saved by someone else"
8 Please use the GNU diff and patch only. Sometimes the unified output
9 format may be superiour; but this depends on the subjects in your Wiki.
12 define("EWIKI_BIN_DIFF", "/usr/bin/diff");
13 define("EWIKI_BIN_PATCH", "/usr/bin/patch");
15 if (function_exists("is_executable") && is_executable(EWIKI_BIN_PATCH
) && is_executable(EWIKI_BIN_DIFF
)) {
16 $ewiki_plugins["edit_patch"][] = "ewiki_edit_patch";
20 function ewiki_edit_patch($id, &$data) {
24 $base = ewiki_database(
26 array("id"=>$id, "version"=>$_REQUEST["version"])
32 $fn_base = EWIKI_TMP
."/ewiki.base.".md5($base["content"]);
33 $fn_requ = EWIKI_TMP
."/ewiki..requ.".md5($_REQUEST["content"]);
34 $fn_patch = EWIKI_TMP
."/ewiki.patch.".md5($base["content"])."-".md5($_REQUEST["content"]);
35 $fn_curr = EWIKI_TMP
."/ewiki.curr.".md5($data["content"]);
37 if ($f = fopen($fn_base, "w")) {
38 fwrite($f, $base["content"]);
45 if ($f = fopen($fn_requ, "w")) {
46 fwrite($f, $_REQUEST["content"]);
54 if ($f = fopen($fn_curr, "w")) {
55 fwrite($f, $data["content"]);
64 exec("diff -c $fn_base $fn_requ > $fn_patch", $output, $retval);
67 exec("patch $fn_curr $fn_patch", $output, $retval);
70 $_REQUEST["version"] = $curr["version"];
71 $_REQUEST["content"] = implode("", file($fn_curr));