Clean up unused syntax

This commit is contained in:
2026-01-22 20:27:47 +01:00
parent 351485efb1
commit 912f9dcac6
10 changed files with 144 additions and 241 deletions

View File

@@ -164,7 +164,6 @@ abstract class syntax_plugin_luxtools_abstract extends SyntaxPlugin
$baseDefaults = [
'sort' => (string)$this->getConf('default_sort'),
'order' => (string)$this->getConf('default_order'),
'style' => (string)$this->getConf('default_style'),
'tableheader' => (int)$this->getConf('default_tableheader'),
'foldersfirst' => (int)$this->getConf('default_foldersfirst'),
'recursive' => (int)$this->getConf('default_recursive'),
@@ -173,7 +172,6 @@ abstract class syntax_plugin_luxtools_abstract extends SyntaxPlugin
'randlinks' => (int)$this->getConf('default_randlinks'),
'showsize' => $defaultShowSize,
'showdate' => $defaultShowDate,
'listsep' => (string)$this->getConf('default_listsep'),
'maxheight' => (int)$this->getConf('default_maxheight'),
];

View File

@@ -10,6 +10,7 @@ require_once(__DIR__ . '/AbstractSyntax.php');
*
* Lists the direct children (folders and files) of a given path.
* Always renders as a table.
* Also accepts the 'files' keyword for backwards compatibility with glob patterns.
*/
class syntax_plugin_luxtools_directory extends syntax_plugin_luxtools_abstract
{
@@ -28,38 +29,101 @@ class syntax_plugin_luxtools_directory extends syntax_plugin_luxtools_abstract
return 'directory';
}
/** @inheritdoc */
public function connectTo($mode)
{
// Accept both {{directory>...}} and {{files>...}} for backwards compatibility
$this->Lexer->addSpecialPattern('\{\{directory>.+?\}\}', $mode, 'plugin_luxtools_directory');
$this->Lexer->addSpecialPattern('\{\{files>.+?\}\}', $mode, 'plugin_luxtools_directory');
}
/** @inheritdoc */
public function handle($match, $state, $pos, Doku_Handler $handler)
{
// Detect which keyword was used
$keyword = 'directory';
if (str_starts_with($match, '{{files>')) {
$keyword = 'files';
}
$match = substr($match, strlen('{{' . $keyword . '>'), -2);
[$path, $flags] = array_pad(explode('&', $match, 2), 2, '');
$params = $this->parseFlags($flags);
$pathData = $this->processPath($path);
// Store the original keyword to determine processing mode
$pathData['isGlobPattern'] = ($keyword === 'files');
return ['pathData' => $pathData, 'params' => $params];
}
/** @inheritdoc */
protected function processPath(string $path): array
{
// Directory path (no glob/pattern)
$path = Path::cleanPath($path, true);
return ['path' => $path];
// Check if path contains glob characters (*, ?, [, ])
$hasGlob = (str_contains($path, '*') || str_contains($path, '?') ||
str_contains($path, '[') || str_contains($path, ']'));
if ($hasGlob) {
// Process as glob pattern (old files syntax)
[$base, $pattern] = $this->separatePathAndPattern($path);
return ['base' => $base, 'pattern' => $pattern, 'isGlobPattern' => true];
} else {
// Process as directory path
$path = Path::cleanPath($path, true);
return ['path' => $path, 'isGlobPattern' => false];
}
}
/** @inheritdoc */
protected function doRender(string $format, \Doku_Renderer $renderer, array $pathData, array $params): bool
{
$pathInfo = $this->getPathInfoSafe($pathData['path'], $renderer);
if ($pathInfo === false) {
return true;
$isGlobPattern = $pathData['isGlobPattern'] ?? false;
if ($isGlobPattern && isset($pathData['base'], $pathData['pattern'])) {
// Old files syntax behavior: crawl with glob pattern
$pathInfo = $this->getPathInfoSafe($pathData['base'], $renderer);
if ($pathInfo === false) {
return true;
}
$crawler = $this->createCrawler($params);
$result = $crawler->crawl(
$pathInfo['root'],
$pathInfo['local'],
$pathData['pattern'],
$params['recursive'],
$params['titlefile']
);
// Pass the base directory as openlocation so the "Open Location" link is displayed.
$params['openlocation'] = $pathInfo['root'] . $pathInfo['local'];
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $result, $this);
$output->renderAsTable($params);
} else {
// Normal directory listing behavior
$pathInfo = $this->getPathInfoSafe($pathData['path'], $renderer);
if ($pathInfo === false) {
return true;
}
// Provide the current directory path so Output can render the "Open Location" link.
$params['openlocation'] = $pathInfo['root'] . $pathInfo['local'];
$crawler = $this->createCrawler($params);
$items = $crawler->listDirectory(
$pathInfo['root'],
$pathInfo['local'],
$params['titlefile']
);
// Render the table even if empty so the "Open Location" link is displayed.
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items, $this);
$output->renderAsFlatTable($params);
}
// Provide the current directory path so Output can render the "Open Location" link.
$params['openlocation'] = $pathInfo['root'] . $pathInfo['local'];
$crawler = $this->createCrawler($params);
$items = $crawler->listDirectory(
$pathInfo['root'],
$pathInfo['local'],
$params['titlefile']
);
// Always render as table style
$params['style'] = 'table';
// Render the table even if empty so the "Open Location" link is displayed.
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items);
$output->renderAsFlatTable($params);
return true;
}
}

