xref: /plugin/tagging/admin.php (revision 302a38ef7e7a2d8a2b1bfa06d48c02880a055fc6)
1<?php
2// must be run within Dokuwiki
3if(!defined('DOKU_INC')) die();
4
5class admin_plugin_tagging extends DokuWiki_Admin_Plugin {
6
7    /** @var helper_plugin_tagging */
8    private $hlp;
9    /** @var  string message to show */
10    private $message;
11
12    public function __construct() {
13        $this->hlp = plugin_load('helper', 'tagging');
14    }
15
16    /**
17     * We allow use by managers
18     *
19     * @return bool always false
20     */
21    function forAdminOnly() {
22        return false;
23    }
24
25    /**
26     * Handle tag renames
27     */
28    function handle() {
29        global $INPUT;
30        if($INPUT->post->has('old') && $INPUT->post->has('new') && checkSecurityToken()) {
31            $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new'));
32        }
33    }
34
35    /**
36     * Draw the interface
37     */
38    function html() {
39        echo $this->locale_xhtml('intro');
40        $this->html_form();
41        echo '<br />';
42        $this->html_table();
43    }
44
45    /**
46     * Show form for renaming tags
47     */
48    protected function html_form() {
49        global $ID;
50
51        $form = new Doku_Form(array('action' => script(), 'method' => 'post', 'class' => 'plugin_tagging'));
52        $form->addHidden('do', 'admin');
53        $form->addHidden('page', 'tagging');
54        $form->addHidden('id', $ID);
55
56        $form->startFieldset($this->getLang('admin rename tag'));
57        $form->addElement(form_makeTextField('old', '', $this->getLang('admin find tag'), '', 'block'));
58        $form->addElement(form_makeTextField('new', '', $this->getLang('admin new name'), '', 'block'));
59        $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin save')));
60
61        $form->printForm();
62    }
63
64    /**
65     * Display ALL the tags!
66     */
67    protected function html_table() {
68        $tags = $this->hlp->getAllTags();
69
70        echo '<table class="inline plugin_tagging">';
71        echo '<tr>';
72        echo '<th>' . $this->getLang('admin tag') . '</th>';
73        echo '<th>' . $this->getLang('admin occurrence') . '</th>';
74        echo '<th>' . $this->getLang('admin taggers') . '</th>';
75        echo '</tr>';
76
77        foreach($tags as $tagname => $taginfo) {
78            $taggers = array_unique($taginfo['tagger']);
79            sort($taggers);
80            $taggers = join(', ', $taggers);
81
82            echo '<tr>';
83            echo '<td><a class="tagslist" href="' . $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>';
84            echo '<td>' . $taginfo['count'] . '</td>';
85            echo '<td>' . hsc($taggers) . '</td>';
86            echo '</tr>';
87        }
88
89        echo '</table>';
90    }
91}
92