xref: /plugin/tagging/admin.php (revision d092e7b8bfa6b15a4508b1daab70e097dee89674)
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 writtenas') . '</th>';
75        echo '<th>' . $this->getLang('admin taggers') . '</th>';
76        echo '</tr>';
77
78        foreach($tags as $tagname => $taginfo) {
79            $taggers = array_unique($taginfo['tagger']);
80            sort($taggers);
81            $written = array_unique($taginfo['orig']);
82            $taggers = join(', ', $taggers);
83            $written = join(', ', $written);
84
85            echo '<tr>';
86            echo '<td><a class="tagslist" href="' . $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>';
87            echo '<td>' . $taginfo['count'] . '</td>';
88            echo '<td>' . hsc($written) . '</td>';
89            echo '<td>' . hsc($taggers) . '</td>';
90            echo '</tr>';
91        }
92
93        echo '</table>';
94    }
95}
96