3 * Copyright © 2007 Reini Urban
5 * This file is part of PhpWiki.
7 * PhpWiki is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * PhpWiki is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * SPDX-License-Identifier: GPL-2.0-or-later
29 require_once 'lib/PageList.php';
31 class WikiPlugin_PopularTags
34 // get list of categories sorted by number of backlinks
35 private function cmp_by_count($a, $b)
37 if ($a['count'] == $b['count']) return 0;
38 return $a['count'] < $b['count'] ? 1 : -1;
41 function getDescription()
43 return _("List the most popular tags.");
46 function getDefaultArguments()
48 return array('pagename' => '[pagename]',
57 * @param string $argstr
58 * @param WikiRequest $request
59 * @param string $basepage
62 function run($dbi, $argstr, &$request, $basepage)
64 $args = $this->getArgs($argstr, $request);
67 $maincat = $dbi->getPage(_("CategoryCategory"));
68 $bi = $maincat->getBackLinks();
70 while ($b = $bi->next()) {
71 $name = $b->getName();
72 if (preg_match("/^" . _("Template") . "/", $name)) continue;
73 $pages = $b->getBackLinks();
74 $bl[] = array('name' => $name,
75 'count' => $pages->count());
78 usort($bl, array($this, 'cmp_by_count'));
85 if ($count < $mincount) break;
86 if ($i > $limit) break;
87 $wo = preg_replace("/^(" . _("Category") . "|"
88 . _("Topic") . ")/", "", $name);
89 $wo = HTML(HTML::span($wo), HTML::raw(" "), HTML::small("(" . $count . ")"));
90 $link = WikiLink($name, 'auto', $wo);
91 $html->pushContent(HTML::li($link));