]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RandomPage.php
Added some default excluded pagenames. Restored showname arg as hidename :-).
[SourceForge/phpwiki.git] / lib / plugin / RandomPage.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RandomPage.php,v 1.7 2002-01-31 01:34:02 carstenklapp Exp $');
3
4 require_once('lib/PageList.php');
5
6 /**
7  */
8 class WikiPlugin_RandomPage
9 extends WikiPlugin
10 {
11     function getName () {
12         return _("RandomPage");
13     }
14
15     function getDescription () {
16         return _("RandomPage");
17     }
18
19     function getDefaultArguments() {
20         return array('pages'        => 1,
21                      'redirect'     => false,
22                      'hidename'     => false, // only for pages=1
23                      'exclude'      => $this->default_exclude(),
24                      'info'         => '');
25     }
26
27     function run($dbi, $argstr, $request) {
28         extract($this->getArgs($argstr, $request));
29
30         $allpages = $dbi->getAllPages();
31
32         $exclude = $exclude ? explode(",", $exclude) : array();
33
34         while ($page = $allpages->next()) {
35             if (!in_array($page->getName(), $exclude))
36                 $pagearray[] = $page;
37         }
38
39         better_srand(); // Start with a good seed.
40
41         if ($pages == 1 && $pagearray) {
42             $page = $pagearray[array_rand($pagearray)];
43             if ($redirect)
44                 $request->redirect(WikiURL($page, false, 'absurl')); // noreturn
45             if ($hidename)
46                 return WikiLink($page, false, _("RandomPage"));
47             else
48                 return WikiLink($page);
49         }
50
51         $pages = min( max(1, (int)$pages), 20, count($pagearray));
52         $pagelist = new PageList($info);
53         $shuffle = array_rand($pagearray, $pages);
54         foreach ($shuffle as $i)
55             $pagelist->addPage($pagearray[$i]);
56         return $pagelist;
57     }
58
59     function default_exclude() {
60         // Some useful default pages to exclude.
61         $default_exclude = 'RandomPage,HomePage,AllPages,RecentChanges,RecentEdits,FullRecentChanges';
62         foreach (explode(",", $default_exclude) as $e) {
63             $_exclude[] = gettext($e);
64         }
65         return implode(",", $_exclude);
66     }
67 };
68
69
70 // Local Variables:
71 // mode: php
72 // tab-width: 8
73 // c-basic-offset: 4
74 // c-hanging-comment-ender-p: nil
75 // indent-tabs-mode: nil
76 // End:   
77 ?>