[Pmwiki-users] autodetect diff and patch

jdkim at socrates.Berkeley.EDU jdkim at socrates.Berkeley.EDU
Thu Jul 3 16:04:27 CDT 2003


Okay, with the following patch, pmwiki will try to detect the location of
diff and patch.  But if it fails, you can still set the variable in
local.php.  For some reason, when I run "which patch" from within a php
code, it returns /usr/bin/patch, even though the same command returns
/usr/local/bin/patch when run in shell.


*** pmwiki-old.php	Thu Jul  3 12:55:04 2003
--- pmwiki.php	Thu Jul  3 13:45:52 2003
***************
*** 33,38 ****
--- 33,40 ----
  $ScriptUrl = 'http://'.$HTTP_SERVER_VARS['HTTP_HOST'];
  $ScriptUrl .= $HTTP_SERVER_VARS['SCRIPT_NAME'];
  $ScriptDir = preg_replace("#/[^/]*\$#","",$ScriptUrl,1);
+ $SysDiff = trim(`which diff`);
+ $SysPatch = trim(`which patch`);
  $WikiImgUrl = "$ScriptDir/pmwiki-50.gif";
  $DiffKeepDays = 3650;
  $WikiDir = "wiki.d";
***************
*** 425,431 ****
  }

  function Diff($oldtext,$newtext) {
!   global $WikiDir;
    $tempold = tempnam($WikiDir,"old");
    if ($oldfp = fopen($tempold,"w")) {
      fputs($oldfp,$oldtext);
--- 427,433 ----
  }

  function Diff($oldtext,$newtext) {
!   global $WikiDir, $SysDiff;
    $tempold = tempnam($WikiDir,"old");
    if ($oldfp = fopen($tempold,"w")) {
      fputs($oldfp,$oldtext);
***************
*** 436,448 ****
      fputs($newfp,$newtext);
      fclose($newfp);
    }
!   @$diff = `/usr/bin/diff $tempold $tempnew`;
    @unlink($tempold); @unlink($tempnew);
    return $diff;
  }

  function Patch($page,$restore) {
!   global $WikiDir;
    Lock(2);
    $txtfile = tempnam($WikiDir,"txt");
    $patfile = tempnam($WikiDir,"pat");
--- 438,450 ----
      fputs($newfp,$newtext);
      fclose($newfp);
    }
!   @$diff = `$SysDiff $tempold $tempnew`;
    @unlink($tempold); @unlink($tempnew);
    return $diff;
  }

  function Patch($page,$restore) {
!   global $WikiDir, $SysPatch;
    Lock(2);
    $txtfile = tempnam($WikiDir,"txt");
    $patfile = tempnam($WikiDir,"pat");
***************
*** 458,464 ****
        fputs($patfp,$v);
        fclose($patfp);
      }
!     $diff = `/usr/bin/patch $txtfile $patfile 2>/dev/null`;
    }
    $text = implode('',file($txtfile));
    @unlink($txtfile); @unlink($patfile);
--- 460,466 ----
        fputs($patfp,$v);
        fclose($patfp);
      }
!     $diff = `$SysPatch $txtfile $patfile 2>/dev/null`;
    }
    $text = implode('',file($txtfile));
    @unlink($txtfile); @unlink($patfile);
___

John Kim






More information about the pmwiki-users mailing list