Add directory listing syntax
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled

This commit is contained in:
2026-01-06 08:56:42 +01:00
parent e59970e0b8
commit 0ad43bcf9c
4 changed files with 311 additions and 1 deletions

View File

@@ -91,6 +91,25 @@ class Output
}
}
/**
* Render a flat list (files and/or directories) as a table.
*
* @param array $params
* @return void
*/
public function renderAsFlatTable($params)
{
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->renderer->doc .= '<div class="filetools-plugin">';
}
$this->renderTableItems($this->files, $params);
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->renderer->doc .= '</div>';
}
}
/**
* Renders the files as a table, including details if configured that way.
@@ -147,7 +166,11 @@ class Output
if ($params['showsize']) {
$renderer->tablecell_open(1, 'right');
$renderer->cdata(filesize_h($item['size']));
if (!empty($item['isdir'])) {
$renderer->cdata('');
} else {
$renderer->cdata(filesize_h($item['size']));
}
$renderer->tablecell_close();
}
@@ -217,6 +240,11 @@ class Output
protected function renderItemLink($item, $cachebuster = false)
{
if (!empty($item['isdir'])) {
$this->renderDirectoryLink($item);
return;
}
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->renderItemLinkXHTML($item, $cachebuster);
} else {
@@ -224,6 +252,60 @@ class Output
}
}
/**
* Render a directory like a normal media link, but with open behaviour.
*
* @param array $item
* @return void
*/
protected function renderDirectoryLink($item)
{
$caption = $item['name'] ?? '';
$path = $item['path'] ?? '';
if ($caption === '') {
$caption = '[n/a]';
}
if (!($this->renderer instanceof \Doku_Renderer_xhtml)) {
$this->renderer->cdata($caption);
return;
}
if (!is_string($path) || $path === '') {
$this->renderer->cdata('[n/a]');
return;
}
global $conf;
/** @var \Doku_Renderer_xhtml $renderer */
$renderer = $this->renderer;
$syntax = plugin_load('syntax', 'luxtools');
$serviceUrl = $syntax ? trim((string)$syntax->getConf('open_service_url')) : '';
$serviceToken = $syntax ? trim((string)$syntax->getConf('open_service_token')) : '';
// Prepare a DokuWiki-style media link with a folder icon class.
$link = [
'target' => $conf['target']['extern'],
'style' => '',
'pre' => '',
'suf' => '',
'name' => $caption,
'url' => '#',
'title' => $renderer->_xmlEntities($path),
'more' => ' class="filetools-open media mediafile mf_folder" data-path="' . hsc($path) . '"',
];
if ($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
if ($serviceUrl !== '') {
$link['more'] .= ' data-service-url="' . hsc($serviceUrl) . '"';
}
if ($serviceToken !== '') {
$link['more'] .= ' data-service-token="' . hsc($serviceToken) . '"';
}
$renderer->doc .= $renderer->_formatLink($link);
}
/**
* Render a file link on the XHTML renderer
*/