summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Arzamastseva <pshns@ukr.net>2011-06-04 19:12:06 +0300
committerKate Arzamastseva <pshns@ukr.net>2011-06-04 19:12:06 +0300
commitcbe26ad6152c998c9a3290b0d321030c61dc7f1b (patch)
tree67a4eef1e67ae14fb789c87d9701e1a90351d6a5
parent8d56551e75f273694893a29a06d8164d3d60ae17 (diff)
downloadrpg-cbe26ad6152c998c9a3290b0d321030c61dc7f1b.tar.gz
rpg-cbe26ad6152c998c9a3290b0d321030c61dc7f1b.tar.bz2
media version saving fix
-rw-r--r--data/media_attic/_dummy0
-rw-r--r--data/media_meta/_dummy0
-rw-r--r--inc/media.php20
-rw-r--r--inc/pageutils.php10
4 files changed, 18 insertions, 12 deletions
diff --git a/data/media_attic/_dummy b/data/media_attic/_dummy
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/data/media_attic/_dummy
diff --git a/data/media_meta/_dummy b/data/media_meta/_dummy
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/data/media_meta/_dummy
diff --git a/inc/media.php b/inc/media.php
index ac65603f1..be55f8044 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -341,16 +341,18 @@ function _media_upload_action($data) {
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Michael Klier <chi@chimeric.de>
+ * @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'move_uploaded_file') {
global $conf;
global $lang;
$old = @filemtime($fn);
- //
- if(!@file_exists(mediaFN($id, $old)) && @file_exists($fn)) {
+ $oldRev = getRevisions($id, -1, 1, 1024, true); // from changelog
+ $oldRev = (int)(empty($oldRev)?0:$oldRev[0]);
+ if(!@file_exists(mediaFN($id, $old)) && @file_exists($fn) && $old>=$oldRev) {
// add old revision to the attic if missing
- saveOldMediaRevision($id);
+ media_saveOldRevision($id);
}
// prepare directory
@@ -376,17 +378,21 @@ 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
+ * Moves the current version of media file to the media_attic
+ * directory
+ *
+ * @author Kate Arzamastseva <pshns@ukr.net>
+ * @param string $id
+ * @return int - revision date
*/
-function saveOldMediaRevision($id, $move = 'copy'){
+function media_saveOldRevision($id){
global $conf;
$oldf = mediaFN($id);
if(!@file_exists($oldf)) return '';
$date = filemtime($oldf);
$newf = mediaFN($id,$date);
io_makeFileDir($newf);
- if($move($oldf, $newf)) {
+ if(copy($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.)
diff --git a/inc/pageutils.php b/inc/pageutils.php
index 51567191e..37b15a498 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -295,8 +295,6 @@ function wikiLockFN($id) {
/**
* returns the full path to the meta file specified by ID and extension
*
- * The filename is URL encoded to protect Unicode chars
- *
* @author Steven Danz <steven-danz@kc.rr.com>
*/
function metaFN($id,$ext){
@@ -310,7 +308,7 @@ 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
+ * @author Kate Arzamastseva <pshns@ukr.net>
*/
function mediaMetaFN($id,$ext){
global $conf;
@@ -339,6 +337,7 @@ function metaFiles($id){
* The filename is URL encoded to protect Unicode chars
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @author Kate Arzamastseva <pshns@ukr.net>
*/
function mediaFN($id, $rev=''){
global $conf;
@@ -347,8 +346,9 @@ function mediaFN($id, $rev=''){
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);
+ $ext = mimetype($id);
+ $name = substr($id, 0, strrpos($id, '.'));
+ $fn = $conf['mediaolddir'].'/'.utf8_encodeFN($name).'.'.(int)$rev.'.'.utf8_encodeFN($ext[0]);
}
return $fn;
}