|
CVS: phpwiki/lib/plugin RandomPage.php,1.12,1.13: msg#00134web.wiki.phpwiki.checkins
Update of /cvsroot/phpwiki/phpwiki/lib/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8268 Modified Files: RandomPage.php Log Message: deprecate pages, replaced by numpages; use complicated transition code; improved pagelist args support Index: RandomPage.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/RandomPage.php,v retrieving revision 1.12 retrieving revision 1.13 diff -u -2 -b -p -d -r1.12 -r1.13 --- RandomPage.php 25 Nov 2004 08:30:15 -0000 1.12 +++ RandomPage.php 25 Jan 2005 08:09:26 -0000 1.13 @@ -2,5 +2,5 @@ rcs_id('$Id$'); /** - Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam + Copyright 1999,2000,2001,2002,2005 $ThePhpWikiProgrammingTeam This file is part of PhpWiki. @@ -23,4 +23,8 @@ rcs_id('$Id$'); require_once('lib/PageList.php'); +/** + * With 1.3.11 the "pages" argument was renamed to "numpages". + * action=upgrade should deal with pages containing RandomPage modified earlier than 2005-01-24 + */ class WikiPlugin_RandomPage extends WikiPlugin @@ -40,40 +44,52 @@ extends WikiPlugin function getDefaultArguments() { - return array('pages' => 1, + return array_merge + ( + PageList::supportedArgs(), + array('numpages' => 20, // was pages + 'pages' => false, // deprecated 'redirect' => false, - 'hidename' => false, // only for pages=1 + 'hidename' => false, // only for numpages=1 'exclude' => $this->default_exclude(), - 'info' => ''); + 'info' => '')); } function run($dbi, $argstr, &$request, $basepage) { - extract($this->getArgs($argstr, $request)); + $args = $this->getArgs($argstr, $request); + extract($args); - $allpages = $dbi->getAllPages(); - $_exclude = $exclude ? explode(",", $exclude) : array(); - while ($page = $allpages->next()) { - if (!in_array($page->getName(), $_exclude)) - $pagearray[] = $page; + // fix deprecated arg + if (is_integer($pages)) { + $numpages = $pages; + $pages = false; + // fix new pages handling in arg preprozessor. + } elseif (is_array($pages)) { + $numpages = (int)$pages[0]; + if ($numpages > 0 and !$dbi->isWikiPage($numpages)) $pages = false; + else $numpages = 1; } + $allpages = $dbi->getAllPages(false, $sortby, $limit, $exclude); + $pagearray = $allpages->asArray(); better_srand(); // Start with a good seed. - if ($pages == 1 && $pagearray) { + if (($numpages == 1) && $pagearray) { $page = $pagearray[array_rand($pagearray)]; + $pagename = $page->getName(); if ($redirect) - $request->redirect(WikiURL($page, false, 'absurl')); // noreturn + $request->redirect(WikiURL($pagename, false, 'absurl')); // noreturn if ($hidename) - return WikiLink($page, false, _("RandomPage")); + return WikiLink($pagename, false, _("RandomPage")); else - return WikiLink($page); + return WikiLink($pagename); } - $pages = min( max(1, (int)$pages), 20, count($pagearray)); - $pagelist = new PageList($info); - $shuffle = array_rand($pagearray, $pages); - if (is_array($pages)) { + $numpages = min( max(1, (int) $numpages), 20, count($pagearray)); + $pagelist = new PageList($info, $exclude, $args); + $shuffle = array_rand($pagearray, $numpages); + if (is_array($shuffle)) { foreach ($shuffle as $i) if (isset($pagearray[$i])) $pagelist->addPage($pagearray[$i]); - } else { // if $pages = 1 + } else { // if $numpages = 1 if (isset($pagearray[$shuffle])) $pagelist->addPage($pagearray[$shuffle]); @@ -86,7 +102,7 @@ extends WikiPlugin $default_exclude = 'RandomPage,HomePage,AllPages,RecentChanges,RecentEdits,FullRecentChanges'; foreach (explode(",", $default_exclude) as $e) { - $_exclude[] = gettext($e); + $exclude[] = gettext($e); } - return implode(",", $_exclude); + return implode(",", $exclude); } }; @@ -94,4 +110,7 @@ extends WikiPlugin // $Log$ +// Revision 1.13 2005/01/25 08:09:26 rurban +// deprecate pages, replaced by numpages; use complicated transition code; improved pagelist args support +// // Revision 1.12 2004/11/25 08:30:15 rurban // dont mess around with spaces ------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | CVS: phpwiki/lib/plugin _WikiTranslation.php,1.14,1.15: 00134, Reini Urban |
|---|---|
| Next by Date: | CVS: phpwiki/pgsrc ReleaseNotes,1.49,1.50: 00134, Reini Urban |
| Previous by Thread: | CVS: phpwiki/lib/plugin _WikiTranslation.php,1.14,1.15i: 00134, Reini Urban |
| Next by Thread: | CVS: phpwiki/pgsrc ReleaseNotes,1.49,1.50: 00134, Reini Urban |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |