From e5d185e17e613b7a9737fc76310f1e78008f71ec Mon Sep 17 00:00:00 2001 From: Kate Arzamastseva Date: Tue, 2 Aug 2011 20:25:17 +0300 Subject: issue #9 config option to disable media revisions, auth --- conf/dokuwiki.php | 1 + feed.php | 5 +++-- inc/html.php | 31 +++++++++++++++++-------------- inc/media.php | 33 ++++++++++++++++++++++++--------- inc/template.php | 21 +++++++++++++++------ lib/exe/mediamanager.php | 4 ++-- 6 files changed, 62 insertions(+), 33 deletions(-) diff --git a/conf/dokuwiki.php b/conf/dokuwiki.php index 5e185e9c2..298c8e572 100644 --- a/conf/dokuwiki.php +++ b/conf/dokuwiki.php @@ -20,6 +20,7 @@ $conf['basedir'] = ''; //absolute dir from serveroot - blank $conf['baseurl'] = ''; //URL to server including protocol - blank for autodetect $conf['savedir'] = './data'; //where to store all the files $conf['allowdebug'] = 0; //allow debug output, enable if needed 0|1 +$conf['mediarevisions'] = 1; //enable/disable media revisions /* Display Options */ diff --git a/feed.php b/feed.php index 1b3641cff..298777eb9 100644 --- a/feed.php +++ b/feed.php @@ -410,10 +410,11 @@ function rss_buildItems(&$rss,&$data,$opt){ * @author Andreas Gohr */ function rssRecentChanges($opt){ + global $conf; $flags = RECENTS_SKIP_DELETED; if(!$opt['show_minor']) $flags += RECENTS_SKIP_MINORS; - if($opt['content_type'] == 'media') $flags += RECENTS_MEDIA_CHANGES; - if($opt['content_type'] == 'both') $flags += RECENTS_MEDIA_PAGES_MIXED; + if($opt['content_type'] == 'media' && $conf['mediarevisions']) $flags += RECENTS_MEDIA_CHANGES; + if($opt['content_type'] == 'both' && $conf['mediarevisions']) $flags += RECENTS_MEDIA_PAGES_MIXED; $recents = getRecents(0,$opt['items'],$opt['namespace'],$flags); return $recents; diff --git a/inc/html.php b/inc/html.php index a225f8503..2b4e2835e 100644 --- a/inc/html.php +++ b/inc/html.php @@ -626,11 +626,12 @@ function html_recent($first=0, $show_changes='both'){ * decide if this is the last page or is there another one. * This is the cheapest solution to get this information. */ - if ($show_changes == 'mediafiles') { + $flags = 0; + if ($show_changes == 'mediafiles' && $conf['mediarevisions']) { $flags = RECENTS_MEDIA_CHANGES; } elseif ($show_changes == 'pages') { $flags = 0; - } else { + } elseif ($conf['mediarevisions']) { $show_changes = 'both'; $flags = RECENTS_MEDIA_PAGES_MIXED; } @@ -656,18 +657,20 @@ function html_recent($first=0, $show_changes='both'){ $form->addHidden('do', 'recent'); $form->addHidden('id', $ID); - $form->addElement(form_makeListboxField( - 'show_changes', - array( - 'pages' => $lang['pages_changes'], - 'mediafiles' => $lang['media_changes'], - 'both' => $lang['both_changes']), - $show_changes, - $lang['changes_type'], - '','', - array('class'=>'quickselect'))); - - $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply'])); + if ($conf['mediarevisions']) { + $form->addElement(form_makeListboxField( + 'show_changes', + array( + 'pages' => $lang['pages_changes'], + 'mediafiles' => $lang['media_changes'], + 'both' => $lang['both_changes']), + $show_changes, + $lang['changes_type'], + '','', + array('class'=>'quickselect'))); + + $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply'])); + } $form->addElement(form_makeOpenTag('ul')); diff --git a/inc/media.php b/inc/media.php index c57afedfb..8c23dc115 100644 --- a/inc/media.php +++ b/inc/media.php @@ -331,7 +331,8 @@ function media_save($file, $id, $ow, $auth, $move) { //check for overwrite $overwrite = @file_exists($fn); - if($overwrite && (!$ow || $auth < AUTH_DELETE)) { + $auth_ow = (($conf['mediarevisions']) ? AUTH_UPLOAD : AUTH_DELETE); + if($overwrite && (!$ow || $auth < $auth_ow)) { return array($lang['uploadexist'], 0); } // check for valid content @@ -426,6 +427,8 @@ function media_saveOldRevision($id){ $oldf = mediaFN($id); if(!@file_exists($oldf)) return ''; $date = filemtime($oldf); + if (!$conf['mediarevisions']) return $date; + $newf = mediaFN($id,$date); io_makeFileDir($newf); if(copy($oldf, $newf)) { @@ -503,7 +506,7 @@ function media_notify($id,$file,$mime,$old_rev=false){ $text = str_replace('@MIME@',$mime,$text); $text = str_replace('@MEDIA@',ml($id,'',true,'&',true),$text); $text = str_replace('@SIZE@',filesize_h(filesize($file)),$text); - if ($old_rev) { + if ($old_rev && $conf['mediarevisions']) { $text = str_replace('@OLD@', ml($id, "rev=$old_rev", true, '&', true), $text); } else { $text = str_replace('@OLD@', '', $text); @@ -593,7 +596,7 @@ function media_tabs_files($selected=false){ * @param string $selected - opened tab */ function media_tabs_details($image, $selected=false){ - global $lang; + global $lang, $conf; echo '
'; @@ -603,7 +606,9 @@ function media_tabs_details($image, $selected=false){ if ($mime == 'image/jpeg') { media_tab(media_managerURL(array('tab_details' => 'edit')), 'edit', $lang['media_edittab'], $selected); } - media_tab(media_managerURL(array('tab_details' => 'history')), 'history', $lang['media_historytab'], $selected); + if ($conf['mediarevisions']) { + media_tab(media_managerURL(array('tab_details' => 'history')), 'history', $lang['media_historytab'], $selected); + } echo '
'; echo '
'; @@ -849,7 +854,7 @@ function media_preview($image, $auth, $rev=false, $meta=false) { * @author Kate Arzamastseva */ function media_preview_buttons($image, $auth, $rev=false) { - global $lang; + global $lang, $conf; echo '
'; @@ -875,6 +880,11 @@ function media_preview_buttons($image, $auth, $rev=false) { $form->addElement(form_makeButton('submit','',$lang['btn_delete'])); $form->printForm(); + } + + $auth_ow = (($conf['mediarevisions']) ? AUTH_UPLOAD : AUTH_DELETE); + if($auth >= $auth_ow && !$rev){ + // upload new version button $form = new Doku_Form(array('id' => 'mediamanager__btn_update', 'action'=>media_managerURL(array('image' => $image, 'mediado' => 'update'), '&'))); @@ -882,7 +892,7 @@ function media_preview_buttons($image, $auth, $rev=false) { $form->printForm(); } - if($auth >= AUTH_DELETE && $rev){ + if($auth >= AUTH_DELETE && $rev && $conf['mediarevisions']){ // restore button $form = new Doku_Form(array('id' => 'mediamanager__btn_restore', @@ -1001,7 +1011,7 @@ function media_diff($image, $ns, $auth) { global $lang; global $conf; - if ($auth < AUTH_READ || !$image) return ''; + if ($auth < AUTH_READ || !$image || !$conf['mediarevisions']) return ''; $rev1 = (int) $_REQUEST['rev']; @@ -1035,7 +1045,11 @@ function media_diff($image, $ns, $auth) { }else{ // no revision was given, compare previous to current $r_rev = ''; $revs = getRevisions($image, 0, 1, 8192, true); - $l_rev = $revs[0]; + if (file_exists(mediaFN($image, $revs[0]))) { + $l_rev = $revs[0]; + } else { + $l_rev = ''; + } } // prepare event data @@ -1190,7 +1204,8 @@ function media_image_diff($image, $l_rev, $r_rev, $meta, $type) { * @author Kate Arzamastseva */ function media_restore($image, $rev, $auth){ - if ($auth < AUTH_DELETE) return false; + global $conf; + if ($auth < AUTH_DELETE || !$conf['mediarevisions']) 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); diff --git a/inc/template.php b/inc/template.php index a48a099e0..e6673c3f3 100644 --- a/inc/template.php +++ b/inc/template.php @@ -1140,7 +1140,7 @@ function tpl_fileList(){ global $JUMPTO; $opened_tab = $_REQUEST['tab_files']; - if (!$opened_tab) $opened_tab = 'files'; + if (!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; if ($_REQUEST['mediado'] == 'update') $opened_tab = 'upload'; media_tabs_files($opened_tab); @@ -1172,8 +1172,7 @@ function tpl_fileList(){ * @author Kate Arzamastseva */ function tpl_fileDetails($image, $rev){ - global $AUTH; - global $NS; + global $AUTH, $NS, $conf; if (!$image || !file_exists(mediaFN($image))) return ''; if ($rev && !file_exists(mediaFN($image, $rev))) $rev = false; @@ -1181,7 +1180,17 @@ function tpl_fileDetails($image, $rev){ $do = $_REQUEST['mediado']; $opened_tab = $_REQUEST['tab_details']; - if (!$opened_tab) $opened_tab = 'view'; + + $tab_array = array('view'); + list($ext, $mime) = mimetype($image); + if ($mime == 'image/jpeg') { + $tab_array[] = 'edit'; + } + if ($conf['mediarevisions']) { + $tab_array[] = 'history'; + } + + if (!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; if ($_REQUEST['edit']) $opened_tab = 'edit'; if ($do == 'restore') $opened_tab = 'view'; @@ -1197,7 +1206,7 @@ function tpl_fileDetails($image, $rev){ media_tab_edit($image, $NS, $AUTH); echo '
'; - } elseif ($opened_tab == 'history') { + } elseif ($opened_tab == 'history' && $conf['mediarevisions']) { echo '
'; media_tab_history($image,$NS,$AUTH); echo '
'; @@ -1446,7 +1455,7 @@ function tpl_getFavicon($abs=false) { */ function tpl_media() { // - global $DEL, $NS, $IMG, $AUTH, $JUMPTO, $REV, $lang, $fullscreen; + global $DEL, $NS, $IMG, $AUTH, $JUMPTO, $REV, $lang, $fullscreen, $conf; $fullscreen = true; require_once(DOKU_INC.'lib/exe/mediamanager.php'); diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php index 939b5a053..5f09fe1f8 100644 --- a/lib/exe/mediamanager.php +++ b/lib/exe/mediamanager.php @@ -84,9 +84,9 @@ $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']); } - if ($_REQUEST['rev']) $REV = (int) $_REQUEST['rev']; + if ($_REQUEST['rev'] && $conf['mediarevisions']) $REV = (int) $_REQUEST['rev']; - if($_REQUEST['mediado'] == 'restore'){ + if($_REQUEST['mediado'] == 'restore' && $conf['mediarevisions']){ $JUMPTO = media_restore($_REQUEST['image'], $REV, $AUTH); } -- cgit v1.2.3