├── plugin.info.txt ├── README └── action.php /plugin.info.txt: -------------------------------------------------------------------------------- 1 | base Random Page 2 | author Pete Prodoehl 3 | email pete@2xlnetworks.com 4 | date 2012-04-19 5 | name randompage plugin 6 | desc Pick a random Page and display it like MediaWiki 7 | url http://2xlnetworks.com/ 8 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | I wanted to use the Random Page plugin for DokuWiki: 3 | 4 | http://www.dokuwiki.org/plugin:random_page 5 | 6 | But it didn't work. 7 | 8 | So I poked at it a bit... and now it works. 9 | 10 | (I even fixed the URLs it returns.) 11 | 12 | Jean Marc Massou did all the original code, I just cleaned it up so it would work. 13 | 14 | I did email him about it, but I figured I should also publish the code in case someone else wanted to use it. 15 | 16 | I also changed it from being named 'random_page' to 'randompage' 17 | 18 | (Hooray for open source.) 19 | 20 | This code is released under the GPL. 21 | 22 | Pete Prodoehl 23 | pete@rasterweb.net 24 | http://rasterweb.net/raster/ 25 | 26 | -------------------------------------------------------------------------------- /action.php: -------------------------------------------------------------------------------- 1 | and Jean Marc Massou 5 | */ 6 | 7 | require_once(DOKU_PLUGIN.'action.php'); 8 | 9 | class action_plugin_randompage extends Dokuwiki_Action_Plugin { 10 | 11 | 12 | /** 13 | * Register its handlers with the dokuwiki's event controller 14 | */ 15 | function register(Doku_Event_Handler $controller) { 16 | $controller->register_hook('ACTION_HEADERS_SEND', 'BEFORE', $this, 'init', 'header'); 17 | } 18 | 19 | 20 | function init(Doku_Event $event, $args) 21 | { 22 | // Catch the good request 23 | if ($_REQUEST['do'] == 'randompage'|| $_REQUEST['do'] == 'nsrandompage' ) { 24 | // On efface les headers par defaut 25 | if ($args == 'header') { 26 | $this->action_randompage($event, $args); 27 | } 28 | 29 | } 30 | } 31 | 32 | 33 | function action_randompage(Doku_Event $event, $args) { 34 | 35 | global $conf; 36 | global $ID; 37 | global $INFO; 38 | $data = array(); 39 | $dir = $conf['savedir']; 40 | 41 | $data = file ($dir.'/index/page.idx'); 42 | 43 | //if current page is in 44 | function isCurNS($value){ 45 | global $INFO; 46 | return stripos($value, $INFO['namespace'])===0 ? true : false; 47 | } 48 | 49 | if ($INFO['namespace']!=null && $_REQUEST['do'] == 'nsrandompage' ) { 50 | $data=array_filter($data,"isCurNS" ); 51 | } 52 | 53 | //We loops through ten random page... 54 | $i = 1; 55 | while ($i <= 10 & $i <> "ok"): 56 | //echo $i; 57 | $i++; 58 | 59 | $id = rtrim($data[array_rand($data, 1)]); 60 | $testACL = auth_aclcheck($id,$_SERVER['REMOTE_USER'],$USERINFO['grps']); 61 | 62 | if (($testACL > 1) and (file_exists(wikiFN($id)))){ 63 | $i="ok"; 64 | //echo $id; 65 | } 66 | 67 | endwhile; 68 | 69 | if ($testACL < 1){ 70 | $id = $ID; 71 | } 72 | 73 | header("Location: ".wl($id,'',true)); 74 | //echo wl($page,'',true); 75 | exit(); 76 | 77 | } 78 | 79 | //Function from Php manual to get a random number in a Array 80 | function array_rand($array, $lim=1) { 81 | mt_srand((double) microtime() * 1000000); 82 | for($a=0; $a<=$lim; $a++) { 83 | $num[] = mt_srand(0, count($array)-1); 84 | } 85 | return @$num; 86 | } 87 | 88 | } 89 | --------------------------------------------------------------------------------