Simple Groupware PHP Cross Reference Groupware Applications

Source: /src/lib/pmwiki/scripts/simuledit.php - 67 lines - 3037 bytes - Summary - Text - Print

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

title

Description

title

Description

title

Description

title

title

Body