]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
redirect stderr to display the failing msg
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 rcs_id('$Id: MostPopular.php,v 1.29 2004-09-25 16:33:52 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.29 $");
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.28  2004/04/20 18:10:55  rurban
111 // config refactoring:
112 //   FileFinder is needed for WikiFarm scripts calling index.php
113 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
114 //   added PHPWIKI_DIR smart-detection code (Theme finder)
115 //   moved FileFind to lib/FileFinder.php
116 //   cleaned lib/config.php
117 //
118 // Revision 1.27  2004/04/20 00:06:53  rurban
119 // paging support
120 //
121 // Revision 1.26  2004/04/18 01:34:21  rurban
122 // protect most_popular from sortby=mtime
123 //
124 // Revision 1.25  2004/03/30 02:38:06  rurban
125 // RateIt support (currently no recommendation engine yet)
126 //
127 // Revision 1.24  2004/03/01 13:48:46  rurban
128 // rename fix
129 // p[] consistency fix
130 //
131 // Revision 1.23  2004/02/17 12:11:36  rurban
132 // 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, ...)
133 //
134 // Revision 1.22  2003/01/18 21:48:56  carstenklapp
135 // Code cleanup:
136 // Reformatting & tabs to spaces;
137 // Added copyleft, getVersion, getDescription, rcs_id.
138 //
139
140 // Local Variables:
141 // mode: php
142 // tab-width: 8
143 // c-basic-offset: 4
144 // c-hanging-comment-ender-p: nil
145 // indent-tabs-mode: nil
146 // End:
147 ?>