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