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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once 'lib/PageList.php';
29 class WikiPlugin_PopularTags
32 // get list of categories sorted by number of backlinks
33 private function cmp_by_count($a, $b)
35 if ($a['count'] == $b['count']) return 0;
36 return $a['count'] < $b['count'] ? 1 : -1;
39 function getDescription()
41 return _("List the most popular tags.");
44 function getDefaultArguments()
46 return array('pagename' => '[pagename]',
53 function run($dbi, $argstr, &$request, $basepage)
55 $args = $this->getArgs($argstr, $request);
58 $maincat = $dbi->getPage(_("CategoryCategory"));
59 $bi = $maincat->getBackLinks(false);
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());
69 usort($bl, array($this, 'cmp_by_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(" "), HTML::small("(" . $count . ")"));
81 $link = WikiLink($name, 'auto', $wo);
82 $html->pushContent(HTML::li($link));
92 // c-hanging-comment-ender-p: nil
93 // indent-tabs-mode: nil