1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php if (!defined('PmWiki')) exit();
/* Copyright 2004-2015 Patrick R. Michaud (pmichaud@pobox.com)
This file is part of PmWiki; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. See pmwiki.php for full details.
This file enables merging of concurrent edits, using the "diff3"
program available on most Unix systems to merge the edits. If
diff3 is not available or you'd like to use a different command,
then set $SysMergeCmd accordingly.
Script maintained by Petko YOTOV www.pmwiki.org/petko
*/
array_unshift($EditFunctions,'MergeSimulEdits');
$HTMLStylesFmt['simuledit'] = ".editconflict { color:green;
font-style:italic; margin-top:1.33em; margin-bottom:1.33em; }\n";
function Merge($newtext,$oldtext,$pagetext) {
global $WorkDir,$SysMergeCmd, $SysMergePassthru;
SDV($SysMergeCmd,"/usr/bin/diff3 -L '' -L '' -L '' -m -E");
if (substr($newtext,-1,1)!="\n") $newtext.="\n";
if (substr($oldtext,-1,1)!="\n") $oldtext.="\n";
if (substr($pagetext,-1,1)!="\n") $pagetext.="\n";
$tempnew = tempnam($WorkDir,"new");
$tempold = tempnam($WorkDir,"old");
$temppag = tempnam($WorkDir,"page");
if ($newfp=fopen($tempnew,'w')) { fputs($newfp,$newtext); fclose($newfp); }
if ($oldfp=fopen($tempold,'w')) { fputs($oldfp,$oldtext); fclose($oldfp); }
if ($pagfp=fopen($temppag,'w')) { fputs($pagfp,$pagetext); fclose($pagfp); }
$mergetext = '';
if (IsEnabled($SysMergePassthru, 0)) {
ob_start();
passthru("$SysMergeCmd $tempnew $tempold $temppag");
$mergetext = ob_get_clean();
}
else {
$merge_handle = popen("$SysMergeCmd $tempnew $tempold $temppag",'r');
if ($merge_handle) {
while (!feof($merge_handle)) $mergetext .= fread($merge_handle,4096);
pclose($merge_handle);
}
}
@unlink($tempnew); @unlink($tempold); @unlink($temppag);
return $mergetext;
}
function MergeSimulEdits($pagename,&$page,&$new) {
global $Now, $EnablePost, $MessagesFmt, $WorkDir;
if (@!$_POST['basetime'] || !PageExists($pagename)
|| $page['time'] >= $Now
|| $_POST['basetime']>=$page['time']
|| $page['text'] == $new['text']) return;
$EnablePost = 0;
$old = array();
RestorePage($pagename,$page,$old,"diff:{$_POST['basetime']}");
$text = Merge($new['text'],$old['text'],$page['text']);
if ($text > '') { $new['text'] = $text; $ec = '$[EditConflict]'; }
else $ec = '$[EditWarning]';
XLSDV('en', array(
'EditConflict' => "The page you are
editing has been modified since you started editing it.
The modifications have been merged into the text below,
you may want to verify the results of the merge before
pressing save. Conflicts the system couldn't resolve are
bracketed by <<<<<<< and
>>>>>>>.",
'EditWarning' => "The page you are editing has been modified
since you started editing it. If you continue, your
changes will overwrite any changes that others have made."));
$MessagesFmt[] = "<p class='editconflict'>$ec
(<a target='_blank' href='\$PageUrl?action=diff'>$[View changes]</a>)
</p>\n";
}
|