]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RandomPage.php
added exclude pages and include_self args
[SourceForge/phpwiki.git] / lib / plugin / RandomPage.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RandomPage.php,v 1.4 2002-01-30 22:45:33 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                      'showname'     => false,
22                      'pagename'     => '[pagename]', // hackish
23                      'exclude'      => '',
24                      'include_self' => 0, // hackish
25                      'info'         => '');
26     }
27
28     function run($dbi, $argstr, $request) {
29         extract($this->getArgs($argstr, $request));
30
31         $allpages = $dbi->getAllPages();
32
33         while ($page = $allpages->next())
34             $pagearray[] = $page;
35
36         better_srand(); // Start with a good seed.
37
38         global $Theme;
39         if ($pages < 2) {
40             $page = $pagearray[array_rand($pagearray)];
41             if (($showname == 'true') || ($showname == 1))
42                 return $Theme->linkExistingWikiWord($page->getName());
43             else
44                 return $Theme->linkExistingWikiWord($page->getName(), _("RandomPage"));
45         } else {
46             if ($pages > 20)
47                 $pages = 20;
48             $PageList = new PageList();
49             $this->_init($pagename, &$PageList, $info, $exclude, $include_self);
50
51             while ($PageList->getTotal() < $pages) {
52                 $PageList->addPage($pagearray[array_rand($pagearray)]);
53             }
54             return $PageList->getContent();
55         }
56     }
57
58     function _init(&$page, &$pagelist, $info = '', $exclude = '', $include_self = '') {
59         if ($info)
60             foreach (explode(",", $info) as $col)
61                 $pagelist->insertColumn($col);
62
63         if ($exclude)
64             foreach (explode(",", $exclude) as $excludepage)
65                 $pagelist->excludePageName($excludepage);
66         if (!$include_self)
67             $pagelist->excludePageName($page);
68    }
69
70 };
71
72
73 // Local Variables:
74 // mode: php
75 // tab-width: 8
76 // c-basic-offset: 4
77 // c-hanging-comment-ender-p: nil
78 // indent-tabs-mode: nil
79 // End:   
80 ?>