From 468441561df674f9df04e53a21d29dd4f1f0c017 Mon Sep 17 00:00:00 2001 From: Ben Coburn <btcoburn@silicodon.net> Date: Mon, 23 Oct 2006 07:21:33 +0200 Subject: [PATCH] synchronize changelog, attic, and external edits The changelog list and the attic now are kept in sync. This allows a changelog entry to be automatically constructed for a page that was manually edited from outside dokuwiki. darcs-hash:20061023052133-05dcb-11b8dbaee1da07fb1875bbe530e88d94871ed65d.gz --- inc/changelog.php | 34 ---------------------------------- inc/common.php | 22 ++++++++++++++++++++-- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/inc/changelog.php b/inc/changelog.php index 570c48740..85de8e2aa 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -271,11 +271,7 @@ function getRevisionInfo($id, $rev, $chunk_size=8192) { * backwards in chunks untill the requested number of changelog * lines are recieved. * - * Because there may exist revisions not listed in the changelog - * the found revisions are merged with the ones found in the attic - * * @author Ben Coburn <btcoburn@silicodon.net> - * @see getRevisionsFromAttic() */ function getRevisions($id, $first, $num, $chunk_size=8192) { global $cache_revinfo; @@ -358,37 +354,7 @@ function getRevisions($id, $first, $num, $chunk_size=8192) { } } - // merge with attic file info - $revs = array_merge($revs,getRevisionsFromAttic($id,false)); - $revs = array_unique($revs); - rsort($revs); - return $revs; } -/** - * Return a list of available and existing page revisons from the attic - * - * @author Andreas Gohr <andi@splitbrain.org> - * @see getRevisions() - */ -function getRevisionsFromAttic($id,$sorted=true){ - $revd = dirname(wikiFN($id,'foo')); - $revs = array(); - $clid = cleanID($id); - if(strrpos($clid,':')) $clid = substr($clid,strrpos($clid,':')+1); //remove path - $clid = utf8_encodeFN($clid); - - if (is_dir($revd) && $dh = opendir($revd)) { - while (($file = readdir($dh)) !== false) { - if (is_dir($revd.'/'.$file)) continue; - if (preg_match('/^'.$clid.'\.(\d+)\.txt(\.gz)?$/',$file,$match)){ - $revs[]=$match[1]; - } - } - closedir($dh); - } - if($sorted) rsort($revs); - return $revs; -} diff --git a/inc/common.php b/inc/common.php index a477f26a1..5edd417d5 100644 --- a/inc/common.php +++ b/inc/common.php @@ -691,15 +691,32 @@ function saveWikiText($id,$text,$summary,$minor=false){ } $file = wikiFN($id); - $old = saveOldRevision($id); + $old = @filemtime($file); $wasRemoved = empty($text); $wasCreated = !@file_exists($file); $wasReverted = ($REV==true); $newRev = false; + if(!@file_exists(wikiFN($id, $old)) && @file_exists($file)) { + // add old revision to the attic if missing + saveOldRevision($id); + // add a changelog entry if this edit came from outside dokuwiki + $oldRev = getRevisions($id, -1, 1, 1024); + $oldRev = (int)(empty($oldRev)?0:$oldRev[0]); + if ($oldRev!==$old) { + addLogEntry($old, $id); + // send notify mails + notify($id,'admin',$oldRev,'',false); + notify($id,'subscribers',$oldRev,'',false); + // remove soon to be stale instructions + $cache = new cache_instructions($id, $file); + $cache->removeCache(); + } + } if ($wasRemoved){ // pre-save deleted revision @touch($file); + clearstatcache(); $newRev = saveOldRevision($id); // remove empty file @unlink($file); @@ -719,7 +736,8 @@ function saveWikiText($id,$text,$summary,$minor=false){ }else{ // save file (namespace dir is created in io_writeWikiPage) io_writeWikiPage($file, $text, $id); - $newRev = @filemtime($file); + // pre-save the revision, to keep the attic in sync + $newRev = saveOldRevision($id); $del = false; } -- GitLab