]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
better support for case_exact search (not caseexact for consistency),
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 rcs_id('$Id: MostPopular.php,v 1.31 2004-11-23 15:17:19 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.31 $");
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);
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             $pagelist->addPage($page);
91         }
92         $pages->free();
93
94         if (! $noheader) {
95             if ($limit > 0) {
96                 $pagelist->setCaption(_("The %d most popular pages of this wiki:"));
97             } else {
98                 if ($limit < 0) {
99                     $pagelist->setCaption(_("The %d least popular pages of this wiki:"));
100                 } else {
101                     $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:"));
102                 }}
103         }
104
105         return $pagelist;
106     }
107 };
108
109 // $Log: not supported by cvs2svn $
110 // Revision 1.30  2004/10/14 19:19:34  rurban
111 // loadsave: check if the dumped file will be accessible from outside.
112 // and some other minor fixes. (cvsclient native not yet ready)
113 //
114 // Revision 1.29  2004/09/25 16:33:52  rurban
115 // add support for all PageList options
116 //
117 // Revision 1.28  2004/04/20 18:10:55  rurban
118 // config refactoring:
119 //   FileFinder is needed for WikiFarm scripts calling index.php
120 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
121 //   added PHPWIKI_DIR smart-detection code (Theme finder)
122 //   moved FileFind to lib/FileFinder.php
123 //   cleaned lib/config.php
124 //
125 // Revision 1.27  2004/04/20 00:06:53  rurban
126 // paging support
127 //
128 // Revision 1.26  2004/04/18 01:34:21  rurban
129 // protect most_popular from sortby=mtime
130 //
131 // Revision 1.25  2004/03/30 02:38:06  rurban
132 // RateIt support (currently no recommendation engine yet)
133 //
134 // Revision 1.24  2004/03/01 13:48:46  rurban
135 // rename fix
136 // p[] consistency fix
137 //
138 // Revision 1.23  2004/02/17 12:11:36  rurban
139 // 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, ...)
140 //
141 // Revision 1.22  2003/01/18 21:48:56  carstenklapp
142 // Code cleanup:
143 // Reformatting & tabs to spaces;
144 // Added copyleft, getVersion, getDescription, rcs_id.
145 //
146
147 // Local Variables:
148 // mode: php
149 // tab-width: 8
150 // c-basic-offset: 4
151 // c-hanging-comment-ender-p: nil
152 // indent-tabs-mode: nil
153 // End:
154 ?>