]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
elseif
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 // $Id$
3 /*
4  * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5  * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
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.
13  *
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.
18  *
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.
22  */
23
24 require_once('lib/PageList.php');
25
26 class WikiPlugin_MostPopular
27 extends WikiPlugin
28 {
29     function getName () {
30         return _("MostPopular");
31     }
32
33     function getDescription () {
34         return _("List the most popular pages.");
35     }
36
37     function getDefaultArguments() {
38         return array_merge
39             (
40              PageList::supportedArgs(),
41              array('pagename' => '[pagename]', // hackish
42                    //'exclude'  => '',
43                    'limit'    => 20, // limit <0 returns least popular pages
44                    'noheader' => 0,
45                    'sortby'   => '-hits',
46                    'info'     => false,
47                    //'paging'   => 'auto'
48                    ));
49     }
50
51     // info arg allows multiple columns
52     // info=mtime,hits,summary,version,author,locked,minor
53     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
54     // sortby: only pagename or hits. mtime not!
55
56     function run($dbi, $argstr, &$request, $basepage) {
57             $args = $this->getArgs($argstr, $request);
58         extract($args);
59         if (strstr($sortby,'mtime')) {
60             trigger_error(_("sortby=mtime not supported with MostPopular"),
61                           E_USER_WARNING);
62             $sortby = '';
63         }
64         $columns = $info ? explode(",", $info) : array();
65         array_unshift($columns, 'hits');
66
67         if (! $request->getArg('count')) {
68             //$args['count'] = $dbi->numPages(false,$exclude);
69             $allpages = $dbi->mostPopular(0, $sortby);
70             $args['count'] = $allpages->count();
71         } else {
72             $args['count'] = $request->getArg('count');
73         }
74         //$dbi->touch();
75         $pages = $dbi->mostPopular($limit, $sortby);
76         $pagelist = new PageList($columns, $exclude, $args);
77         while ($page = $pages->next()) {
78             $hits = $page->get('hits');
79             // don't show pages with no hits if most popular pages wanted
80             if ($hits == 0 && $limit > 0) {
81                 break;
82             }
83             $pagelist->addPage($page);
84         }
85         $pages->free();
86
87         if (! $noheader) {
88             if ($limit > 0) {
89                 $pagelist->setCaption(fmt("The %d most popular pages of this wiki:", $limit));
90             } elseif ($limit < 0) {
91                 $pagelist->setCaption(fmt("The %d least popular pages of this wiki:", -$limit));
92             } else {
93                 $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:"));
94             }
95         }
96
97         return $pagelist;
98     }
99 };
100
101 // Local Variables:
102 // mode: php
103 // tab-width: 8
104 // c-basic-offset: 4
105 // c-hanging-comment-ender-p: nil
106 // indent-tabs-mode: nil
107 // End:
108 ?>