Skip to content

Commit

Permalink
issue #38 diff links only if diff available; deleted files
Browse files Browse the repository at this point in the history
  • Loading branch information
akate committed Aug 3, 2011
1 parent e5d185e commit 92cac9a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
30 changes: 19 additions & 11 deletions inc/html.php
Expand Up @@ -695,20 +695,28 @@ function html_recent($first=0, $show_changes='both'){
$form->addElement(form_makeCloseTag('span'));

if ($recent['media']) {
$href = media_managerURL(array('tab_details' => 'history',
'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
$diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id'])));
if ($diff) {
$href = media_managerURL(array('tab_details' => 'history',
'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
}
} else {
$href = wl($recent['id'],"do=diff", false, '&');
}
$form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
$form->addElement(form_makeTag('img', array(
'src' => DOKU_BASE.'lib/images/diff.png',
'width' => 15,
'height'=> 11,
'title' => $lang['diff'],
'alt' => $lang['diff']
)));
$form->addElement(form_makeCloseTag('a'));

if ($recent['media'] && !$diff) {
$form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
} else {
$form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
$form->addElement(form_makeTag('img', array(
'src' => DOKU_BASE.'lib/images/diff.png',
'width' => 15,
'height'=> 11,
'title' => $lang['diff'],
'alt' => $lang['diff']
)));
$form->addElement(form_makeCloseTag('a'));
}

if ($recent['media']) {
$href = media_managerURL(array('tab_details' => 'history',
Expand Down
31 changes: 18 additions & 13 deletions inc/media.php
Expand Up @@ -313,7 +313,7 @@ function media_save($file, $id, $ow, $auth, $move) {
}
}

global $lang;
global $lang, $conf;

// get filename
$id = cleanID($id,false,true);
Expand Down Expand Up @@ -603,7 +603,7 @@ function media_tabs_details($image, $selected=false){
media_tab(media_managerURL(array('tab_details' => 'view')), 'view', $lang['media_viewtab'], $selected);

list($ext, $mime) = mimetype($image);
if ($mime == 'image/jpeg') {
if ($mime == 'image/jpeg' && @file_exists(mediaFN($image))) {
media_tab(media_managerURL(array('tab_details' => 'edit')), 'edit', $lang['media_edittab'], $selected);
}
if ($conf['mediarevisions']) {
Expand Down Expand Up @@ -867,12 +867,15 @@ function media_preview_buttons($image, $auth, $rev=false) {
}
$link = ml($image,$more,true,'&');

// view original file button
$form = new Doku_Form(array('action'=>$link, 'target'=>'_blank'));
$form->addElement(form_makeButton('submit','',$lang['mediaview']));
$form->printForm();
if (@file_exists(mediaFN($image, $rev))) {

// view original file button
$form = new Doku_Form(array('action'=>$link, 'target'=>'_blank'));
$form->addElement(form_makeButton('submit','',$lang['mediaview']));
$form->printForm();
}

if($auth >= AUTH_DELETE && !$rev){
if($auth >= AUTH_DELETE && !$rev && @file_exists(mediaFN($image))){

// delete button
$form = new Doku_Form(array('id' => 'mediamanager__btn_delete',
Expand All @@ -892,7 +895,7 @@ function media_preview_buttons($image, $auth, $rev=false) {
$form->printForm();
}

if($auth >= AUTH_DELETE && $rev && $conf['mediarevisions']){
if($auth >= AUTH_DELETE && $rev && $conf['mediarevisions'] && @file_exists(mediaFN($image, $rev))){

// restore button
$form = new Doku_Form(array('id' => 'mediamanager__btn_restore',
Expand All @@ -916,7 +919,7 @@ function media_preview_buttons($image, $auth, $rev=false) {
* @return array
*/
function media_image_preview_size($image, $rev, $meta, $size = 500) {
if (!preg_match("/\.(jpe?g|gif|png)$/", $image)) return false;
if (!preg_match("/\.(jpe?g|gif|png)$/", $image) || !file_exists(mediaFN($image, $rev))) return false;

$info = getimagesize(mediaFN($image, $rev));
$w = (int) $info[0];
Expand Down Expand Up @@ -1206,7 +1209,8 @@ function media_image_diff($image, $l_rev, $r_rev, $meta, $type) {
function media_restore($image, $rev, $auth){
global $conf;
if ($auth < AUTH_DELETE || !$conf['mediarevisions']) return false;
if (!$image || !file_exists(mediaFN($image))) return false;
$removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')));
if (!$image || (!file_exists(mediaFN($image)) && !$removed)) return false;
if (!$rev || !file_exists(mediaFN($image, $rev))) return false;
list($iext,$imime,$dl) = mimetype($image);
$res = media_upload_finish(mediaFN($image, $rev),
Expand Down Expand Up @@ -1526,16 +1530,17 @@ function media_managerURL($params=false, $amp='&amp;', $abs=false) {
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_uploadform($ns, $auth, $fullscreen = false){
global $lang;
global $lang, $conf;

if($auth < AUTH_UPLOAD) {
echo '<div class="nothing">'.$lang['media_perm_upload'].'</div>'.NL;
return;
}
$auth_ow = (($conf['mediarevisions']) ? AUTH_UPLOAD : AUTH_DELETE);

$update = false;
$id = '';
if ($auth >= AUTH_DELETE && $fullscreen && $_REQUEST['mediado'] == 'update') {
if ($auth >= $auth_ow && $fullscreen && $_REQUEST['mediado'] == 'update') {
$update = true;
$id = cleanID($_REQUEST['image']);
}
Expand All @@ -1562,7 +1567,7 @@ function media_uploadform($ns, $auth, $fullscreen = false){
$form->addElement(form_makeButton('submit', '', $lang['btn_upload']));
$form->addElement(form_makeCloseTag('p'));

if($auth >= AUTH_DELETE){
if($auth >= $auth_ow){
$form->addElement(form_makeOpenTag('p'));
$attrs = array();
if ($update) $attrs['checked'] = 'checked';
Expand Down
5 changes: 3 additions & 2 deletions inc/template.php
Expand Up @@ -1174,7 +1174,8 @@ function tpl_fileList(){
function tpl_fileDetails($image, $rev){
global $AUTH, $NS, $conf;

if (!$image || !file_exists(mediaFN($image))) return '';
$removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
if (!$image || (!file_exists(mediaFN($image)) && !$removed)) return '';
if ($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
if (isset($NS) && getNS($image) != $NS) return '';
$do = $_REQUEST['mediado'];
Expand All @@ -1201,7 +1202,7 @@ function tpl_fileDetails($image, $rev){
media_tab_view($image, $NS, $AUTH, $rev);
echo '</div>';

} elseif ($opened_tab == 'edit') {
} elseif ($opened_tab == 'edit' && !$removed) {
echo '<div id="mediamanager__details">';
media_tab_edit($image, $NS, $AUTH);
echo '</div>';
Expand Down
2 changes: 1 addition & 1 deletion lib/exe/ajax.php
Expand Up @@ -222,7 +222,7 @@ function ajax_medialist(){
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function ajax_mediadetails(){
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');

Expand Down

0 comments on commit 92cac9a

Please sign in to comment.