diff options
author | michael <michael@content-space.de> | 2009-01-18 16:43:45 +0100 |
---|---|---|
committer | michael <michael@content-space.de> | 2009-01-18 16:43:45 +0100 |
commit | 99c8d7f21203dc68bb191d77e01c2f8a6f0cf5a0 (patch) | |
tree | 6797f3dac32455b4ac4ba5ad8ce3ac6a1cf91bd8 /inc | |
parent | 5dfff2790d523c9e0e0c1c4bcb8abd70675a213a (diff) | |
download | rpg-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')
-rw-r--r-- | inc/changelog.php | 108 | ||||
-rw-r--r-- | inc/common.php | 1 | ||||
-rw-r--r-- | inc/init.php | 1 | ||||
-rw-r--r-- | inc/media.php | 18 |
4 files changed, 118 insertions, 10 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; } diff --git a/inc/common.php b/inc/common.php index bb1c45baa..606f107b7 100644 --- a/inc/common.php +++ b/inc/common.php @@ -20,6 +20,7 @@ require_once(DOKU_INC.'inc/infoutils.php'); define('RECENTS_SKIP_DELETED',2); define('RECENTS_SKIP_MINORS',4); define('RECENTS_SKIP_SUBSPACES',8); +define('RECENTS_MEDIA_CHANGES',16); /** * Wrapper around htmlspecialchars() diff --git a/inc/init.php b/inc/init.php index e721cdb6c..9c4baa988 100644 --- a/inc/init.php +++ b/inc/init.php @@ -208,6 +208,7 @@ function init_paths(){ if ($conf['changelog_old']=='') { unset($conf['changelog_old']); } // hardcoded changelog because it is now a cache that lives in meta $conf['changelog'] = $conf['metadir'].'/_dokuwiki.changes'; + $conf['media_changelog'] = $conf['metadir'].'/_media.changes'; } /** diff --git a/inc/media.php b/inc/media.php index 5c7dd3843..2d3ca3556 100644 --- a/inc/media.php +++ b/inc/media.php @@ -187,6 +187,7 @@ function media_delete($id,$auth){ if ($evt->advise_before()) { $data['unl'] = @unlink($file); if($data['unl']){ + addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_DELETE); $data['del'] = io_sweepNS($id,'mediadir'); } } @@ -215,6 +216,7 @@ function media_delete($id,$auth){ * $data[1] fn: the file name of the uploaded file * $data[2] id: the future directory id of the uploaded file * $data[3] imime: the mimetype of the uploaded file + * $data[4] overwrite: if an existing file is going to be overwritten * * @triggers MEDIA_UPLOAD_FINISH * @author Andreas Gohr <andi@splitbrain.org> @@ -263,7 +265,8 @@ function media_upload($ns,$auth){ // because a temp file was created already if(preg_match('/\.('.$regex.')$/i',$fn)){ //check for overwrite - if(@file_exists($fn) && (!$_REQUEST['ow'] || $auth < AUTH_DELETE)){ + $overwrite = @file_exists($fn); + if($overwrite && (!$_REQUEST['ow'] || $auth < AUTH_DELETE)){ msg($lang['uploadexist'],0); return false; } @@ -285,6 +288,7 @@ function media_upload($ns,$auth){ $data[1] = $fn; $data[2] = $id; $data[3] = $imime; + $data[4] = $overwrite; // trigger event return trigger_event('MEDIA_UPLOAD_FINISH', $data, '_media_upload_action', true); @@ -301,8 +305,8 @@ function media_upload($ns,$auth){ */ function _media_upload_action($data) { // fixme do further sanity tests of given data? - if(is_array($data) && count($data)===4) { - return media_upload_finish($data[0], $data[1], $data[2], $data[3]); + if(is_array($data) && count($data)===5) { + return media_upload_finish($data[0], $data[1], $data[2], $data[3], $data[4]); } else { return false; //callback error } @@ -314,7 +318,7 @@ function _media_upload_action($data) { * @author Andreas Gohr <andi@splitbrain.org> * @author Michael Klier <chi@chimeric.de> */ -function media_upload_finish($fn_tmp, $fn, $id, $imime) { +function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite) { global $conf; global $lang; @@ -328,6 +332,12 @@ function media_upload_finish($fn_tmp, $fn, $id, $imime) { chmod($fn, $conf['fmode']); msg($lang['uploadsucc'],1); media_notify($id,$fn,$imime); + // add a log entry to the media changelog + if ($overwrite) { + addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_EDIT); + } else { + addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_CREATE); + } return $id; }else{ msg($lang['uploadfail'],-1); |