From 99c8d7f21203dc68bb191d77e01c2f8a6f0cf5a0 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 18 Jan 2009 16:43:45 +0100 Subject: Media changelog added There is a new media changelog now, with the flag RECENTS_MEDIA_CHANGES media changes can be requested from the getRecents()-function or the new getRecentsSince()-function, that returns all changes since a given timestamp and optionally before a given timestamp. The media upload and the XML-RPC-server have been changed to use these functions. Additionally, the event MEDIA_UPLOAD_FINISH has been extended, it has a new $data-attribute (the 5th), that contains a boolean if the file does already exist and will be overwritten. darcs-hash:20090118154345-074e0-5d9a90d269e86d8c6a156ecce5cf63115c827433.gz --- inc/changelog.php | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 6 deletions(-) (limited to 'inc/changelog.php') diff --git a/inc/changelog.php b/inc/changelog.php index f60b487db..20e2ae340 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -95,6 +95,39 @@ function addLogEntry($date, $id, $type=DOKU_CHANGE_TYPE_EDIT, $summary='', $extr io_saveFile($conf['changelog'],$logline,true); //global changelog cache } +/** + * Add's an entry to the media changelog + * + * @author Michael Hamann + * @author Andreas Gohr + * @author Esther Brunner + * @author Ben Coburn + */ +function addMediaLogEntry($date, $id, $type=DOKU_CHANGE_TYPE_EDIT, $summary='', $extra='', $flags=null){ + global $conf, $INFO; + + $id = cleanid($id); + + if(!$date) $date = time(); //use current time if none supplied + $remote = $_SERVER['REMOTE_ADDR']; + $user = $_SERVER['REMOTE_USER']; + + $strip = array("\t", "\n"); + $logline = array( + 'date' => $date, + 'ip' => $remote, + 'type' => str_replace($strip, '', $type), + 'id' => $id, + 'user' => $user, + 'sum' => str_replace($strip, '', $summary), + 'extra' => str_replace($strip, '', $extra) + ); + + // add changelog lines + $logline = implode("\t", $logline)."\n"; + io_saveFile($conf['media_changelog'],$logline,true); //global media changelog cache +} + /** * returns an array of recently changed files using the * changelog @@ -105,6 +138,7 @@ function addLogEntry($date, $id, $type=DOKU_CHANGE_TYPE_EDIT, $summary='', $extr * RECENTS_SKIP_DELETED - don't include deleted pages * RECENTS_SKIP_MINORS - don't include minor changes * RECENTS_SKIP_SUBSPACES - don't include subspaces + * RECENTS_MEDIA_CHANGES - return media changes instead of page changes * * @param int $first number of first entry returned (for paginating * @param int $num return $num entries @@ -122,12 +156,17 @@ function getRecents($first,$num,$ns='',$flags=0){ return $recent; // read all recent changes. (kept short) - $lines = @file($conf['changelog']); + if ($flags & RECENTS_MEDIA_CHANGES) { + $lines = @file($conf['media_changelog']); + } else { + $lines = @file($conf['changelog']); + } // handle lines + $seen = array(); // caches seen lines, _handleRecent() skips them for($i = count($lines)-1; $i >= 0; $i--){ - $rec = _handleRecent($lines[$i], $ns, $flags); + $rec = _handleRecent($lines[$i], $ns, $flags, $seen); if($rec !== false) { if(--$first >= 0) continue; // skip first entries $recent[] = $rec; @@ -140,6 +179,62 @@ function getRecents($first,$num,$ns='',$flags=0){ return $recent; } +/** + * returns an array of files changed since a given time using the + * changelog + * + * The following constants can be used to control which changes are + * included. Add them together as needed. + * + * RECENTS_SKIP_DELETED - don't include deleted pages + * RECENTS_SKIP_MINORS - don't include minor changes + * RECENTS_SKIP_SUBSPACES - don't include subspaces + * RECENTS_MEDIA_CHANGES - return media changes instead of page changes + * + * @param int $from date of the oldest entry to return + * @param int $to date of the newest entry to return (for pagination, optional) + * @param string $ns restrict to given namespace (optional) + * @param bool $flags see above (optional) + * + * @author Michael Hamann + * @author Ben Coburn + */ +function getRecentsSince($from,$to=null,$ns='',$flags=0){ + global $conf; + $recent = array(); + + if($to && $to < $from) + return $recent; + + // read all recent changes. (kept short) + if ($flags & RECENTS_MEDIA_CHANGES) { + $lines = @file($conf['media_changelog']); + } else { + $lines = @file($conf['changelog']); + } + + // we start searching at the end of the list + $lines = array_reverse($lines); + + // handle lines + $seen = array(); // caches seen lines, _handleRecent() skips them + + foreach($lines as $line){ + $rec = _handleRecent($line, $ns, $flags, $seen); + if($rec !== false) { + if ($rec['date'] >= $from) { + if (!$to || $rec['date'] <= $to) { + $recent[] = $rec; + } + } else { + break; + } + } + } + + return array_reverse($recent); +} + /** * Internal function used by getRecents * @@ -149,8 +244,7 @@ function getRecents($first,$num,$ns='',$flags=0){ * @author Andreas Gohr * @author Ben Coburn */ -function _handleRecent($line,$ns,$flags){ - static $seen = array(); //caches seen pages and skip them +function _handleRecent($line,$ns,$flags,&$seen){ if(empty($line)) return false; //skip empty lines // split the line into parts @@ -176,10 +270,12 @@ function _handleRecent($line,$ns,$flags){ if (($flags & RECENTS_SKIP_SUBSPACES) && (getNS($recent['id']) != $ns)) return false; // check ACL - if (auth_quickaclcheck($recent['id']) < AUTH_READ) return false; + $recent['perms'] = auth_quickaclcheck($recent['id']); + if ($recent['perms'] < AUTH_READ) return false; // check existance - if((!@file_exists(wikiFN($recent['id']))) && ($flags & RECENTS_SKIP_DELETED)) return false; + $fn = (($flags & RECENTS_MEDIA_CHANGES) ? mediaFN($recent['id']) : wikiFN($recent['id'])); + if((!@file_exists($fn)) && ($flags & RECENTS_SKIP_DELETED)) return false; return $recent; } -- cgit v1.2.3