summaryrefslogtreecommitdiff
path: root/inc/changelog.php
diff options
context:
space:
mode:
authormichael <michael@content-space.de>2009-01-18 16:43:45 +0100
committermichael <michael@content-space.de>2009-01-18 16:43:45 +0100
commit99c8d7f21203dc68bb191d77e01c2f8a6f0cf5a0 (patch)
tree6797f3dac32455b4ac4ba5ad8ce3ac6a1cf91bd8 /inc/changelog.php
parent5dfff2790d523c9e0e0c1c4bcb8abd70675a213a (diff)
downloadrpg-99c8d7f21203dc68bb191d77e01c2f8a6f0cf5a0.tar.gz
rpg-99c8d7f21203dc68bb191d77e01c2f8a6f0cf5a0.tar.bz2
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
Diffstat (limited to 'inc/changelog.php')
-rw-r--r--inc/changelog.php108
1 files changed, 102 insertions, 6 deletions
diff --git a/inc/changelog.php b/inc/changelog.php
index f60b487db..20e2ae340 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -96,6 +96,39 @@ function addLogEntry($date, $id, $type=DOKU_CHANGE_TYPE_EDIT, $summary='', $extr
}
/**
+ * Add's an entry to the media changelog
+ *
+ * @author Michael Hamann <michael@content-space.de>
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @author Esther Brunner <wikidesign@gmail.com>
+ * @author Ben Coburn <btcoburn@silicodon.net>
+ */
+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;
@@ -141,6 +180,62 @@ function getRecents($first,$num,$ns='',$flags=0){
}
/**
+ * 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 <michael@content-space.de>
+ * @author Ben Coburn <btcoburn@silicodon.net>
+ */
+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
*
* don't call directly
@@ -149,8 +244,7 @@ function getRecents($first,$num,$ns='',$flags=0){
* @author Andreas Gohr <andi@splitbrain.org>
* @author Ben Coburn <btcoburn@silicodon.net>
*/
-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;
}