4 * Copyright 2007 Reini Urban
6 * This file is part of PhpWiki.
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.
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.
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
27 require_once('lib/PageList.php');
29 class WikiPlugin_PopularTags
33 return _("PopularTags");
36 function getDescription () {
37 return _("List the most popular tags.");
40 function getDefaultArguments() {
41 return array('pagename' => '[pagename]',
48 function run($dbi, $argstr, &$request, $basepage) {
49 $args = $this->getArgs($argstr, $request);
52 $maincat = $dbi->getPage(_("CategoryCategory"));
53 $bi = $maincat->getBackLinks(false);
55 while ($b = $bi->next()) {
56 $name = $b->getName();
57 if (preg_match("/^"._("Template")."/", $name)) continue;
58 $pages = $b->getBackLinks(false);
59 $bl[] = array('name' => $name,
60 'count' => $pages->count());
63 usort($bl, 'cmp_by_count');
64 $html = HTML::ul(); $i = 0;
69 if ($count < $mincount) break;
70 if ($i > $limit) break;
71 $wo = preg_replace("/^("._("Category")."|"
72 ._("Topic").")/", "", $name);
73 $wo = HTML(HTML::span($wo),HTML::raw(" "),HTML::small("(".$count.")"));
74 $link = WikiLink($name, 'auto', $wo);
75 $html->pushContent(HTML::li($link));
81 // get list of categories sorted by number of backlinks
82 function cmp_by_count($a, $b) {
83 if ($a['count'] == $b['count']) return 0;
84 return $a['count'] < $b['count'] ? 1 : -1;
91 // c-hanging-comment-ender-p: nil
92 // indent-tabs-mode: nil