]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PopularTags.php
getName should not translate
[SourceForge/phpwiki.git] / lib / plugin / PopularTags.php
1 <?php
2
3 /*
4  * Copyright 2007 Reini Urban
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /* Usage:
24  *   <<PopularTags>>
25  */
26
27 require_once 'lib/PageList.php';
28
29 class WikiPlugin_PopularTags
30     extends WikiPlugin
31 {
32     // get list of categories sorted by number of backlinks
33     private function cmp_by_count($a, $b)
34     {
35         if ($a['count'] == $b['count']) return 0;
36         return $a['count'] < $b['count'] ? 1 : -1;
37     }
38
39     function getDescription()
40     {
41         return _("List the most popular tags.");
42     }
43
44     function getDefaultArguments()
45     {
46         return array('pagename' => '[pagename]',
47             'limit' => 10,
48             'mincount' => 5,
49             'noheader' => 0,
50         );
51     }
52
53     function run($dbi, $argstr, &$request, $basepage)
54     {
55         $args = $this->getArgs($argstr, $request);
56         extract($args);
57
58         $maincat = $dbi->getPage(_("CategoryCategory"));
59         $bi = $maincat->getBackLinks(false);
60         $bl = array();
61         while ($b = $bi->next()) {
62             $name = $b->getName();
63             if (preg_match("/^" . _("Template") . "/", $name)) continue;
64             $pages = $b->getBackLinks(false);
65             $bl[] = array('name' => $name,
66                 'count' => $pages->count());
67         }
68
69         usort($bl, array($this, 'cmp_by_count'));
70         $html = HTML::ul();
71         $i = 0;
72         foreach ($bl as $b) {
73             $i++;
74             $name = $b['name'];
75             $count = $b['count'];
76             if ($count < $mincount) break;
77             if ($i > $limit) break;
78             $wo = preg_replace("/^(" . _("Category") . "|"
79                 . _("Topic") . ")/", "", $name);
80             $wo = HTML(HTML::span($wo), HTML::raw("&nbsp;"), HTML::small("(" . $count . ")"));
81             $link = WikiLink($name, 'auto', $wo);
82             $html->pushContent(HTML::li($link));
83         }
84         return $html;
85     }
86 }
87
88 // Local Variables:
89 // mode: php
90 // tab-width: 8
91 // c-basic-offset: 4
92 // c-hanging-comment-ender-p: nil
93 // indent-tabs-mode: nil
94 // End: