1<?php
2
3if(!defined('DOKU_INC')) die();
4
5class action_plugin_disabledelete extends DokuWiki_Action_Plugin {
6	public function register(Doku_Event_Handler $controller) {
7        $controller->register_hook('COMMON_WIKIPAGE_SAVE', 'BEFORE', $this, 'handle_pagesave_after');
8    }
9
10    public function handle_pagesave_after(Doku_Event $event) {
11    	global $INFO;
12    	if (empty($INFO['isadmin'])) {
13	    	preg_match_all('/^={2,6}([^\n\r]+)={2,6}$/sm', $event->data['oldContent'], $oldHeadings);
14	    	preg_match_all('/^={2,6}([^\n\r]+)={2,6}$/sm', $event->data['newContent'], $newHeadings);
15
16	    	$missingHeadings = count(array_diff($oldHeadings[0], $newHeadings[0]));
17	    	$extraHeadings = count(array_diff($newHeadings[0], $oldHeadings[0]));
18
19	    	if (
20	    		$event->data['changeType'] == DOKU_CHANGE_TYPE_DELETE
21	    		|| ($event->data['changeType'] == DOKU_CHANGE_TYPE_EDIT && $missingHeadings > 0 && $extraHeadings == 0)
22	    	) {
23	    		$event->preventDefault();
24	    	}
25	    }
26    }
27}
28