View File

@@ -1,62 +0,0 @@
<?php
use dokuwiki\plugin\luxtools\Output;
require_once(__DIR__ . '/AbstractSyntax.php');
/**
* luxtools Plugin: Files syntax.
*
* Lists files matching a given glob pattern.
*/
class syntax_plugin_luxtools_files extends syntax_plugin_luxtools_abstract
{
/** @inheritdoc */
protected function getSyntaxKeyword(): string
{
return 'files';
}
/** @inheritdoc */
protected function processPath(string $path): array
{
[$base, $pattern] = $this->separatePathAndPattern($path);
return ['base' => $base, 'pattern' => $pattern];
}
/** @inheritdoc */
protected function doRender(string $format, \Doku_Renderer $renderer, array $pathData, array $params): bool
{
$pathInfo = $this->getPathInfoSafe($pathData['base'], $renderer);
if ($pathInfo === false) {
return true;
}
$crawler = $this->createCrawler($params);
$result = $crawler->crawl(
$pathInfo['root'],
$pathInfo['local'],
$pathData['pattern'],
$params['recursive'],
$params['titlefile']
);
// For table style, pass the base directory as openlocation so the "Open Location" link is displayed.
if ($params['style'] === 'table') {
$params['openlocation'] = $pathInfo['root'] . $pathInfo['local'];
}
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $result);
switch ($params['style']) {
case 'list':
case 'olist':
$output->renderAsList($params);
break;
case 'table':
$output->renderAsTable($params);
break;
}
return true;
}
}

View File

@@ -22,11 +22,9 @@ class syntax_plugin_luxtools_images extends syntax_plugin_luxtools_abstract
{
// Images syntax doesn't use some of the common params
return [
'style' => null,
'tableheader' => null,
'showsize' => null,
'showdate' => null,
'listsep' => null,
];
}
@@ -62,19 +60,13 @@ class syntax_plugin_luxtools_images extends syntax_plugin_luxtools_abstract
return true;
}
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items);
if ($format == 'xhtml') {
$output->renderAsGallery($params);
return true;
// Images syntax only supports XHTML format (gallery rendering)
if ($format !== 'xhtml') {
return false;
}
// Fallback for non-XHTML formats: render as a list of links
$params['style'] = 'list';
$params['showsize'] = 0;
$params['showdate'] = 0;
$params['listsep'] = ', ';
$output->renderAsList($params);
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items, $this);
$output->renderAsGallery($params);
return true;
}