]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
RateIt support (currently no recommendation engine yet)
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 rcs_id('$Id: MostPopular.php,v 1.25 2004-03-30 02:38:06 rurban 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.25 $");
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                      'sortby'   => 'hits',
50                      'info'     => false
51                     );
52     }
53     
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
58     function run($dbi, $argstr, &$request, $basepage) {
59         //$request->setArg('nocache','1');
60         extract($this->getArgs($argstr, $request));
61
62         $columns = $info ? explode(",", $info) : array();
63         array_unshift($columns, 'hits');
64
65         $pagelist = new PageList($columns, $exclude);
66
67         $pages = $dbi->mostPopular($limit,$sortby);
68         while ($page = $pages->next()) {
69             $hits = $page->get('hits');
70             // don't show pages with no hits if most popular pages
71             // wanted
72             if ($hits == 0 && $limit > 0)
73                 break;
74             $pagelist->addPage($page);
75         }
76         $pages->free();
77
78         if (! $noheader) {
79             if ($limit > 0) {
80                 $pagelist->setCaption(_("The %d most popular pages of this wiki:"));
81             } else {
82                 if ($limit < 0) {
83                     $pagelist->setCaption(_("The %d least popular pages of this wiki:"));
84                 } else {
85                     $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:"));
86                 }}
87         }
88
89         return $pagelist;
90     }
91 };
92
93 // $Log: not supported by cvs2svn $
94 // Revision 1.24  2004/03/01 13:48:46  rurban
95 // rename fix
96 // p[] consistency fix
97 //
98 // Revision 1.23  2004/02/17 12:11:36  rurban
99 // 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, ...)
100 //
101 // Revision 1.22  2003/01/18 21:48:56  carstenklapp
102 // Code cleanup:
103 // Reformatting & tabs to spaces;
104 // Added copyleft, getVersion, getDescription, rcs_id.
105 //
106
107 // Local Variables:
108 // mode: php
109 // tab-width: 8
110 // c-basic-offset: 4
111 // c-hanging-comment-ender-p: nil
112 // indent-tabs-mode: nil
113 // End:
114 ?>