summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Arzamastseva <pshns@ukr.net>2011-06-30 19:44:31 +0300
committerKate Arzamastseva <pshns@ukr.net>2011-06-30 19:44:31 +0300
commit9c1bd4bc9aa4b9ac3b9981543a14508091cd639a (patch)
tree08090fc59d03aee0c33422cee79be9b3dc58cf96
parent98f03b57e3bb6185cbbb815a71d254e28df79912 (diff)
downloadrpg-9c1bd4bc9aa4b9ac3b9981543a14508091cd639a.tar.gz
rpg-9c1bd4bc9aa4b9ac3b9981543a14508091cd639a.tar.bz2
restoring old media revisions
-rw-r--r--inc/lang/en/lang.php1
-rw-r--r--inc/media.php47
-rw-r--r--inc/template.php10
-rw-r--r--lib/exe/mediamanager.php6
4 files changed, 55 insertions, 9 deletions
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index abe59d0aa..7a2050fac 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -341,5 +341,6 @@ $lang['media_meta_edited']= 'metadata edited';
$lang['media_perm_read'] = 'Sorry, you don\'t have enough rights to read files.';
$lang['media_perm_upload']= 'Sorry, you don\'t have enough rights to upload files.';
$lang['media_update'] = 'Upload new version';
+$lang['media_restore'] = 'Restore this version';
//Setup VIM: ex: et ts=2 :
diff --git a/inc/media.php b/inc/media.php
index cba89b995..34bdec42b 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -367,6 +367,7 @@ function _media_upload_action($data) {
function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'move_uploaded_file') {
global $conf;
global $lang;
+ global $REV;
$old = @filemtime($fn);
if(!@file_exists(mediaFN($id, $old)) && @file_exists($fn)) {
@@ -378,6 +379,7 @@ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'mov
io_createNamespace($id, 'media');
if($move($fn_tmp, $fn)) {
+ clearstatcache(true,$fn);
$new = @filemtime($fn);
// Set the correct permission here.
// Always chmod media because they may be saved with different permissions than expected from the php umask.
@@ -386,7 +388,9 @@ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'mov
msg($lang['uploadsucc'],1);
media_notify($id,$fn,$imime);
// add a log entry to the media changelog
- if ($overwrite) {
+ if ($REV){
+ addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_REVERT, '', $REV);
+ } elseif ($overwrite) {
addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_EDIT);
} else {
addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_CREATE, $lang['created']);
@@ -707,7 +711,7 @@ function media_tab_search($ns,$auth=null) {
*
* @author Kate Arzamastseva <pshns@ukr.net>
*/
-function media_tab_view($image, $ns, $auth=null) {
+function media_tab_view($image, $ns, $auth=null, $rev=false) {
global $lang, $conf;
if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*");
@@ -717,7 +721,6 @@ function media_tab_view($image, $ns, $auth=null) {
echo '</div>';
echo '<div class="scroll-container">';
- $rev = (int) $_REQUEST['rev'];
media_preview($image, $auth, $rev);
media_details($image, $auth, $rev);
echo '</div>';
@@ -789,7 +792,7 @@ function media_preview($image, $auth, $rev=false) {
echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL;
return '';
}
- $info = getimagesize(mediaFN($image));
+ $info = getimagesize(mediaFN($image, $rev));
$w = (int) $info[0];
$more = '';
@@ -810,11 +813,18 @@ function media_preview($image, $auth, $rev=false) {
$form->addElement(form_makeButton('submit','',$lang['btn_delete']));
$form->printForm();
- $form = new Doku_Form(array('action'=>media_managerURL()));
+ $form = new Doku_Form(array('action'=>media_managerURL(array('image' => $image))));
$form->addHidden('mediado','update');
$form->addElement(form_makeButton('submit','',$lang['media_update']));
$form->printForm();
}
+ if($auth >= AUTH_DELETE && $rev){
+ $form = new Doku_Form(array('action'=>media_managerURL(array('image' => $image))));
+ $form->addHidden('mediado','restore');
+ $form->addHidden('rev',$rev);
+ $form->addElement(form_makeButton('submit','',$lang['media_restore']));
+ $form->printForm();
+ }
echo '</div>';
}
@@ -927,6 +937,33 @@ function media_diff($image, $ns, $auth) {
}
/**
+ * Restores an old revision of a media file
+ *
+ * @param string $image
+ * @param int $rev
+ * @param int $auth
+ * @return string - file's id
+ * @author Kate Arzamastseva <pshns@ukr.net>
+ */
+function media_restore($image, $rev, $auth){
+ if ($auth < AUTH_DELETE) return false;
+ if (!$image || !file_exists(mediaFN($image))) return false;
+ if (!$rev || !file_exists(mediaFN($image, $rev))) return false;
+ list($iext,$imime,$dl) = mimetype($image);
+ $res = media_upload_finish(mediaFN($image, $rev),
+ mediaFN($image),
+ $image,
+ $imime,
+ true,
+ 'copy');
+ if (is_array($res)) {
+ msg($res[0], $res[1]);
+ return false;
+ }
+ return $res;
+}
+
+/**
* List all files found by the search request
*
* @author Tobias Sarnowski <sarnowski@cosmocode.de>
diff --git a/inc/template.php b/inc/template.php
index e3d716c25..cb5004891 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -1159,11 +1159,12 @@ function tpl_fileList(){
*
* @author Kate Arzamastseva <pshns@ukr.net>
*/
-function tpl_fileDetails($image){
+function tpl_fileDetails($image, $rev){
global $AUTH;
global $NS;
if (!$image || !file_exists(mediaFN($image))) return '';
+ if ($rev && !file_exists(mediaFN($image, $rev))) return '';
if (isset($NS) && getNS($image) != $NS) return '';
$opened_tab = $_REQUEST['tab_details'];
@@ -1171,7 +1172,7 @@ function tpl_fileDetails($image){
if ($_REQUEST['edit']) $opened_tab = 'edit';
media_tabs_details($image, $opened_tab);
- if ($opened_tab == 'view') media_tab_view($image, $NS, $AUTH);
+ if ($opened_tab == 'view') media_tab_view($image, $NS, $AUTH, $rev);
if ($opened_tab == 'edit') media_tab_edit($image, $NS, $AUTH);
if ($opened_tab == 'history') media_tab_history($image,$NS,$AUTH);
}
@@ -1419,13 +1420,14 @@ function tpl_getFavicon($abs=false) {
*/
function tpl_media() {
//
- global $DEL, $NS, $IMG, $AUTH, $JUMPTO, $lang, $fullscreen;
+ global $DEL, $NS, $IMG, $AUTH, $JUMPTO, $REV, $lang, $fullscreen;
$fullscreen = true;
require_once(DOKU_INC.'lib/exe/mediamanager.php');
if ($_REQUEST['image']) $image = cleanID($_REQUEST['image']);
if (isset($IMG)) $image = $IMG;
if (isset($JUMPTO)) $image = $JUMPTO;
+ if (isset($REV) && !$JUMPTO) $rev = $REV;
echo '<div class="mediamanager" id="id-mediamanager">';
echo '<div class="mediamanager-slider" id="id-mediamanager-layout">';
@@ -1446,7 +1448,7 @@ function tpl_media() {
tpl_fileList();
echo '</div>';
echo '<div id="id-mediamanager-layout-detail" class="layout" style="width: 30%;">';
- tpl_fileDetails($image);
+ tpl_fileDetails($image, $rev);
echo '</div>';
echo '<div class="clearer"></div>';
echo '</div>';
diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php
index 24dd5f911..46257a9a7 100644
--- a/lib/exe/mediamanager.php
+++ b/lib/exe/mediamanager.php
@@ -84,6 +84,12 @@
$JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
}
+ if ($_REQUEST['rev']) $REV = (int) $_REQUEST['rev'];
+
+ if($_REQUEST['mediado'] == 'restore'){
+ $JUMPTO = media_restore($_REQUEST['image'], $REV, $AUTH);
+ }
+
// handle deletion
if($DEL) {
$res = 0;