blob: 75cfb86133555b3c5f73afabeb89f62d191de56c [file] [log] [blame]
<?php if (!defined('PmWiki')) exit();
/* Copyright 2004 Patrick R. Michaud (
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.
$HTMLStylesFmt[] = ".editconflict { color:green; font-style:italic;
margin-top:1.33em; margin-bottom:1.33em; }\n";
function Merge($newtext,$oldtext,$pagetext) {
global $WorkDir,$SysMergeCmd;
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 = '';
$merge_handle = popen("$SysMergeCmd $tempnew $tempold $temppag",'r');
if ($merge_handle) {
while (!feof($merge_handle)) $mergetext .= fread($merge_handle,4096);
@unlink($tempnew); @unlink($tempold); @unlink($temppag);
return $mergetext;
function MergeSimulEdits($pagename,&$page,&$new) {
global $EditMessageFmt,$WorkDir,$SysMergeCmd;
SDV($SysMergeCmd,"/usr/bin/diff3 -L '' -L '' -L '' -m -E");
if (@!$_POST['basetime'] || !PageExists($pagename) ||
$_POST['basetime']>=$page['time']) return;
$EditMessageFmt .= "<p class='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 &lt;&lt;&lt;&lt;&lt;&lt;&lt; and
&gt;&gt;&gt;&gt;&gt;&gt;&gt;. (<a target='_blank'
href='\$PageUrl?action=diff'>View changes</a>)</p>\n";
$old = array();
$new['text'] = Merge($new['text'],$old['text'],$page['text']);