readded $jump mechanism, removed unused functions

This commit is contained in:
Andreas Gohr 2021-01-06 22:11:42 +01:00
parent 0a47efcd61
commit 9453716dc4
4 changed files with 20 additions and 206 deletions

View File

@ -12,6 +12,9 @@ class Display
/** @var string should IDs be shown relative to this namespace? Used in search results */
protected $relativeDisplay = null;
/** @var bool scroll to this file on display? */
protected $scrollIntoView = false;
/**
* Display constructor.
* @param MediaFile $mediaFile
@ -61,6 +64,16 @@ class Display
$this->relativeDisplay = $ns;
}
/**
* Scroll to this file on display?
*
* @param bool $set
*/
public function scrollIntoView($set = true)
{
$this->scrollIntoView = $set;
}
/** @return string */
protected function formatDate()
{

View File

@ -13,16 +13,14 @@ class DisplayRow extends DisplayTile
public function show()
{
global $lang;
// FIXME support for jumping to file?
// FIXME Zebra classes have been dropped and need to be readded via CSS
// FIXME use of $display_namespace unclear, dropped for now -> maybe for search?
$id = $this->mediaFile->getId();
$class = 'select mediafile mf_' . $this->mediaFile->getIcoClass();
$info = trim($this->formatDimensions('') . ' ' . $this->formatDate() . ' ' . $this->formatFileSize());
$jump = $this->scrollIntoView ? 'id="scroll__here"' : '';
echo '<div title="' . $id . '">';
echo '<div title="' . $id . '" ' . $jump . '>';
echo '<a id="h_:' . $id . '" class="' . $class . '">' .
$this->formatDisplayName() .
'</a> ';

View File

@ -30,7 +30,9 @@ class DisplayTile extends Display
*/
public function show()
{
echo '<dl title="' . $this->mediaFile->getDisplayName() . '">';
$jump = $this->scrollIntoView ? 'id="scroll__here"' : '';
echo '<dl title="' . $this->mediaFile->getDisplayName() . '"' . $jump . '>';
echo '<dt>';
echo '<a id="l_:' . $this->mediaFile->getId() . '" class="image thumb" href="' . $this->mmUrl . '">';
echo $this->getPreviewHtml(90, 90);

View File

@ -712,11 +712,13 @@ function media_filelist($ns,$auth=null,$jump='',$fullscreenview=false,$sort=fals
if (!$fullscreenview) {
//FIXME old call: media_printfile($item,$auth,$jump);
$display = new \dokuwiki\Ui\Media\DisplayRow($item);
$display->scrollIntoView($jump == $item->getID());
$display->show();
} else {
//FIXME old call: media_printfile_thumbs($item,$auth,$jump);
echo '<li>';
$display = new \dokuwiki\Ui\Media\DisplayTile($item);
$display->scrollIntoView($jump == $item->getID());
$display->show();
echo '</li>';
}
@ -1582,86 +1584,6 @@ function media_searchlist($query,$ns,$auth=null,$fullscreen=false,$sort='natural
}
}
/**
* Formats and prints one file in the list
*
* @param array $item
* @param int $auth permission level
* @param string $jump item id
* @param bool $display_namespace
*/
function media_printfile($item,$auth,$jump,$display_namespace=false){
global $lang;
// Prepare zebra coloring
// I always wanted to use this variable name :-D
static $twibble = 1;
$twibble *= -1;
$zebra = ($twibble == -1) ? 'odd' : 'even';
// Automatically jump to recent action
if($jump == $item['id']) {
$jump = ' id="scroll__here" ';
}else{
$jump = '';
}
// Prepare fileicons
list($ext) = mimetype($item['file'],false);
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
$class = 'select mediafile mf_'.$class;
// Prepare filename
$file = utf8_decodeFN($item['file']);
// Prepare info
$info = '';
if($item['isimg']){
$info .= (int) $item['meta']->getField('File.Width');
$info .= '&#215;';
$info .= (int) $item['meta']->getField('File.Height');
$info .= ' ';
}
$info .= '<i>'.dformat($item['mtime']).'</i>';
$info .= ' ';
$info .= filesize_h($item['size']);
// output
echo '<div class="'.$zebra.'"'.$jump.' title="'.hsc($item['id']).'">'.NL;
if (!$display_namespace) {
echo '<a id="h_:'.$item['id'].'" class="'.$class.'">'.hsc($file).'</a> ';
} else {
echo '<a id="h_:'.$item['id'].'" class="'.$class.'">'.hsc($item['id']).'</a><br/>';
}
echo '<span class="info">('.$info.')</span>'.NL;
// view button
$link = ml($item['id'],'',true);
echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/magnifier.png" '.
'alt="'.$lang['mediaview'].'" title="'.$lang['mediaview'].'" class="btn" /></a>';
// mediamanager button
$link = wl('',array('do'=>'media','image'=>$item['id'],'ns'=>getNS($item['id'])));
echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/mediamanager.png" '.
'alt="'.$lang['btn_media'].'" title="'.$lang['btn_media'].'" class="btn" /></a>';
// delete button
if($item['writable'] && $auth >= AUTH_DELETE){
$link = DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']).
'&amp;sectok='.getSecurityToken();
echo ' <a href="'.$link.'" class="btn_media_delete" title="'.$item['id'].'">'.
'<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '.
'title="'.$lang['btn_delete'].'" class="btn" /></a>';
}
echo '<div class="example" id="ex_'.str_replace(':','_',$item['id']).'">';
echo $lang['mediausage'].' <code>{{:'.$item['id'].'}}</code>';
echo '</div>';
if($item['isimg']) media_printimgdetail($item);
echo '<div class="clearer"></div>'.NL;
echo '</div>'.NL;
}
/**
* Display a media icon
*
@ -1681,127 +1603,6 @@ function media_printicon($filename, $size=''){
return '<img src="'.$icon.'" alt="'.$filename.'" class="icon" />';
}
/**
* Formats and prints one file in the list in the thumbnails view
*
* @author Kate Arzamastseva <pshns@ukr.net>
*
* @param array $item
* @param int $auth permission level
* @param bool|string $jump item id
* @param bool $display_namespace
*/
function media_printfile_thumbs($item,$auth,$jump=false,$display_namespace=false){
// Prepare filename
$file = utf8_decodeFN($item['file']);
// output
echo '<li><dl title="'.hsc($item['id']).'">'.NL;
echo '<dt>';
if($item['isimg']) {
media_printimgdetail($item, true);
} else {
echo '<a id="d_:'.$item['id'].'" class="image" title="'.$item['id'].'" href="'.
media_managerURL(['image' => hsc($item['id']), 'ns' => getNS($item['id']),
'tab_details' => 'view']).'">';
echo media_printicon($item['id'], '32x32');
echo '</a>';
}
echo '</dt>'.NL;
if (!$display_namespace) {
$name = hsc($file);
} else {
$name = hsc($item['id']);
}
echo '<dd class="name"><a href="'.media_managerURL(['image' => hsc($item['id']), 'ns' => getNS($item['id']),
'tab_details' => 'view']).'" id="h_:'.$item['id'].'">'.$name.'</a></dd>'.NL;
if($item['isimg']){
$size = '';
$size .= (int) $item['meta']->getField('File.Width');
$size .= '&#215;';
$size .= (int) $item['meta']->getField('File.Height');
echo '<dd class="size">'.$size.'</dd>'.NL;
} else {
echo '<dd class="size">&#160;</dd>'.NL;
}
$date = dformat($item['mtime']);
echo '<dd class="date">'.$date.'</dd>'.NL;
$filesize = filesize_h($item['size']);
echo '<dd class="filesize">'.$filesize.'</dd>'.NL;
echo '</dl></li>'.NL;
}
/**
* Prints a thumbnail and metainfo
*
* @param array $item
* @param bool $fullscreen
*/
function media_printimgdetail($item, $fullscreen=false){
// prepare thumbnail
$size = $fullscreen ? 90 : 120;
$w = (int) $item['meta']->getField('File.Width');
$h = (int) $item['meta']->getField('File.Height');
if($w>$size || $h>$size){
if (!$fullscreen) {
$ratio = $item['meta']->getResizeRatio($size);
} else {
$ratio = $item['meta']->getResizeRatio($size,$size);
}
$w = floor($w * $ratio);
$h = floor($h * $ratio);
}
$src = ml($item['id'],array('w'=>$w,'h'=>$h,'t'=>$item['mtime']));
$p = array();
if (!$fullscreen) {
// In fullscreen mediamanager view, image resizing is done via CSS.
$p['width'] = $w;
$p['height'] = $h;
}
$p['alt'] = $item['id'];
$att = buildAttributes($p);
// output
if ($fullscreen) {
echo '<a id="l_:'.$item['id'].'" class="image thumb" href="'.
media_managerURL(['image' => hsc($item['id']), 'ns' => getNS($item['id']), 'tab_details' => 'view']).'">';
echo '<img src="'.$src.'" '.$att.' />';
echo '</a>';
}
if ($fullscreen) return;
echo '<div class="detail">';
echo '<div class="thumb">';
echo '<a id="d_:'.$item['id'].'" class="select">';
echo '<img src="'.$src.'" '.$att.' />';
echo '</a>';
echo '</div>';
// read EXIF/IPTC data
$t = $item['meta']->getField(array('IPTC.Headline','xmp.dc:title'));
$d = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment',
'EXIF.TIFFImageDescription',
'EXIF.TIFFUserComment'));
if(\dokuwiki\Utf8\PhpString::strlen($d) > 250) $d = \dokuwiki\Utf8\PhpString::substr($d,0,250).'...';
$k = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category','xmp.dc:subject'));
// print EXIF/IPTC data
if($t || $d || $k ){
echo '<p>';
if($t) echo '<strong>'.hsc($t).'</strong><br />';
if($d) echo hsc($d).'<br />';
if($t) echo '<em>'.hsc($k).'</em>';
echo '</p>';
}
echo '</div>';
}
/**
* Build link based on the current, adding/rewriting parameters
*