2 rcs_id('$Id: RandomPage.php,v 1.8 2003-01-04 02:25:41 carstenklapp Exp $');
5 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
7 This file is part of PhpWiki.
9 PhpWiki is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 PhpWiki is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with PhpWiki; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 require_once('lib/PageList.php');
26 class WikiPlugin_RandomPage
30 return _("RandomPage");
33 function getDescription () {
34 return _("Displays a list of randomly chosen pages or redirects to a random page.");
37 function getVersion() {
38 return preg_replace("/[Revision: $]/", '',
42 function getDefaultArguments() {
43 return array('pages' => 1,
45 'hidename' => false, // only for pages=1
46 'exclude' => $this->default_exclude(),
50 function run($dbi, $argstr, $request) {
51 extract($this->getArgs($argstr, $request));
53 $allpages = $dbi->getAllPages();
55 $exclude = $exclude ? explode(",", $exclude) : array();
56 foreach ($exclude as $e) {
57 $_exclude []= trim($e);
60 while ($page = $allpages->next()) {
61 if (!in_array($page->getName(), $_exclude))
65 better_srand(); // Start with a good seed.
67 if ($pages == 1 && $pagearray) {
68 $page = $pagearray[array_rand($pagearray)];
70 $request->redirect(WikiURL($page, false, 'absurl')); // noreturn
72 return WikiLink($page, false, _("RandomPage"));
74 return WikiLink($page);
77 $pages = min( max(1, (int)$pages), 20, count($pagearray));
78 $pagelist = new PageList($info);
79 $shuffle = array_rand($pagearray, $pages);
80 foreach ($shuffle as $i)
81 $pagelist->addPage($pagearray[$i]);
85 function default_exclude() {
86 // Some useful default pages to exclude.
87 $default_exclude = 'RandomPage, HomePage, AllPages, RecentChanges, RecentEdits, FullRecentChanges';
88 foreach (explode(",", $default_exclude) as $e) {
89 $_exclude[] = gettext(trim($e));
91 return implode(", ", $_exclude);
96 $Log: not supported by cvs2svn $
103 // c-hanging-comment-ender-p: nil
104 // indent-tabs-mode: nil