1, 'redirect' => false, 'hidename' => false, // only for pages=1 'exclude' => $this->default_exclude(), 'info' => ''); } function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); $allpages = $dbi->getAllPages(); $_exclude = $exclude ? explode(",", $exclude) : array(); while ($page = $allpages->next()) { if (!in_array($page->getName(), $_exclude)) $pagearray[] = $page; } better_srand(); // Start with a good seed. if ($pages == 1 && $pagearray) { $page = $pagearray[array_rand($pagearray)]; if ($redirect) $request->redirect(WikiURL($page, false, 'absurl')); // noreturn if ($hidename) return WikiLink($page, false, _("RandomPage")); else return WikiLink($page); } $pages = min( max(1, (int)$pages), 20, count($pagearray)); $pagelist = new PageList($info); $shuffle = array_rand($pagearray, $pages); if (is_array($pages)) { foreach ($shuffle as $i) if (isset($pagearray[$i])) $pagelist->addPage($pagearray[$i]); } else { // if $pages = 1 if (isset($pagearray[$shuffle])) $pagelist->addPage($pagearray[$shuffle]); } return $pagelist; } function default_exclude() { // Some useful default pages to exclude. $default_exclude = 'RandomPage,HomePage,AllPages,RecentChanges,RecentEdits,FullRecentChanges'; foreach (explode(",", $default_exclude) as $e) { $_exclude[] = gettext($e); } return implode(",", $_exclude); } }; // $Log: not supported by cvs2svn $ // Revision 1.11 2004/10/04 23:42:42 rurban // fix for pages=1 // // Revision 1.10 2004/02/17 12:11:36 rurban // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...) // // Revision 1.9 2003/01/18 22:01:43 carstenklapp // Code cleanup: // Reformatting & tabs to spaces; // Added copyleft, getVersion, getDescription, rcs_id. // // Revision 1.8 2003/01/04 02:25:41 carstenklapp // Added copyleft and plugin description & version, tweaked default // exclude list code to allow spaces (a cosmetic workaround for // PluginManager plugin). // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>