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