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]',
55 * @param string $argstr
56 * @param WikiRequest $request
57 * @param string $basepage
60 function run($dbi, $argstr, &$request, $basepage)
62 $args = $this->getArgs($argstr, $request);
65 $maincat = $dbi->getPage(_("CategoryCategory"));
66 $bi = $maincat->getBackLinks();
68 while ($b = $bi->next()) {
69 $name = $b->getName();
70 if (preg_match("/^" . _("Template") . "/", $name)) continue;
71 $pages = $b->getBackLinks();
72 $bl[] = array('name' => $name,
73 'count' => $pages->count());
76 usort($bl, array($this, 'cmp_by_count'));
83 if ($count < $mincount) break;
84 if ($i > $limit) break;
85 $wo = preg_replace("/^(" . _("Category") . "|"
86 . _("Topic") . ")/", "", $name);
87 $wo = HTML(HTML::span($wo), HTML::raw(" "), HTML::small("(" . $count . ")"));
88 $link = WikiLink($name, 'auto', $wo);
89 $html->pushContent(HTML::li($link));
99 // c-hanging-comment-ender-p: nil
100 // indent-tabs-mode: nil