diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/changelog.php | 19 | ||||
-rw-r--r-- | inc/init.php | 2 | ||||
-rw-r--r-- | inc/media.php | 27 | ||||
-rw-r--r-- | inc/pageutils.php | 22 |
4 files changed, 63 insertions, 7 deletions
diff --git a/inc/changelog.php b/inc/changelog.php index 15cd46d77..0bbb77540 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -138,6 +138,7 @@ function addMediaLogEntry($date, $id, $type=DOKU_CHANGE_TYPE_EDIT, $summary='', // add changelog lines $logline = implode("\t", $logline)."\n"; io_saveFile($conf['media_changelog'],$logline,true); //global media changelog cache + io_saveFile(mediaMetaFN($id,'.changes'),$logline,true); //media file's changelog } /** @@ -301,7 +302,7 @@ function _handleRecent($line,$ns,$flags,&$seen){ * * @author Ben Coburn <btcoburn@silicodon.net> */ -function getRevisionInfo($id, $rev, $chunk_size=8192) { +function getRevisionInfo($id, $rev, $chunk_size=8192, $media=false) { global $cache_revinfo; $cache =& $cache_revinfo; if (!isset($cache[$id])) { $cache[$id] = array(); } @@ -312,7 +313,11 @@ function getRevisionInfo($id, $rev, $chunk_size=8192) { return $cache[$id][$rev]; } - $file = metaFN($id, '.changes'); + if ($media) { + $file = mediaMetaFN($id, '.changes'); + } else { + $file = metaFN($id, '.changes'); + } if (!@file_exists($file)) { return false; } if (filesize($file)<$chunk_size || $chunk_size==0) { // read whole file @@ -398,7 +403,7 @@ function getRevisionInfo($id, $rev, $chunk_size=8192) { * * @author Ben Coburn <btcoburn@silicodon.net> */ -function getRevisions($id, $first, $num, $chunk_size=8192) { +function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) { global $cache_revinfo; $cache =& $cache_revinfo; if (!isset($cache[$id])) { $cache[$id] = array(); } @@ -406,11 +411,15 @@ function getRevisions($id, $first, $num, $chunk_size=8192) { $revs = array(); $lines = array(); $count = 0; - $file = metaFN($id, '.changes'); + if ($media) { + $file = mediaMetaFN($id, '.changes'); + } else { + $file = metaFN($id, '.changes'); + } $num = max($num, 0); $chunk_size = max($chunk_size, 0); if ($first<0) { $first = 0; } - else if (@file_exists(wikiFN($id))) { + else if (!$media && @file_exists(wikiFN($id)) || $media && @file_exists(mediaFN($id))) { // skip current revision if the page exists $first = max($first+1, 0); } diff --git a/inc/init.php b/inc/init.php index 819d92bdc..e82e26efd 100644 --- a/inc/init.php +++ b/inc/init.php @@ -230,7 +230,9 @@ function init_paths(){ $paths = array('datadir' => 'pages', 'olddir' => 'attic', 'mediadir' => 'media', + 'mediaolddir' => 'media_attic', 'metadir' => 'meta', + 'mediametadir' => 'media_meta', 'cachedir' => 'cache', 'indexdir' => 'index', 'lockdir' => 'locks', diff --git a/inc/media.php b/inc/media.php index 3c9340d51..6be66dedc 100644 --- a/inc/media.php +++ b/inc/media.php @@ -346,6 +346,13 @@ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'mov global $conf; global $lang; + $old = @filemtime($fn); + // + if(!@file_exists(mediaFN($id, $old)) && @file_exists($fn)) { + // add old revision to the attic if missing + saveOldMediaRevision($id); + } + // prepare directory io_createNamespace($id, 'media'); @@ -369,6 +376,26 @@ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'mov } /** + * moves the current version to the media_attic and returns its + * revision date + */ +function saveOldMediaRevision($id, $move = 'copy'){ + global $conf; + $oldf = mediaFN($id); + if(!@file_exists($oldf)) return ''; + $date = filemtime($oldf); + $newf = mediaFN($id,$date); + io_makeFileDir($newf); + if($move($oldf, $newf)) { + // Set the correct permission here. + // Always chmod media because they may be saved with different permissions than expected from the php umask. + // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.) + chmod($newf, $conf['fmode']); + } + return $date; +} + +/** * This function checks if the uploaded content is really what the * mimetype says it is. We also do spam checking for text types here. * diff --git a/inc/pageutils.php b/inc/pageutils.php index c9bf60135..51567191e 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -308,6 +308,19 @@ function metaFN($id,$ext){ } /** + * returns the full path to the media's meta file specified by ID and extension + * + * The filename is URL encoded to protect Unicode chars + */ +function mediaMetaFN($id,$ext){ + global $conf; + $id = cleanID($id); + $id = str_replace(':','/',$id); + $fn = $conf['mediametadir'].'/'.utf8_encodeFN($id).$ext; + return $fn; +} + +/** * returns an array of full paths to all metafiles of a given ID * * @author Esther Brunner <esther@kaffeehaus.ch> @@ -327,11 +340,16 @@ function metaFiles($id){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function mediaFN($id){ +function mediaFN($id, $rev=''){ global $conf; $id = cleanID($id); $id = str_replace(':','/',$id); - $fn = $conf['mediadir'].'/'.utf8_encodeFN($id); + if(empty($rev)){ + $fn = $conf['mediadir'].'/'.utf8_encodeFN($id); + }else{ + list($name, $ext) = explode(".", $id); + $fn = $conf['mediaolddir'].'/'.utf8_encodeFN($name).'.'.$rev.'.'.utf8_encodeFN($ext); + } return $fn; } |