]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
Plugin now traps the include error when phpweather.php is not installed. Tested with...
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 rcs_id('$Id: MostPopular.php,v 1.21 2002-08-27 21:51:31 rurban Exp $');
3 /**
4  */
5
6 require_once('lib/PageList.php');
7
8 class WikiPlugin_MostPopular
9 extends WikiPlugin
10 {
11     function getName () {
12         return _("MostPopular");
13     }
14
15     function getDescription () {
16         return _("List the most popular pages");
17     }
18
19     function getDefaultArguments() {
20         return array('pagename'     => '[pagename]', // hackish
21                      'exclude'      => '',
22                      'limit'        => 20, // limit <0 returns least popular pages
23                      'noheader'     => 0,
24                      'info'         => false
25                     );
26     }
27     // info arg allows multiple columns info=mtime,hits,summary,version,author,locked,minor
28     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
29
30     function run($dbi, $argstr, $request) {
31         extract($this->getArgs($argstr, $request));
32
33         $columns = $info ? explode(",", $info) : array();
34         array_unshift($columns, 'hits');
35         
36         $pagelist = new PageList($columns, $exclude);
37
38         $pages = $dbi->mostPopular($limit);
39
40         while ($page = $pages->next()) {
41             $hits = $page->get('hits');
42             if ($hits == 0 && $limit > 0)  // don't show pages with no hits if most
43                 break;                     // popular pages wanted
44             $pagelist->addPage($page);
45         }
46         $pages->free();
47         
48         if (! $noheader) {
49             if ($limit > 0) {
50                 $pagelist->setCaption(_("The %d most popular pages of this wiki:"));
51             } else {
52                 if ($limit < 0) {
53                     $pagelist->setCaption(_("The %d least popular pages of this wiki:"));
54                 } else {
55                     $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:"));
56                 }}
57         }
58         
59         return $pagelist;
60     }
61 };
62
63 // Local Variables:
64 // mode: php
65 // tab-width: 8
66 // c-basic-offset: 4
67 // c-hanging-comment-ender-p: nil
68 // indent-tabs-mode: nil
69 // End:
70 ?>