diff --git a/.github/workflows/dokuwiki.yml b/.github/workflows/dokuwiki.yml deleted file mode 100644 index 8268881..0000000 --- a/.github/workflows/dokuwiki.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: DokuWiki Default Tasks -on: - push: - pull_request: - schedule: - - cron: '58 2 25 * *' - - -jobs: - all: - uses: dokuwiki/github-action/.github/workflows/all.yml@main diff --git a/.github/workflows/instructions.md b/.github/workflows/instructions.md new file mode 100644 index 0000000..bb76c47 --- /dev/null +++ b/.github/workflows/instructions.md @@ -0,0 +1,4 @@ +# 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 diff --git a/README b/README index b0cdb89..34dac86 100644 --- a/README +++ b/README @@ -12,6 +12,21 @@ will not work! Syntax: {{files>...}} +Scratchpad (shared, file-backed, no page revisions): + {{scratchpad>...}} + +The scratchpad is resolved via the "scratchpad_paths" setting. + +Each scratchpad entry is a full filesystem path to a file (including extension), +followed by an alias line that defines the pad name used in the wiki. + +Example: + /var/lib/dokuwiki-scratchpads/startpad.txt + A> start + +Then use: + {{scratchpad>start}} + Please refer to http://www.dokuwiki.org/extensions for additional info on how to install extensions in DokuWiki. diff --git a/ScratchpadMap.php b/ScratchpadMap.php new file mode 100644 index 0000000..2c8165b --- /dev/null +++ b/ScratchpadMap.php @@ -0,0 +1,96 @@ + padname + * + * The next A> line assigns an alias for the previously listed file. + */ +class ScratchpadMap +{ + /** @var array */ + protected $map = []; + + /** + * @param string $config + */ + public function __construct($config) + { + $this->map = $this->parseConfig((string)$config); + } + + /** + * Resolve the given alias to a full file path. + * + * @param string $alias + * @return string + * @throws \Exception + */ + public function resolve($alias) + { + $alias = trim((string)$alias); + if ($alias === '') throw new \Exception('Empty alias'); + if (!isset($this->map[$alias])) { + throw new \Exception('Unknown scratchpad alias'); + } + return (string)$this->map[$alias]['path']; + } + + /** + * Return the parsed mapping. + * + * @return array + */ + public function getMap() + { + return $this->map; + } + + /** + * @param string $config + * @return array + */ + protected function parseConfig($config) + { + $map = []; + $lines = explode("\n", (string)$config); + + $lastFile = ''; + foreach ($lines as $line) { + $line = trim($line); + if ($line === '') continue; + + if (str_starts_with($line, 'A>')) { + $alias = trim(substr($line, 2)); + if ($alias === '' || $lastFile === '') continue; + $map[$alias] = [ + 'alias' => $alias, + 'path' => $lastFile, + ]; + continue; + } + + // Ignore W> lines for compatibility with the Path config style + if (str_starts_with($line, 'W>')) { + continue; + } + + // Treat as file path (no trailing slash enforced) + $filePath = Path::cleanPath($line, false); + if ($filePath === '' || str_ends_with($filePath, '/')) { + // Ignore invalid entries; they will not be resolvable + $lastFile = ''; + continue; + } + + $lastFile = $filePath; + } + + return $map; + } +} diff --git a/_test/ScratchpadMapTest.php b/_test/ScratchpadMapTest.php new file mode 100644 index 0000000..85707c0 --- /dev/null +++ b/_test/ScratchpadMapTest.php @@ -0,0 +1,43 @@ + start + +C:\\pads\\notes.md +A> notes +W> ignored + +\\\\server\\share\\pads\\team.txt +A> team +EOT + ); + + $this->assertEquals('/var/scratchpads/startpad.txt', $map->resolve('start')); + $this->assertEquals('C:/pads/notes.md', $map->resolve('notes')); + $this->assertEquals('\\\\server/share/pads/team.txt', $map->resolve('team')); + } + + public function testUnknownAliasThrows() + { + $map = new ScratchpadMap("/tmp/pad.txt\nA> pad\n"); + $this->expectExceptionMessageMatches('/Unknown scratchpad alias/'); + $map->resolve('nope'); + } +} diff --git a/admin/main.php b/admin/main.php index 4c86353..447f7d7 100644 --- a/admin/main.php +++ b/admin/main.php @@ -11,6 +11,7 @@ class admin_plugin_luxtools_main extends DokuWiki_Admin_Plugin /** @var string[] */ protected $configKeys = [ 'paths', + 'scratchpad_paths', 'allow_in_comments', 'defaults', 'extensions', @@ -51,6 +52,11 @@ class admin_plugin_luxtools_main extends DokuWiki_Admin_Plugin $paths = $INPUT->str('paths'); $paths = str_replace(["\r\n", "\r"], "\n", $paths); $newConf['paths'] = $paths; + + $scratchpadPaths = $INPUT->str('scratchpad_paths'); + $scratchpadPaths = str_replace(["\r\n", "\r"], "\n", $scratchpadPaths); + $newConf['scratchpad_paths'] = $scratchpadPaths; + $newConf['allow_in_comments'] = (int)$INPUT->bool('allow_in_comments'); $newConf['defaults'] = $INPUT->str('defaults'); $newConf['extensions'] = $INPUT->str('extensions'); @@ -88,6 +94,12 @@ class admin_plugin_luxtools_main extends DokuWiki_Admin_Plugin echo ''; echo '
'; + // scratchpad_paths: multiline textarea + $scratchpadPaths = (string)$this->getConf('scratchpad_paths'); + echo '
'; + // allow_in_comments $checked = $this->getConf('allow_in_comments') ? ' checked="checked"' : ''; echo '