xref: /plugin/deletepageguard/README.md (revision 9a383d51b90310842e2a3f0f9d693178d0875b32)
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
111a97af9eSJohann Duscher* 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.
181a97af9eSJohann Duscher* **Pattern validation**: Real-time validation with detailed error messages for administrators.
191a97af9eSJohann Duscher* **Admin interface**: Dedicated admin page for testing and validating patterns.
201a97af9eSJohann Duscher* **Security features**: Built-in ReDoS protection and input sanitization.
21e39ccd63SJonny Dee
22e39ccd63SJonny Dee## Installation
23e39ccd63SJonny Dee
24e39ccd63SJonny Dee1. Copy the contents of this plugin directory into
25994617c9SJohann Duscher   `<dokuwiki>/lib/plugins/deletepageguard/`.
26e39ccd63SJonny Dee2. Ensure that the directory name matches the `base` value in
27994617c9SJohann Duscher   `plugin.info.txt` (here: `deletepageguard`).
28e39ccd63SJonny Dee3. Visit the **Configuration Manager** in your DokuWiki and adjust the
29994617c9SJohann Duscher   plugin settings under the “Delete Page Guard” section.
30e39ccd63SJonny Dee
31e39ccd63SJonny Dee## Configuration
32e39ccd63SJonny Dee
33e39ccd63SJonny DeeThe following options are available in the Configuration Manager:
34e39ccd63SJonny Dee
35e39ccd63SJonny Dee| Setting | Description |
36e39ccd63SJonny Dee|---|---|
371a97af9eSJohann Duscher| **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. Invalid patterns are automatically skipped with warnings shown to administrators. |
38e39ccd63SJonny 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`). |
39e39ccd63SJonny 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. |
40e39ccd63SJonny 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. |
41e39ccd63SJonny Dee
421a97af9eSJohann Duscher### Pattern Validation
431a97af9eSJohann Duscher
441a97af9eSJohann DuscherThe plugin includes comprehensive pattern validation:
451a97af9eSJohann Duscher
461a97af9eSJohann Duscher* **Real-time validation**: Invalid patterns are automatically detected when pages are saved
471a97af9eSJohann Duscher* **Administrator feedback**: Detailed error messages are shown to administrators when invalid patterns are encountered
481a97af9eSJohann Duscher* **Admin interface**: Visit **Admin → Delete Page Guard** to test and validate patterns before saving them to configuration
491a97af9eSJohann Duscher* **Security protection**: Built-in protection against ReDoS (Regular Expression Denial of Service) attacks
501a97af9eSJohann Duscher
51e39ccd63SJonny Dee### Pattern examples
52e39ccd63SJonny Dee
53e39ccd63SJonny Dee* `^users:` – protect all pages in the `users` namespace.
540da69785SJohann Duscher* `^users:[^:]+:start$` – protect every user's landing page named `start` under `users:<username>`.
550da69785SJohann Duscher* `^projects:.*$` – protect everything in the `projects` namespace.
560da69785SJohann Duscher* `^private/.*\.txt$` – when matching against file paths, protect any `.txt` file in the `private` directory.
57e39ccd63SJonny Dee
58e39ccd63SJonny Dee## How it works
59e39ccd63SJonny Dee
600da69785SJohann 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.
610da69785SJohann Duscher
620da69785SJohann Duscher## Security Features
630da69785SJohann Duscher
640da69785SJohann Duscher* **Regex Validation**: All regular expressions are validated for syntax before use.
650da69785SJohann Duscher* **ReDoS Protection**: Basic protection against Regular Expression Denial of Service attacks through pattern complexity checks and execution timeouts.
660da69785SJohann Duscher* **Input Sanitization**: User input is properly sanitized and validated.
67e39ccd63SJonny Dee
68c176b8b3SJohann Duscher## Development
69c176b8b3SJohann Duscher
70c176b8b3SJohann Duscher### Developer Testing
71c176b8b3SJohann Duscher
72c176b8b3SJohann DuscherThe plugin includes a comprehensive test suite for developers:
73c176b8b3SJohann Duscher
74c176b8b3SJohann Duscher```bash
75c176b8b3SJohann Duscher# Run all tests
76c176b8b3SJohann Duscherphp tests/test_runner.php
77c176b8b3SJohann Duscher
78c176b8b3SJohann Duscher# Check syntax of all files (if make is available)
79c176b8b3SJohann Duschermake check
80c176b8b3SJohann Duscher
81c176b8b3SJohann Duscher# See all available commands (if make is available)
82c176b8b3SJohann Duschermake help
83c176b8b3SJohann Duscher```
84c176b8b3SJohann Duscher
85c176b8b3SJohann DuscherThe test suite covers pattern validation, matching logic, security features, and edge cases without requiring a DokuWiki installation.
86c176b8b3SJohann Duscher
87*9a383d51SJohann Duscher### Release Process
88*9a383d51SJohann Duscher
89*9a383d51SJohann DuscherFor maintainers and contributors, see **[RELEASE.md](RELEASE.md)** for the complete release workflow including:
90*9a383d51SJohann Duscher- Version management and semantic versioning
91*9a383d51SJohann Duscher- Automated testing and validation
92*9a383d51SJohann Duscher- Distribution packaging
93*9a383d51SJohann Duscher- Git workflow and tagging
94*9a383d51SJohann Duscher- Quality assurance processes
95*9a383d51SJohann Duscher
96c176b8b3SJohann Duscher### Test Coverage
97c176b8b3SJohann Duscher
98*9a383d51SJohann Duscher- **Comprehensive tests** covering all core functionality
99*9a383d51SJohann Duscher- **Pattern validation** (syntax, ReDoS protection, length limits)
100*9a383d51SJohann Duscher- **Pattern matching** (simple and complex regex patterns)
101*9a383d51SJohann Duscher- **File path conversion** (absolute to relative paths)
102*9a383d51SJohann Duscher- **Configuration parsing** (multi-line patterns, different line endings)
103*9a383d51SJohann Duscher- **Security features** (escaping, unicode support, injection protection)
104*9a383d51SJohann Duscher- **Edge cases** (empty patterns, very long inputs)
105*9a383d51SJohann Duscher- **Real-world scenarios** (user pages, namespaces, file extensions)
106c176b8b3SJohann Duscher
107e39ccd63SJonny Dee## Compatibility
108e39ccd63SJonny Dee
1090da69785SJohann 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.
110e39ccd63SJonny Dee
111e39ccd63SJonny Dee## License
112e39ccd63SJonny Dee
113e39ccd63SJonny DeeThis plugin is released under the terms of the
114e39ccd63SJonny Dee[GNU General Public License v2](https://www.gnu.org/licenses/gpl-2.0.html).
115