1<?php
2
3/**
4 * DokuWiki Plugin log404 (Action Component)
5 *
6 * @license GPL 3 http://www.gnu.org/licenses/gpl-3.0.html
7 * @author  Sam Wilson <sam@samwilson.id.au>
8 */
9// must be run within Dokuwiki
10if (!defined('DOKU_INC'))
11    die();
12
13class action_plugin_log404 extends DokuWiki_Action_Plugin {
14
15    /**
16     * Registers a callback function for the PREPROCESS event.
17     *
18     * @param Doku_Event_Handler $controller DokuWiki's event controller object
19     * @return void
20     */
21    public function register(Doku_Event_Handler $controller) {
22        $controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'handle');
23    }
24
25    /**
26     * Write to the 404 log file if this is a non-existant page
27     *
28     * @param Doku_Event $event  Not used
29     * @param mixed      $param  Not used
30     * @return void
31     */
32    public function handle(Doku_Event &$event, $param) {
33        global $INFO, $ACT, $ID;
34        $validActions = array('show', 'notfound');
35        if ($INFO['exists'] || !in_array($ACT, $validActions)) {
36            return;
37        }
38        $log = $this->loadHelper('log404');
39        $log->save($ID);
40    }
41
42}
43
44// vim:ts=4:sw=4:et:
45