1<?php
2/**
3 *
4 * @author     Szymon Olewniczak
5 */
6
7if(!defined('DOKU_INC')) die();
8
9
10class action_plugin_randompage2 extends DokuWiki_Action_Plugin {
11
12
13    public function register(Doku_Event_Handler $controller) {
14        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'do_randompage');
15    }
16
17    public function do_randompage(Doku_Event $event, $param) {
18        if($event->data !== 'randompage') return;
19        $event->preventDefault();
20
21        global $conf;
22        $dir = $conf['indexdir'];
23
24        $pages = file($dir.'/page.idx');
25        shuffle($pages);
26
27        foreach ($pages as $page) {
28            $page = trim($page);
29            if(!page_exists($page)) continue;
30            if(isHiddenPage($page)) continue;
31            if (auth_quickaclcheck($page)) {
32                send_redirect(wl($page, '', true, '&'));
33            }
34        }
35    }
36}
37