1<?php
2/**
3 * DokuWiki Plugin showlogin (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Oliver Geisen <oliver.geisen@kreisbote.de>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15
16require_once DOKU_PLUGIN.'action.php';
17
18class action_plugin_showlogin extends DokuWiki_Action_Plugin {
19
20    /**
21     * Register its handlers with the dokuwiki's event controller
22     */
23    public function register(Doku_Event_Handler $controller) {
24
25      # TPL_CONTENT_DISPLAY is called before and after content of wikipage is written to output buffer
26       $controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, 'handle_tpl_content_display');
27
28    }
29
30    /**
31     * Handle the event
32     */
33    public function handle_tpl_content_display(Doku_Event &$event, $param) {
34      global $ACT;
35
36      # If user is not logged in and access to page is denied, show login form
37      if (($ACT == 'denied') && (! $_SERVER['REMOTE_USER'])) {
38	$event->preventDefault(); // prevent "Access denied" page from showing
39	html_login(); // show login dialog instead
40      }
41      # .. or show regular access denied page
42    }
43
44}
45
46// vim:ts=4:sw=4:et:
47