]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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$");
42     }
43
44     function getDefaultArguments() {
45         return array_merge
46             (
47              PageList::supportedArgs(),
48              array('pagename' => '[pagename]', // hackish
49                    //'exclude'  => '',
50                    'limit'    => 20, // limit <0 returns least popular pages
51                    'noheader' => 0,
52                    'sortby'   => '-hits',
53                    'info'     => false,
54                    //'paging'   => 'auto'
55                    ));
56     }
57     
58     // info arg allows multiple columns
59     // info=mtime,hits,summary,version,author,locked,minor
60     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
61     // sortby: only pagename or hits. mtime not!
62
63     function run($dbi, $argstr, &$request, $basepage) {
64         $args = $this->getArgs($argstr, $request);
65         extract($args);
66         if (strstr($sortby,'mtime')) {
67             trigger_error(_("sortby=mtime not supported with MostPopular"),
68                           E_USER_WARNING);
69             $sortby = '';
70         }
71         $columns = $info ? explode(",", $info) : array();
72         array_unshift($columns, 'hits');
73         
74         if (! $request->getArg('count')) {
75             //$args['count'] = $dbi->numPages(false,$exclude);
76             $allpages = $dbi->mostPopular(0, $sortby);
77             $args['count'] = $allpages->count();
78         } else {
79             $args['count'] = $request->getArg('count');
80         }
81         //$dbi->touch();
82         $pages = $dbi->mostPopular($limit, $sortby);
83         $pagelist = new PageList($columns, $exclude, $args);
84         while ($page = $pages->next()) {
85             $hits = $page->get('hits');
86             // don't show pages with no hits if most popular pages
87             // wanted
88             if ($hits == 0 && $limit > 0) {
89                 break;
90             }
91             $pagelist->addPage($page);
92         }
93         $pages->free();
94
95         if (! $noheader) {
96             if ($limit > 0) {
97                 $pagelist->setCaption(_("The %d most popular pages of this wiki:"));
98             } else {
99                 if ($limit < 0) {
100                     $pagelist->setCaption(_("The %d least popular pages of this wiki:"));
101                 } else {
102                     $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:"));
103                 }}
104         }
105
106         return $pagelist;
107     }
108 };
109
110 // $Log: not supported by cvs2svn $
111 // Revision 1.31  2004/11/23 15:17:19  rurban
112 // better support for case_exact search (not caseexact for consistency),
113 // plugin args simplification:
114 //   handle and explode exclude and pages argument in WikiPlugin::getArgs
115 //     and exclude in advance (at the sql level if possible)
116 //   handle sortby and limit from request override in WikiPlugin::getArgs
117 // ListSubpages: renamed pages to maxpages
118 //
119 // Revision 1.30  2004/10/14 19:19:34  rurban
120 // loadsave: check if the dumped file will be accessible from outside.
121 // and some other minor fixes. (cvsclient native not yet ready)
122 //
123 // Revision 1.29  2004/09/25 16:33:52  rurban
124 // add support for all PageList options
125 //
126 // Revision 1.28  2004/04/20 18:10:55  rurban
127 // config refactoring:
128 //   FileFinder is needed for WikiFarm scripts calling index.php
129 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
130 //   added PHPWIKI_DIR smart-detection code (Theme finder)
131 //   moved FileFind to lib/FileFinder.php
132 //   cleaned lib/config.php
133 //
134 // Revision 1.27  2004/04/20 00:06:53  rurban
135 // paging support
136 //
137 // Revision 1.26  2004/04/18 01:34:21  rurban
138 // protect most_popular from sortby=mtime
139 //
140 // Revision 1.25  2004/03/30 02:38:06  rurban
141 // RateIt support (currently no recommendation engine yet)
142 //
143 // Revision 1.24  2004/03/01 13:48:46  rurban
144 // rename fix
145 // p[] consistency fix
146 //
147 // Revision 1.23  2004/02/17 12:11:36  rurban
148 // 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, ...)
149 //
150 // Revision 1.22  2003/01/18 21:48:56  carstenklapp
151 // Code cleanup:
152 // Reformatting & tabs to spaces;
153 // Added copyleft, getVersion, getDescription, rcs_id.
154 //
155
156 // Local Variables:
157 // mode: php
158 // tab-width: 8
159 // c-basic-offset: 4
160 // c-hanging-comment-ender-p: nil
161 // indent-tabs-mode: nil
162 // End:
163 ?>