From 63285236242865b687316c17d3484054c1f83bf9 Mon Sep 17 00:00:00 2001 From: luxick Date: Fri, 9 Jan 2026 09:37:21 +0100 Subject: [PATCH] Additional error checking for scratchpads --- .github/copilot-instructions.md | 3 ++- lang/de/lang.php | 9 +++++++++ lang/en/lang.php | 1 + scratchpad.php | 13 +++++++++++-- syntax/scratchpad.php | 18 ++++++++++++++++-- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index bb76c47..a734bea 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -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 \ No newline at end of file +- Use `php -l ` to check for syntax errors. +- Consider The official documentation for writing dokuwiki plugins: https://www.dokuwiki.org/devel:plugins \ No newline at end of file diff --git a/lang/de/lang.php b/lang/de/lang.php index b504557..a1d7cd9 100644 --- a/lang/de/lang.php +++ b/lang/de/lang.php @@ -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'; diff --git a/lang/en/lang.php b/lang/en/lang.php index 8f73c56..9e6f62b 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -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'; diff --git a/scratchpad.php b/scratchpad.php index 4902f25..83cab96 100644 --- a/scratchpad.php +++ b/scratchpad.php @@ -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]); } diff --git a/syntax/scratchpad.php b/syntax/scratchpad.php index fa0d857..1566728 100644 --- a/syntax/scratchpad.php +++ b/syntax/scratchpad.php @@ -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') {