xref: /plugin/deletepageguard/README.md (revision e39ccd63478fc57ef8a8eb17b92c646766ac43fd)
1*e39ccd63SJonny Dee# Delete Guard Plugin for DokuWiki
2*e39ccd63SJonny Dee
3*e39ccd63SJonny DeeThe **Delete Guard** plugin prevents accidental or intentional deletion of
4*e39ccd63SJonny Deewikipages in your DokuWiki installation by blocking the “empty save”
5*e39ccd63SJonny Deeoperation when certain pages are protected. A page is considered for
6*e39ccd63SJonny Deeprotection when its ID or relative file path matches one or more
7*e39ccd63SJonny Deeregular expressions configured via the DokuWiki Configuration Manager.
8*e39ccd63SJonny Dee
9*e39ccd63SJonny Dee## Features
10*e39ccd63SJonny Dee
11*e39ccd63SJonny Dee* Prevents deletion via “empty save” on protected pages.
12*e39ccd63SJonny Dee* Supports any number of protection patterns using PCRE syntax.
13*e39ccd63SJonny Dee* Choose whether to match against the colon‑separated page ID or the
14*e39ccd63SJonny Dee  relative file system path.
15*e39ccd63SJonny Dee* Allow administrators and optional additional groups to bypass the
16*e39ccd63SJonny Dee  protection.
17*e39ccd63SJonny Dee* Optionally treat whitespace‑only content as empty.
18*e39ccd63SJonny Dee
19*e39ccd63SJonny Dee## Installation
20*e39ccd63SJonny Dee
21*e39ccd63SJonny Dee1. Copy the contents of this plugin directory into
22*e39ccd63SJonny Dee   `<dokuwiki>/lib/plugins/deleteguard/`.
23*e39ccd63SJonny Dee2. Ensure that the directory name matches the `base` value in
24*e39ccd63SJonny Dee   `plugin.info.txt` (here: `deleteguard`).
25*e39ccd63SJonny Dee3. Visit the **Configuration Manager** in your DokuWiki and adjust the
26*e39ccd63SJonny Dee   plugin settings under the “Delete Guard” section.
27*e39ccd63SJonny Dee
28*e39ccd63SJonny Dee## Configuration
29*e39ccd63SJonny Dee
30*e39ccd63SJonny DeeThe following options are available in the Configuration Manager:
31*e39ccd63SJonny Dee
32*e39ccd63SJonny Dee| Setting | Description |
33*e39ccd63SJonny Dee|---|---|
34*e39ccd63SJonny 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. |
35*e39ccd63SJonny 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`). |
36*e39ccd63SJonny 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. |
37*e39ccd63SJonny 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. |
38*e39ccd63SJonny Dee
39*e39ccd63SJonny Dee### Pattern examples
40*e39ccd63SJonny Dee
41*e39ccd63SJonny Dee* `^users:` – protect all pages in the `users` namespace.
42*e39ccd63SJonny Dee* `^users:[^:]+:start$` – protect every user’s landing page named `start` under `users:<username>`. |
43*e39ccd63SJonny Dee* `^projects:.*$` – protect everything in the `projects` namespace. |
44*e39ccd63SJonny Dee* `^private/.*\.txt$` – when matching against file paths, protect any `.txt` file in the `private` directory. |
45*e39ccd63SJonny Dee
46*e39ccd63SJonny Dee## How it works
47*e39ccd63SJonny Dee
48*e39ccd63SJonny DeeWhen a page is saved, DokuWiki triggers the
49*e39ccd63SJonny Dee`COMMON_WIKIPAGE_SAVE` event just before writing to disk. For normal
50*e39ccd63SJonny Deeedits, the plugin does nothing. However, when the new content is
51*e39ccd63SJonny Deeempty (after optional trimming) the plugin checks the configured
52*e39ccd63SJonny Deepatterns against the chosen target (ID or file path). If a match
53*e39ccd63SJonny Deeoccurs and the current user is not an administrator and not in one of
54*e39ccd63SJonny Deethe exempt groups, the plugin prevents the deletion by calling
55*e39ccd63SJonny Dee`$event->preventDefault()` and `$event->stopPropagation()` as
56*e39ccd63SJonny Deedocumented in DokuWiki’s event system【147016890842581†L304-L335】. An error message is displayed to
57*e39ccd63SJonny Deethe user informing them that deletion is not allowed.
58*e39ccd63SJonny Dee
59*e39ccd63SJonny Dee## Compatibility
60*e39ccd63SJonny Dee
61*e39ccd63SJonny DeeThis plugin hooks into the `COMMON_WIKIPAGE_SAVE` event, which was
62*e39ccd63SJonny Deeintroduced in DokuWiki release **“Detritus” (2016‑02‑24)** and is
63*e39ccd63SJonny Deemarked as preventable【699486104488352†L111-L139】. It has been tested for compatibility with
64*e39ccd63SJonny Deecurrent releases such as **Kaos 2024‑02‑06b** and **Librarian 2025‑05‑14**.
65*e39ccd63SJonny DeeThe plugin uses only public APIs and the documented event system,
66*e39ccd63SJonny Deeso it should continue to work with future versions as long as these
67*e39ccd63SJonny Deeevents remain available.
68*e39ccd63SJonny Dee
69*e39ccd63SJonny Dee## License
70*e39ccd63SJonny Dee
71*e39ccd63SJonny DeeThis plugin is released under the terms of the
72*e39ccd63SJonny Dee[GNU General Public License v2](https://www.gnu.org/licenses/gpl-2.0.html).