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