1 <?php
2 if(!defined('DOKU_INC')) die();
3 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4 require_once(DOKU_PLUGIN.'action.php');
5 
6 
7 class action_plugin_notfound extends DokuWiki_Action_Plugin {
8 
9     function register(Doku_Event_Handler $controller) {
10         $controller->register_hook('ACTION_ACT_PREPROCESS','BEFORE', $this, '_check404');
11         $controller->register_hook('TPL_CONTENT_DISPLAY','BEFORE', $this, '_show404');
12     }
13 
14 
15     function _check404(Doku_Event $event , $param) {
16         if($event->data != 'show') return false;
17         global $INFO;
18         if($INFO['exists']) return false;
19 
20         $event->data = 'notfound';
21         $event->stopPropagation();
22         $event->preventDefault();
23         return true;
24     }
25 
26     function _show404(Doku_Event $event, $param) {
27         global $ACT;
28         if($ACT != 'notfound') return false;
29         $event->stopPropagation();
30         $event->preventDefault();
31 
32         global $ID;
33         $oldid = $ID;
34         $ID = $this->getConf('404page');
35         echo p_wiki_xhtml($ID,'',false);
36         $ID = $oldid;
37         $ACT='show';
38 
39         return true;
40     }
41 }
42