]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
don't display the SQL dsn connection password
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 rcs_id('$Id: MostPopular.php,v 1.22 2003-01-18 21:48:56 carstenklapp Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  */
25
26 require_once('lib/PageList.php');
27
28 class WikiPlugin_MostPopular
29 extends WikiPlugin
30 {
31     function getName () {
32         return _("MostPopular");
33     }
34
35     function getDescription () {
36         return _("List the most popular pages.");
37     }
38
39     function getVersion() {
40         return preg_replace("/[Revision: $]/", '',
41                             "\$Revision: 1.22 $");
42     }
43
44     function getDefaultArguments() {
45         return array('pagename' => '[pagename]', // hackish
46                      'exclude'  => '',
47                      'limit'    => 20, // limit <0 returns least popular pages
48                      'noheader' => 0,
49                      'info'     => false
50                     );
51     }
52     // info arg allows multiple columns
53     // info=mtime,hits,summary,version,author,locked,minor
54     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
55
56     function run($dbi, $argstr, $request) {
57         extract($this->getArgs($argstr, $request));
58
59         $columns = $info ? explode(",", $info) : array();
60         array_unshift($columns, 'hits');
61
62         $pagelist = new PageList($columns, $exclude);
63
64         $pages = $dbi->mostPopular($limit);
65
66         while ($page = $pages->next()) {
67             $hits = $page->get('hits');
68             // don't show pages with no hits if most popular pages
69             // wanted
70             if ($hits == 0 && $limit > 0)
71                 break;
72             $pagelist->addPage($page);
73         }
74         $pages->free();
75
76         if (! $noheader) {
77             if ($limit > 0) {
78                 $pagelist->setCaption(_("The %d most popular pages of this wiki:"));
79             } else {
80                 if ($limit < 0) {
81                     $pagelist->setCaption(_("The %d least popular pages of this wiki:"));
82                 } else {
83                     $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:"));
84                 }}
85         }
86
87         return $pagelist;
88     }
89 };
90
91 // $Log: not supported by cvs2svn $
92
93 // Local Variables:
94 // mode: php
95 // tab-width: 8
96 // c-basic-offset: 4
97 // c-hanging-comment-ender-p: nil
98 // indent-tabs-mode: nil
99 // End:
100 ?>