xref: /plugin/tagging/admin.php (revision a99b66c123f24ba7d7d591a490d231a0a5bca61e)
1<?php
2// must be run within Dokuwiki
3if (!defined('DOKU_INC')) {
4    die();
5}
6
7class admin_plugin_tagging extends DokuWiki_Admin_Plugin {
8
9    /** @var helper_plugin_tagging */
10    private $hlp;
11    /** @var  string message to show */
12    private $message;
13
14    public function __construct() {
15        $this->hlp = plugin_load('helper', 'tagging');
16    }
17
18    /**
19     * We allow use by managers
20     *
21     * @return bool always false
22     */
23    function forAdminOnly() {
24        return false;
25    }
26
27    /**
28     * Handle tag renames
29     */
30    function handle() {
31        global $INPUT;
32        if ($INPUT->post->has('old') && $INPUT->post->has('new') && checkSecurityToken()) {
33            $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new'));
34        }
35    }
36
37    /**
38     * Draw the interface
39     */
40    function html() {
41        echo $this->locale_xhtml('intro');
42        $this->html_form();
43        echo '<br />';
44        $this->html_table();
45    }
46
47    /**
48     * Show form for renaming tags
49     */
50    protected function html_form() {
51        global $ID, $INPUT;
52
53        $form = new Doku_Form(array('action' => script(), 'method' => 'post', 'class' => 'plugin_tagging'));
54        $form->addHidden('do', 'admin');
55        $form->addHidden('page', 'tagging');
56        $form->addHidden('id', $ID);
57
58        $form->startFieldset($this->getLang('admin rename tag'));
59        $form->addElement(form_makeTextField('old', '', $this->getLang('admin find tag'), '', 'block'));
60        $form->addElement(form_makeTextField('new', '', $this->getLang('admin new name'), '', 'block'));
61        $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin save')));
62
63        $form->printForm();
64    }
65
66    /**
67     * Display ALL the tags!
68     */
69    protected function html_table() {
70        global $ID, $INPUT;
71
72        //by default use current page namespace
73        if (!$INPUT->has('filter')) $INPUT->set('filter', getNS($ID));
74
75        $tags = $this->hlp->getAllTags($INPUT->str('filter'));
76
77        echo '<table class="inline plugin_tagging">';
78        echo '<tr>';
79        echo '<th colspan="5">';
80        /**
81         * Show form for filtering the tags by namespaces
82         */
83        $form = new dokuwiki\Form\Form();
84        $form->setHiddenField('do',   'admin');
85        $form->setHiddenField('page', 'tagging');
86        $form->setHiddenField('id',    $ID);
87        $form->addTextInput('filter', $this->getLang('admin filter').': ');
88        $form->addButton('fn[filter]', $this->getLang('admin filter button'));
89        echo $form->toHTML();
90        echo '</th>';
91        echo '</tr>';
92
93        echo '<form action="'.wl().'" method="post" accept-charset="utf-8">';
94        formSecurityToken();
95        echo '<input type="hidden" name="do"   value="admin" />';
96        echo '<input type="hidden" name="page" value="tagging" />';
97        echo '<input type="hidden" name="id"   value="'.$ID.'" />';
98
99        echo '<tr>';
100        echo '<th>' . $this->getLang('admin tag') . '</th>';
101        echo '<th>' . $this->getLang('admin occurrence') . '</th>';
102        echo '<th>' . $this->getLang('admin writtenas') . '</th>';
103        echo '<th>' . $this->getLang('admin taggers') . '</th>';
104        echo '</tr>';
105
106        foreach ($tags as $tagname => $taginfo) {
107            $taggers = array_unique($taginfo['tagger']);
108            sort($taggers);
109            $written = array_unique($taginfo['orig']);
110            $taggers = join(', ', $taggers);
111            $written = join(', ', $written);
112
113            echo '<tr>';
114            echo '<td><a class="tagslist" href="' . $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>';
115            echo '<td>' . $taginfo['count'] . '</td>';
116            echo '<td>' . hsc($written) . '</td>';
117            echo '<td>' . hsc($taggers) . '</td>';
118            echo '</tr>';
119        }
120        echo '<tr>';
121        echo '<td colspan="5" class="centeralign">';
122        echo '<span class="medialeft">';
123        echo '<button type="submit" name="fn[delete]" id="tagging__del">'.$this->getLang('admin delete_selected').'</button>';
124        echo '</tr>';
125        echo '</form>';
126        echo '</table>';
127
128    }
129
130    /**
131     * Rename a tag
132     *
133     */
134    protected function _renameTag() {
135        global $INPUT;
136
137        if ($INPUT->post->has('old') && $INPUT->post->has('new')) {
138            $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new'));
139        }
140    }
141
142    /**
143     * Delete tags
144     *
145     */
146    protected function _deleteTags() {
147        global $INPUT;
148
149        if ($INPUT->post->has('tags')) {
150            $this->hlp->deleteTags(array_keys($INPUT->post->arr('tags')));
151        }
152    }
153}
154