xref: /plugin/deletepageguard/README.md (revision 0da697856a21f6e79666d7fe1c6a3ae059c82150)
1994617c9SJohann Duscher# Delete Page Guard for DokuWiki
2e39ccd63SJonny Dee
3994617c9SJohann DuscherThe **Delete Page Guard** plugin prevents accidental or intentional deletion of
4e39ccd63SJonny Deewikipages in your DokuWiki installation by blocking the “empty save”
5e39ccd63SJonny Deeoperation when certain pages are protected. A page is considered for
6e39ccd63SJonny Deeprotection when its ID or relative file path matches one or more
7e39ccd63SJonny Deeregular expressions configured via the DokuWiki Configuration Manager.
8e39ccd63SJonny Dee
9e39ccd63SJonny Dee## Features
10e39ccd63SJonny Dee
11e39ccd63SJonny Dee* Prevents deletion via “empty save” on protected pages.
12e39ccd63SJonny Dee* Supports any number of protection patterns using PCRE syntax.
13e39ccd63SJonny Dee* Choose whether to match against the colon‑separated page ID or the
14e39ccd63SJonny Dee  relative file system path.
15e39ccd63SJonny Dee* Allow administrators and optional additional groups to bypass the
16e39ccd63SJonny Dee  protection.
17e39ccd63SJonny Dee* Optionally treat whitespace‑only content as empty.
18e39ccd63SJonny Dee
19e39ccd63SJonny Dee## Installation
20e39ccd63SJonny Dee
21e39ccd63SJonny Dee1. Copy the contents of this plugin directory into
22994617c9SJohann Duscher   `<dokuwiki>/lib/plugins/deletepageguard/`.
23e39ccd63SJonny Dee2. Ensure that the directory name matches the `base` value in
24994617c9SJohann Duscher   `plugin.info.txt` (here: `deletepageguard`).
25e39ccd63SJonny Dee3. Visit the **Configuration Manager** in your DokuWiki and adjust the
26994617c9SJohann Duscher   plugin settings under the “Delete Page Guard” section.
27e39ccd63SJonny Dee
28e39ccd63SJonny Dee## Configuration
29e39ccd63SJonny Dee
30e39ccd63SJonny DeeThe following options are available in the Configuration Manager:
31e39ccd63SJonny Dee
32e39ccd63SJonny Dee| Setting | Description |
33e39ccd63SJonny Dee|---|---|
34e39ccd63SJonny Dee| **Protected page patterns** | List of PCRE regular expressions. Each line defines a pattern. When a page matches any pattern, non‑admin users cannot delete it by empty save. |
35e39ccd63SJonny Dee| **Match against** | Choose whether the patterns should match against the page ID (e.g. `users:john:home`) or the relative file path (e.g. `users/john/home.txt`). |
36e39ccd63SJonny Dee| **Extra groups allowed to delete** | Comma separated list of user groups that are allowed to delete protected pages, in addition to administrators. Leave empty to restrict deletion to admins only. |
37e39ccd63SJonny Dee| **Treat whitespace‑only pages as empty** | If enabled, pages containing only whitespace will be treated as empty and deletion will be blocked on protected pages. |
38e39ccd63SJonny Dee
39e39ccd63SJonny Dee### Pattern examples
40e39ccd63SJonny Dee
41e39ccd63SJonny Dee* `^users:` – protect all pages in the `users` namespace.
42*0da69785SJohann Duscher* `^users:[^:]+:start$` – protect every user's landing page named `start` under `users:<username>`.
43*0da69785SJohann Duscher* `^projects:.*$` – protect everything in the `projects` namespace.
44*0da69785SJohann Duscher* `^private/.*\.txt$` – when matching against file paths, protect any `.txt` file in the `private` directory.
45e39ccd63SJonny Dee
46e39ccd63SJonny Dee## How it works
47e39ccd63SJonny Dee
48*0da69785SJohann DuscherWhen a page is saved, DokuWiki triggers the `COMMON_WIKIPAGE_SAVE` event just before writing to disk. For normal edits, the plugin does nothing. However, when the new content is empty (after optional trimming) the plugin checks the configured patterns against the chosen target (ID or file path). If a match occurs and the current user is not an administrator and not in one of the exempt groups, the plugin prevents the deletion by calling `$event->preventDefault()` and `$event->stopPropagation()` as documented in DokuWiki's event system. An error message is displayed to the user informing them that deletion is not allowed.
49*0da69785SJohann Duscher
50*0da69785SJohann Duscher## Security Features
51*0da69785SJohann Duscher
52*0da69785SJohann Duscher* **Regex Validation**: All regular expressions are validated for syntax before use.
53*0da69785SJohann Duscher* **ReDoS Protection**: Basic protection against Regular Expression Denial of Service attacks through pattern complexity checks and execution timeouts.
54*0da69785SJohann Duscher* **Input Sanitization**: User input is properly sanitized and validated.
55e39ccd63SJonny Dee
56e39ccd63SJonny Dee## Compatibility
57e39ccd63SJonny Dee
58*0da69785SJohann DuscherThis plugin hooks into the `COMMON_WIKIPAGE_SAVE` event, which was introduced in DokuWiki release **"Detritus" (2016‑02‑24)** and is marked as preventable. It has been tested for compatibility with current releases such as **"Kaos" (2024‑02‑06b)**. The plugin uses only public APIs and the documented event system, so it should continue to work with future versions as long as these events remain available.
59e39ccd63SJonny Dee
60e39ccd63SJonny Dee## License
61e39ccd63SJonny Dee
62e39ccd63SJonny DeeThis plugin is released under the terms of the
63e39ccd63SJonny Dee[GNU General Public License v2](https://www.gnu.org/licenses/gpl-2.0.html).