]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
from RecBackLinks submitted as sf.net patch by Cuthbert Cat.
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 rcs_id('$Id: MostPopular.php,v 1.20 2002-02-08 20:30:48 lakka 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                                                                                    // popular pages wanted
44                 break;
45             $pagelist->addPage($page);
46         }
47         $pages->free();
48         
49         if (! $noheader) {
50             if ($limit > 0) {
51                 $pagelist->setCaption(_("The %d most popular pages of this wiki:"));
52             } else {
53                         if ($limit < 0) {
54                                 $pagelist->setCaption(_("The %d least popular pages of this wiki:"));
55                         } else {
56                 $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:"));
57             }}
58         }
59
60         return $pagelist;
61     }
62 };
63
64 // Local Variables:
65 // mode: php
66 // tab-width: 8
67 // c-basic-offset: 4
68 // c-hanging-comment-ender-p: nil
69 // indent-tabs-mode: nil
70 // End:
71 ?>