1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
<?php
use dokuwiki\Extension\Event;
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
define('DOKU_MEDIAMANAGER', 1);
// for multi uploader:
@ini_set('session.use_only_cookies', 0);
require_once(DOKU_INC . 'inc/init.php');
global $INPUT;
global $lang;
global $conf;
// handle passed message
if ($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')), 1);
if ($INPUT->str('err')) msg(hsc($INPUT->str('err')), -1);
global $DEL;
// get namespace to display (either direct or from deletion order)
if ($INPUT->str('delete')) {
$DEL = cleanID($INPUT->str('delete'));
$IMG = $DEL;
$NS = getNS($DEL);
} elseif ($INPUT->str('edit')) {
$IMG = cleanID($INPUT->str('edit'));
$NS = getNS($IMG);
} elseif ($INPUT->str('img')) {
$IMG = cleanID($INPUT->str('img'));
$NS = getNS($IMG);
} else {
$NS = cleanID($INPUT->str('ns'));
$IMG = null;
}
global $INFO, $JSINFO;
$INFO = empty($INFO) ? mediainfo() : array_merge($INFO, mediainfo());
$JSINFO['id'] = '';
$JSINFO['namespace'] = '';
$AUTH = $INFO['perm']; // shortcut for historical reasons
// If this page is directly opened it means we are in popup mode not fullscreen
// $fullscreen isn't defined by default it might lead to some PHP warnings
$fullscreen ??= false;
$tmp = [];
Event::createAndTrigger('MEDIAMANAGER_STARTED', $tmp);
session_write_close(); //close session
// do not display the manager if user does not have read access
if ($AUTH < AUTH_READ && !$fullscreen) {
http_status(403);
die($lang['accessdenied']);
}
// handle flash upload
if (isset($_FILES['Filedata'])) {
$_FILES['upload'] =& $_FILES['Filedata'];
$JUMPTO = media_upload($NS, $AUTH);
if ($JUMPTO == false) {
http_status(400);
echo 'Upload failed';
}
echo 'ok';
exit;
}
// give info on PHP caught upload errors
if (!empty($_FILES['upload']['error'])) {
switch ($_FILES['upload']['error']) {
case 1:
case 2:
msg(sprintf(
$lang['uploadsize'],
filesize_h(php_to_byte(ini_get('upload_max_filesize')))
), -1);
break;
default:
msg($lang['uploadfail'] . ' (' . $_FILES['upload']['error'] . ')', -1);
}
unset($_FILES['upload']);
}
// handle upload
if (!empty($_FILES['upload']['tmp_name'])) {
$JUMPTO = media_upload($NS, $AUTH);
if ($JUMPTO) $NS = getNS($JUMPTO);
}
// handle meta saving
if ($IMG && @array_key_exists('save', $INPUT->arr('do'))) {
$JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
}
if ($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) {
$JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
}
if ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev');
if ($INPUT->str('mediado') == 'restore' && $conf['mediarevisions']) {
$JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH);
}
// handle deletion
if ($DEL) {
$res = 0;
if (checkSecurityToken()) {
$res = media_delete($DEL, $AUTH);
}
if ($res & DOKU_MEDIA_DELETED) {
$msg = sprintf($lang['deletesucc'], noNS($DEL));
if ($res & DOKU_MEDIA_EMPTY_NS && !$fullscreen) {
// current namespace was removed. redirecting to root ns passing msg along
send_redirect(DOKU_URL . 'lib/exe/mediamanager.php?msg1=' .
rawurlencode($msg) . '&edid=' . $INPUT->str('edid'));
}
msg($msg, 1);
} elseif ($res & DOKU_MEDIA_INUSE) {
msg(sprintf($lang['mediainuse'], noNS($DEL)), 0);
} else {
msg(sprintf($lang['deletefail'], noNS($DEL)), -1);
}
}
// finished - start output
if (!$fullscreen) {
header('Content-Type: text/html; charset=utf-8');
include(template('mediamanager.php'));
}
|