Additional error checking for scratchpads

This commit is contained in:
2026-01-09 09:37:21 +01:00
parent 15cfa01114
commit 6328523624
5 changed files with 39 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
# Development instructions
- Do not use `phpunit` There are missing dependencies that make it fail.
- Consider The official documentation for wirting dokuwiki plugins: https://www.dokuwiki.org/devel:plugins
- Use `php -l <file>` to check for syntax errors.
- Consider The official documentation for writing dokuwiki plugins: https://www.dokuwiki.org/devel:plugins

View File

@@ -26,9 +26,18 @@ $lang['err_save'] = 'Einstellungen konnten nicht gespeichert werden. Bitte Schre
$lang['err_security'] = 'Sicherheits-Token ungültig. Bitte erneut versuchen.';
$lang['paths'] = 'Erlaubte Basis-Pfade (eine pro Zeile oder komma-separiert).';
$lang['scratchpad_paths'] = 'Scratchpad-Dateien (eine pro Zeile). Jeder Dateipfad muss eine Erweiterung enthalten. Mit einer folgenden A>-Zeile wird der Pad-Name gesetzt, der im Wiki verwendet wird.';
$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).';
$lang['scratchpad_edit'] = 'Scratchpad bearbeiten';
$lang['scratchpad_save'] = 'Speichern';
$lang['scratchpad_cancel'] = 'Abbrechen';
$lang['scratchpad_err_nopath'] = 'Scratchpad-Pfad fehlt';
$lang['scratchpad_err_badpath'] = 'Ungültiger Scratchpad-Pfad';
$lang['scratchpad_err_unknown'] = 'Unbekannter Scratchpad-Name';
$lang['scratchpad_err_unreadable'] = 'Scratchpad-Datei ist nicht lesbar';

View File

@@ -40,3 +40,4 @@ $lang['scratchpad_cancel'] = 'Cancel';
$lang['scratchpad_err_nopath'] = 'Scratchpad path missing';
$lang['scratchpad_err_badpath'] = 'Invalid scratchpad path';
$lang['scratchpad_err_unknown'] = 'Unknown scratchpad pad name';
$lang['scratchpad_err_unreadable'] = 'Scratchpad file is not readable';

View File

@@ -70,8 +70,17 @@ try {
if ($cmd === 'load') {
$text = '';
if (@is_file($resolved) && @is_readable($resolved)) {
$text = (string)io_readFile($resolved, false);
$exists = @is_file($resolved);
if ($exists) {
if (!@is_readable($resolved)) {
luxtools_scratchpad_json(500, ['ok' => false, 'error' => 'unreadable']);
}
$read = io_readFile($resolved, false);
if ($read === false) {
luxtools_scratchpad_json(500, ['ok' => false, 'error' => 'unreadable']);
}
$text = (string)$read;
}
luxtools_scratchpad_json(200, ['ok' => true, 'text' => $text]);
}

View File

@@ -88,8 +88,22 @@ class syntax_plugin_luxtools_scratchpad extends SyntaxPlugin
}
$text = '';
if (@is_file($filePath) && @is_readable($filePath)) {
$text = (string)io_readFile($filePath, false);
$exists = @is_file($filePath);
// If the scratchpad file is missing, render empty content. This allows
// creating the file via the inline editor without showing an error.
if ($exists) {
if (!@is_readable($filePath)) {
$this->renderError($renderer, 'scratchpad_err_unreadable');
return true;
}
$read = io_readFile($filePath, false);
if ($read === false) {
$this->renderError($renderer, 'scratchpad_err_unreadable');
return true;
}
$text = (string)$read;
}
if ($format === 'odt') {