Add own admin page for the plugin
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled
This commit is contained in:
2
README
2
README
@@ -1,4 +1,4 @@
|
||||
LuxTools plugin for DokuWiki
|
||||
luxtools plugin for DokuWiki
|
||||
|
||||
Lists files matching a given glob pattern.
|
||||
|
||||
|
||||
@@ -39,48 +39,44 @@ class GeneralTest extends DokuWikiTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
|
||||
* conf/metadata.php.
|
||||
* luxtools settings are managed via the plugin's admin page, not via the Configuration Manager.
|
||||
* Ensure default config exists and (when present) metadata.php does not expose any settings.
|
||||
*/
|
||||
public function testPluginConf(): void
|
||||
{
|
||||
$conf_file = __DIR__ . '/../conf/default.php';
|
||||
$meta_file = __DIR__ . '/../conf/metadata.php';
|
||||
|
||||
if (!file_exists($conf_file) && !file_exists($meta_file)) {
|
||||
self::markTestSkipped('No config files exist -> skipping test');
|
||||
if (!file_exists($conf_file)) {
|
||||
self::markTestSkipped('No config default.php exists -> skipping test');
|
||||
}
|
||||
|
||||
if (file_exists($conf_file)) {
|
||||
$conf = null;
|
||||
$meta = null;
|
||||
|
||||
include($conf_file);
|
||||
}
|
||||
$this->assertIsArray(
|
||||
$conf,
|
||||
'The ' . DOKU_PLUGIN . 'luxtools/conf/default.php file needs to define $conf as an array.'
|
||||
);
|
||||
|
||||
if (file_exists($meta_file)) {
|
||||
include($meta_file);
|
||||
|
||||
if ($meta === null) {
|
||||
// If the file exists but does not define $meta, treat it as empty.
|
||||
$meta = [];
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
gettype($conf),
|
||||
gettype($meta),
|
||||
'Both ' . DOKU_PLUGIN . 'luxtools/conf/default.php and ' . DOKU_PLUGIN . 'luxtools/conf/metadata.php have to exist and contain the same keys.'
|
||||
);
|
||||
|
||||
if ($conf !== null && $meta !== null) {
|
||||
foreach ($conf as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$this->assertIsArray(
|
||||
$meta,
|
||||
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'luxtools/conf/metadata.php'
|
||||
'The ' . DOKU_PLUGIN . 'luxtools/conf/metadata.php file needs to define $meta as an array.'
|
||||
);
|
||||
$this->assertEmpty(
|
||||
$meta,
|
||||
'luxtools should not expose settings via the Configuration Manager.'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($meta as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$conf,
|
||||
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'luxtools/conf/default.php'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
195
admin/main.php
Normal file
195
admin/main.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
/**
|
||||
* luxtools: Admin settings page
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
class admin_plugin_luxtools_main extends DokuWiki_Admin_Plugin
|
||||
{
|
||||
/** @var string[] */
|
||||
protected $configKeys = [
|
||||
'paths',
|
||||
'allow_in_comments',
|
||||
'defaults',
|
||||
'extensions',
|
||||
'thumb_placeholder',
|
||||
'gallery_thumb_scale',
|
||||
'open_service_url',
|
||||
];
|
||||
|
||||
public function getMenuText($language)
|
||||
{
|
||||
return $this->getLang('menu');
|
||||
}
|
||||
|
||||
public function getMenuSort()
|
||||
{
|
||||
// keep near other plugin tools
|
||||
return 1011;
|
||||
}
|
||||
|
||||
public function forAdminOnly()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
global $INPUT;
|
||||
|
||||
if ($INPUT->str('luxtools_cmd') !== 'save') return;
|
||||
|
||||
if (!checkSecurityToken()) {
|
||||
msg($this->getLang('err_security'), -1);
|
||||
return;
|
||||
}
|
||||
|
||||
$newConf = [];
|
||||
// Normalize newlines to "\n" for consistent parsing
|
||||
$paths = $INPUT->str('paths');
|
||||
$paths = str_replace(["\r\n", "\r"], "\n", $paths);
|
||||
$newConf['paths'] = $paths;
|
||||
$newConf['allow_in_comments'] = (int)$INPUT->bool('allow_in_comments');
|
||||
$newConf['defaults'] = $INPUT->str('defaults');
|
||||
$newConf['extensions'] = $INPUT->str('extensions');
|
||||
$newConf['thumb_placeholder'] = $INPUT->str('thumb_placeholder');
|
||||
$newConf['gallery_thumb_scale'] = $INPUT->str('gallery_thumb_scale');
|
||||
$newConf['open_service_url'] = $INPUT->str('open_service_url');
|
||||
|
||||
if ($this->savePluginLocalConf($newConf)) {
|
||||
msg($this->getLang('saved'), 1);
|
||||
} else {
|
||||
msg($this->getLang('err_save'), -1);
|
||||
}
|
||||
}
|
||||
|
||||
public function html()
|
||||
{
|
||||
global $ID;
|
||||
|
||||
echo '<div class="plugin_luxtools_admin">';
|
||||
echo '<h1>' . hsc($this->getLang('settings')) . '</h1>';
|
||||
|
||||
echo '<form action="' . hsc(wl($ID)) . '" method="post" class="plugin_luxtools_admin_form">';
|
||||
echo '<input type="hidden" name="do" value="admin" />';
|
||||
echo '<input type="hidden" name="page" value="luxtools_main" />';
|
||||
echo '<input type="hidden" name="id" value="' . hsc($ID) . '" />';
|
||||
echo '<input type="hidden" name="luxtools_cmd" value="save" />';
|
||||
echo formSecurityToken();
|
||||
|
||||
echo '<fieldset>';
|
||||
echo '<legend>' . hsc($this->getLang('legend')) . '</legend>';
|
||||
|
||||
// paths: multiline textarea
|
||||
$paths = (string)$this->getConf('paths');
|
||||
echo '<label class="block"><span>' . hsc($this->getLang('paths')) . '</span><br />';
|
||||
echo '<textarea name="paths" rows="8" cols="80" class="edit">' . hsc($paths) . '</textarea>';
|
||||
echo '</label><br />';
|
||||
|
||||
// allow_in_comments
|
||||
$checked = $this->getConf('allow_in_comments') ? ' checked="checked"' : '';
|
||||
echo '<label class="block"><span>' . hsc($this->getLang('allow_in_comments')) . '</span> ';
|
||||
echo '<input type="checkbox" name="allow_in_comments" value="1"' . $checked . ' />';
|
||||
echo '</label><br />';
|
||||
|
||||
// defaults
|
||||
echo '<label class="block"><span>' . hsc($this->getLang('defaults')) . '</span> ';
|
||||
echo '<input type="text" class="edit" name="defaults" value="' . hsc((string)$this->getConf('defaults')) . '" />';
|
||||
echo '</label><br />';
|
||||
|
||||
// extensions
|
||||
echo '<label class="block"><span>' . hsc($this->getLang('extensions')) . '</span> ';
|
||||
echo '<input type="text" class="edit" name="extensions" value="' . hsc((string)$this->getConf('extensions')) . '" />';
|
||||
echo '</label><br />';
|
||||
|
||||
// thumb_placeholder
|
||||
echo '<label class="block"><span>' . hsc($this->getLang('thumb_placeholder')) . '</span> ';
|
||||
echo '<input type="text" class="edit" name="thumb_placeholder" value="' . hsc((string)$this->getConf('thumb_placeholder')) . '" />';
|
||||
echo '</label><br />';
|
||||
|
||||
// gallery_thumb_scale
|
||||
echo '<label class="block"><span>' . hsc($this->getLang('gallery_thumb_scale')) . '</span> ';
|
||||
echo '<input type="text" class="edit" name="gallery_thumb_scale" value="' . hsc((string)$this->getConf('gallery_thumb_scale')) . '" />';
|
||||
echo '</label><br />';
|
||||
|
||||
// open_service_url
|
||||
echo '<label class="block"><span>' . hsc($this->getLang('open_service_url')) . '</span> ';
|
||||
echo '<input type="text" class="edit" name="open_service_url" value="' . hsc((string)$this->getConf('open_service_url')) . '" />';
|
||||
echo '</label><br />';
|
||||
|
||||
echo '<button type="submit" class="button">' . hsc($this->getLang('btn_save')) . '</button>';
|
||||
|
||||
echo '</fieldset>';
|
||||
echo '</form>';
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist plugin settings to conf/plugins/luxtools.local.php.
|
||||
*
|
||||
* @param array $newConf
|
||||
* @return bool
|
||||
*/
|
||||
protected function savePluginLocalConf(array $newConf)
|
||||
{
|
||||
if (!defined('DOKU_CONF')) return false;
|
||||
|
||||
$plugin = 'luxtools';
|
||||
$confDir = DOKU_CONF . 'plugins/';
|
||||
$file = $confDir . $plugin . '.local.php';
|
||||
|
||||
if (function_exists('io_mkdir_p')) {
|
||||
io_mkdir_p($confDir);
|
||||
} elseif (!@is_dir($confDir)) {
|
||||
@mkdir($confDir, 0777, true);
|
||||
}
|
||||
|
||||
// Only write known keys; ignore extras.
|
||||
$lines = ["<?php"];
|
||||
foreach ($this->configKeys as $key) {
|
||||
if (!array_key_exists($key, $newConf)) continue;
|
||||
$value = $newConf[$key];
|
||||
$lines[] = '$conf[' . var_export($key, true) . '] = ' . $this->exportPhpValue($value, $key) . ';';
|
||||
}
|
||||
$lines[] = '';
|
||||
$content = implode("\n", $lines);
|
||||
|
||||
if (function_exists('io_saveFile')) {
|
||||
return (bool)io_saveFile($file, $content);
|
||||
}
|
||||
|
||||
return @file_put_contents($file, $content, LOCK_EX) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export a value to PHP code.
|
||||
*
|
||||
* We use nowdoc for multiline strings to safely preserve newlines.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function exportPhpValue($value, string $key): string
|
||||
{
|
||||
if (is_bool($value) || is_int($value) || is_float($value) || $value === null) {
|
||||
return var_export($value, true);
|
||||
}
|
||||
|
||||
$value = (string)$value;
|
||||
|
||||
if (str_contains($value, "\n") || str_contains($value, "\r")) {
|
||||
$marker = strtoupper('LUXTOOLS_' . preg_replace('/[^A-Z0-9_]/i', '_', $key) . '_EOT');
|
||||
// Extremely unlikely, but avoid delimiter collision.
|
||||
while (str_contains($value, $marker)) {
|
||||
$marker .= '_X';
|
||||
}
|
||||
return "<<<'$marker'\n" . $value . "\n$marker";
|
||||
}
|
||||
|
||||
return var_export($value, true);
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,10 @@
|
||||
|
||||
/**
|
||||
* Metadata for configuration manager plugin
|
||||
* Additions for the luxtools plugin
|
||||
*
|
||||
* @author Gina Haeussge <osd@foosel.net>
|
||||
* NOTE: luxtools settings are managed via the plugin's dedicated admin page
|
||||
* (Admin -> Additional Plugins). Therefore, we intentionally do not expose
|
||||
* any settings to the Configuration Manager.
|
||||
*/
|
||||
|
||||
$meta['paths'] = array('');
|
||||
$meta['allow_in_comments'] = array('onoff');
|
||||
$meta['defaults'] = array('string');
|
||||
$meta['extensions'] = array('string');
|
||||
|
||||
$meta['thumb_placeholder'] = array('string');
|
||||
|
||||
// Thumbnail generation scale factor for the {{images>...}} gallery.
|
||||
$meta['gallery_thumb_scale'] = array('string');
|
||||
|
||||
$meta['open_service_url'] = array('string');
|
||||
$meta = [];
|
||||
|
||||
@@ -16,3 +16,19 @@ $lang['error_outsidejail'] = 'Zugriff verweigert';
|
||||
|
||||
$lang['empty_files'] = 'Keine Dateien';
|
||||
$lang['empty_images'] = 'Keine Bilder';
|
||||
|
||||
$lang['menu'] = 'luxtools';
|
||||
$lang['settings'] = 'luxtools-Einstellungen';
|
||||
$lang['legend'] = 'Einstellungen';
|
||||
$lang['btn_save'] = 'Speichern';
|
||||
$lang['saved'] = 'Einstellungen gespeichert.';
|
||||
$lang['err_save'] = 'Einstellungen konnten nicht gespeichert werden. Bitte Schreibrechte für conf/plugins/ prüfen.';
|
||||
$lang['err_security'] = 'Sicherheits-Token ungültig. Bitte erneut versuchen.';
|
||||
|
||||
$lang['paths'] = 'Erlaubte Basis-Pfade (eine pro Zeile oder komma-separiert).';
|
||||
$lang['allow_in_comments'] = 'Files-Syntax in Kommentaren erlauben.';
|
||||
$lang['defaults'] = 'Standardoptionen (gleiche Syntax wie bei Inline-Konfiguration).';
|
||||
$lang['extensions'] = 'Kommagetrennte Liste erlaubter Dateiendungen.';
|
||||
$lang['thumb_placeholder'] = 'MediaManager-ID für den Platzhalter der Galerie-Thumbnails.';
|
||||
$lang['gallery_thumb_scale'] = 'Skalierungsfaktor für Galerie-Thumbnails. 2 erzeugt schärfere Thumbnails auf HiDPI-Displays (Anzeige bleibt 150×150).';
|
||||
$lang['open_service_url'] = 'URL des lokalen Client-Dienstes für {{open>...}} (z.B. http://127.0.0.1:8765).';
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<?php
|
||||
|
||||
$lang['paths'] = 'Erlaubte Basis-Pfade (eine pro Zeile oder komma-separiert).';
|
||||
$lang['allow_in_comments'] = 'Files-Syntax in Kommentaren erlauben.';
|
||||
|
||||
$lang['defaults'] = 'Standardoptionen (gleiche Syntax wie bei Inline-Konfiguration).';
|
||||
$lang['extensions'] = 'Kommagetrennte Liste erlaubter Dateiendungen.';
|
||||
|
||||
$lang['thumb_placeholder'] = 'MediaManager-ID für den Platzhalter der Galerie-Thumbnails';
|
||||
|
||||
$lang['gallery_thumb_scale'] = 'Skalierungsfaktor für Galerie-Thumbnails. 2 erzeugt schärfere Thumbnails auf HiDPI-Displays (Anzeige bleibt 150×150).';
|
||||
|
||||
@@ -16,3 +16,19 @@ $lang['error_outsidejail'] = 'Access denied';
|
||||
|
||||
$lang['empty_files'] = 'No Files';
|
||||
$lang['empty_images'] = 'No Images';
|
||||
|
||||
$lang['menu'] = 'luxtools';
|
||||
$lang['settings'] = 'luxtools settings';
|
||||
$lang['legend'] = 'Settings';
|
||||
$lang['btn_save'] = 'Save';
|
||||
$lang['saved'] = 'Settings saved.';
|
||||
$lang['err_save'] = 'Could not save settings. Please check write permissions for conf/plugins/.';
|
||||
$lang['err_security'] = 'Security token mismatch. Please retry.';
|
||||
|
||||
$lang['paths'] = 'Allowed base paths (one per line or comma-separated).';
|
||||
$lang['allow_in_comments'] = 'Whether to allow the files syntax to be used in comments.';
|
||||
$lang['defaults'] = 'Default options. Use the same syntax as in inline configuration.';
|
||||
$lang['extensions'] = 'Comma-separated list of allowed file extensions to list.';
|
||||
$lang['thumb_placeholder'] = 'MediaManager ID for the gallery thumbnail placeholder.';
|
||||
$lang['gallery_thumb_scale'] = 'Gallery thumbnail scale factor. Use 2 for sharper thumbnails on HiDPI screens (still displayed as 150×150).';
|
||||
$lang['open_service_url'] = 'Local client service URL for the {{open>...}} button (e.g. http://127.0.0.1:8765).';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
$lang['paths'] = 'Allowed base paths (one per line or comma-separated).';
|
||||
$lang['allow_in_comments'] = 'Whether to allow the files syntax to be used in comments.';
|
||||
$lang['defaults'] = 'Default options. Use the same syntax as in inline configuration';
|
||||
$lang['extensions'] = 'Comma-separated list of allowed file extensions to list';
|
||||
|
||||
@@ -2,6 +2,6 @@ base luxtools
|
||||
author Gina Häußge, Dokufreaks, luxick
|
||||
email dokuwiki@luxick.de
|
||||
date 2026-01-05
|
||||
name LuxTools
|
||||
name luxtools
|
||||
desc Lists files matching a given glob pattern.
|
||||
url https://www.dokuwiki.org/plugin:luxtools
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* LuxTools plugin styles
|
||||
/* luxtools plugin styles
|
||||
* Keep this minimal and scoped to the plugin container.
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ require_once(__DIR__ . '/syntax/AbstractSyntax.php');
|
||||
require_once(__DIR__ . '/syntax/files.php');
|
||||
|
||||
/**
|
||||
* LuxTools plugin bootstrap.
|
||||
* luxtools plugin bootstrap.
|
||||
*
|
||||
* The actual {{files>...}} syntax implementation lives in syntax/files.php.
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@ use dokuwiki\plugin\luxtools\Output;
|
||||
use dokuwiki\plugin\luxtools\Path;
|
||||
|
||||
/**
|
||||
* LuxTools Plugin: Abstract base class for file-listing syntax handlers.
|
||||
* luxtools Plugin: Abstract base class for file-listing syntax handlers.
|
||||
*
|
||||
* Provides shared functionality for directory, files, and images syntax.
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@ use dokuwiki\plugin\luxtools\Path;
|
||||
require_once(__DIR__ . '/AbstractSyntax.php');
|
||||
|
||||
/**
|
||||
* LuxTools Plugin: Directory syntax.
|
||||
* luxtools Plugin: Directory syntax.
|
||||
*
|
||||
* Lists the direct children (folders and files) of a given path.
|
||||
* Always renders as a table.
|
||||
|
||||
@@ -5,7 +5,7 @@ use dokuwiki\plugin\luxtools\Output;
|
||||
require_once(__DIR__ . '/AbstractSyntax.php');
|
||||
|
||||
/**
|
||||
* LuxTools Plugin: Files syntax.
|
||||
* luxtools Plugin: Files syntax.
|
||||
*
|
||||
* Lists files matching a given glob pattern.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ use dokuwiki\plugin\luxtools\Output;
|
||||
require_once(__DIR__ . '/AbstractSyntax.php');
|
||||
|
||||
/**
|
||||
* LuxTools Plugin: Image gallery syntax.
|
||||
* luxtools Plugin: Image gallery syntax.
|
||||
*
|
||||
* Renders a thumbnail gallery of images matching a glob pattern.
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use dokuwiki\Extension\SyntaxPlugin;
|
||||
|
||||
/**
|
||||
* LuxTools Plugin: Open local path syntax.
|
||||
* luxtools Plugin: Open local path syntax.
|
||||
*
|
||||
* Renders an inline button. Clicking it triggers client-side JS that attempts
|
||||
* to open the configured path in the default file manager (best-effort).
|
||||
|
||||
Reference in New Issue
Block a user