4 * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5 * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
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 along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once 'lib/PageList.php';
26 class WikiPlugin_MostPopular
31 return _("MostPopular");
34 function getDescription()
36 return _("List the most popular pages.");
39 function getDefaultArguments()
43 PageList::supportedArgs(),
44 array('pagename' => '[pagename]', // hackish
46 'limit' => 20, // limit <0 returns least popular pages
54 // info arg allows multiple columns
55 // info=mtime,hits,summary,version,author,locked,minor
56 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
57 // sortby: only pagename or hits. mtime not!
59 function run($dbi, $argstr, &$request, $basepage)
61 $args = $this->getArgs($argstr, $request);
63 if (strstr($sortby, 'mtime')) {
64 trigger_error(_("sortby=mtime not supported with MostPopular"),
68 $columns = $info ? explode(",", $info) : array();
69 array_unshift($columns, 'hits');
71 if (!$request->getArg('count')) {
72 //$args['count'] = $dbi->numPages(false,$exclude);
73 $allpages = $dbi->mostPopular(0, $sortby);
74 $args['count'] = $allpages->count();
76 $args['count'] = $request->getArg('count');
79 $pages = $dbi->mostPopular($limit, $sortby);
80 $pagelist = new PageList($columns, $exclude, $args);
81 while ($page = $pages->next()) {
82 $hits = $page->get('hits');
83 // don't show pages with no hits if most popular pages wanted
84 if ($hits == 0 && $limit > 0) {
87 $pagelist->addPage($page);
93 $pagelist->setCaption(fmt("The %d most popular pages of this wiki:", $limit));
94 } elseif ($limit < 0) {
95 $pagelist->setCaption(fmt("The %d least popular pages of this wiki:", -$limit));
97 $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:"));
111 // c-hanging-comment-ender-p: nil
112 // indent-tabs-mode: nil