xref: /plugin/tagging/admin.php (revision 8f630140209c8c1f672efff851e8c4dd35833139)
1872edc7cSRené Corinth<?php
2872edc7cSRené Corinth// must be run within Dokuwiki
30cfde7e9SMichael Großeif (!defined('DOKU_INC')) {
40cfde7e9SMichael Große    die();
50cfde7e9SMichael Große}
6872edc7cSRené Corinth
7872edc7cSRené Corinthclass admin_plugin_tagging extends DokuWiki_Admin_Plugin {
8872edc7cSRené Corinth
98a1a3846SAndreas Gohr    /** @var helper_plugin_tagging */
10872edc7cSRené Corinth    private $hlp;
118a1a3846SAndreas Gohr    /** @var  string message to show */
128b352fbcSRené Corinth    private $message;
13872edc7cSRené Corinth
148a1a3846SAndreas Gohr    public function __construct() {
15872edc7cSRené Corinth        $this->hlp = plugin_load('helper', 'tagging');
168a1a3846SAndreas Gohr    }
17872edc7cSRené Corinth
188a1a3846SAndreas Gohr    /**
198a1a3846SAndreas Gohr     * We allow use by managers
208a1a3846SAndreas Gohr     *
218a1a3846SAndreas Gohr     * @return bool always false
228a1a3846SAndreas Gohr     */
238a1a3846SAndreas Gohr    function forAdminOnly() {
248a1a3846SAndreas Gohr        return false;
258a1a3846SAndreas Gohr    }
268a1a3846SAndreas Gohr
278a1a3846SAndreas Gohr    /**
28*8f630140SSzymon Olewniczak     * Handle tag actions
298a1a3846SAndreas Gohr     */
308a1a3846SAndreas Gohr    function handle() {
318b352fbcSRené Corinth        global $INPUT;
32*8f630140SSzymon Olewniczak
33*8f630140SSzymon Olewniczak        if (!$INPUT->has('fn')) return false;
34*8f630140SSzymon Olewniczak        if (!checkSecurityToken()) return false;
35*8f630140SSzymon Olewniczak
36*8f630140SSzymon Olewniczak        // extract the command and any specific parameters
37*8f630140SSzymon Olewniczak        // submit button name is of the form - fn[cmd][param(s)]
38*8f630140SSzymon Olewniczak        $fn   = $INPUT->param('fn');
39*8f630140SSzymon Olewniczak
40*8f630140SSzymon Olewniczak        if (is_array($fn)) {
41*8f630140SSzymon Olewniczak            $cmd = key($fn);
42*8f630140SSzymon Olewniczak            $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null;
43*8f630140SSzymon Olewniczak        } else {
44*8f630140SSzymon Olewniczak            $cmd = $fn;
45*8f630140SSzymon Olewniczak            $param = null;
46*8f630140SSzymon Olewniczak        }
47*8f630140SSzymon Olewniczak
48*8f630140SSzymon Olewniczak        switch ($cmd) {
49*8f630140SSzymon Olewniczak            case 'rename'    : $this->_renameTag(); break;
50*8f630140SSzymon Olewniczak            case 'delete'    : $this->_deleteTags(); break;
51872edc7cSRené Corinth        }
52872edc7cSRené Corinth    }
53872edc7cSRené Corinth
548a1a3846SAndreas Gohr    /**
558a1a3846SAndreas Gohr     * Draw the interface
568a1a3846SAndreas Gohr     */
57872edc7cSRené Corinth    function html() {
588a1a3846SAndreas Gohr        echo $this->locale_xhtml('intro');
598a1a3846SAndreas Gohr        $this->html_form();
608a1a3846SAndreas Gohr        echo '<br />';
618a1a3846SAndreas Gohr        $this->html_table();
62872edc7cSRené Corinth    }
63872edc7cSRené Corinth
648a1a3846SAndreas Gohr    /**
658a1a3846SAndreas Gohr     * Show form for renaming tags
668a1a3846SAndreas Gohr     */
678a1a3846SAndreas Gohr    protected function html_form() {
688a1a3846SAndreas Gohr        global $ID;
698a1a3846SAndreas Gohr
708a1a3846SAndreas Gohr        $form = new Doku_Form(array('action' => script(), 'method' => 'post', 'class' => 'plugin_tagging'));
718a1a3846SAndreas Gohr        $form->addHidden('do', 'admin');
728a1a3846SAndreas Gohr        $form->addHidden('page', 'tagging');
738a1a3846SAndreas Gohr        $form->addHidden('id', $ID);
74*8f630140SSzymon Olewniczak        $form->addHidden('fn', 'rename');
758a1a3846SAndreas Gohr
768a1a3846SAndreas Gohr        $form->startFieldset($this->getLang('admin rename tag'));
778a1a3846SAndreas Gohr        $form->addElement(form_makeTextField('old', '', $this->getLang('admin find tag'), '', 'block'));
788a1a3846SAndreas Gohr        $form->addElement(form_makeTextField('new', '', $this->getLang('admin new name'), '', 'block'));
798a1a3846SAndreas Gohr        $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin save')));
808a1a3846SAndreas Gohr
818a1a3846SAndreas Gohr        $form->printForm();
828a1a3846SAndreas Gohr    }
838a1a3846SAndreas Gohr
848a1a3846SAndreas Gohr    /**
858a1a3846SAndreas Gohr     * Display ALL the tags!
868a1a3846SAndreas Gohr     */
878a1a3846SAndreas Gohr    protected function html_table() {
88*8f630140SSzymon Olewniczak        global $ID;
89*8f630140SSzymon Olewniczak
908a1a3846SAndreas Gohr        $tags = $this->hlp->getAllTags();
918a1a3846SAndreas Gohr
92*8f630140SSzymon Olewniczak        echo '<form action="'.wl().'" method="post" accept-charset="utf-8">';
93*8f630140SSzymon Olewniczak        formSecurityToken();
94*8f630140SSzymon Olewniczak        echo '<input type="hidden" name="do"   value="admin" />';
95*8f630140SSzymon Olewniczak        echo '<input type="hidden" name="page" value="tagging" />';
96*8f630140SSzymon Olewniczak        echo '<input type="hidden" name="id"   value="'.$ID.'" />';
97*8f630140SSzymon Olewniczak
988a1a3846SAndreas Gohr        echo '<table class="inline plugin_tagging">';
998a1a3846SAndreas Gohr        echo '<tr>';
100*8f630140SSzymon Olewniczak        echo '<th>&#160;</th>';
1018a1a3846SAndreas Gohr        echo '<th>' . $this->getLang('admin tag') . '</th>';
1028a1a3846SAndreas Gohr        echo '<th>' . $this->getLang('admin occurrence') . '</th>';
103fb1d0583SAndreas Gohr        echo '<th>' . $this->getLang('admin writtenas') . '</th>';
1048a1a3846SAndreas Gohr        echo '<th>' . $this->getLang('admin taggers') . '</th>';
1058a1a3846SAndreas Gohr        echo '</tr>';
1068a1a3846SAndreas Gohr
1078a1a3846SAndreas Gohr        foreach ($tags as $tagname => $taginfo) {
1088a1a3846SAndreas Gohr            $taggers = array_unique($taginfo['tagger']);
1098a1a3846SAndreas Gohr            sort($taggers);
110fb1d0583SAndreas Gohr            $written = array_unique($taginfo['orig']);
1118a1a3846SAndreas Gohr            $taggers = join(', ', $taggers);
112fb1d0583SAndreas Gohr            $written = join(', ', $written);
1138a1a3846SAndreas Gohr
1148a1a3846SAndreas Gohr            echo '<tr>';
115*8f630140SSzymon Olewniczak            echo '<td class="centeralign"><input type="checkbox" name="tags['.hsc($tagname).']" /></td>';
116302a38efSAndreas Gohr            echo '<td><a class="tagslist" href="' . $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>';
1178a1a3846SAndreas Gohr            echo '<td>' . $taginfo['count'] . '</td>';
118fb1d0583SAndreas Gohr            echo '<td>' . hsc($written) . '</td>';
1198a1a3846SAndreas Gohr            echo '<td>' . hsc($taggers) . '</td>';
1208a1a3846SAndreas Gohr            echo '</tr>';
1218a1a3846SAndreas Gohr        }
122*8f630140SSzymon Olewniczak        echo '<tr>';
123*8f630140SSzymon Olewniczak        echo '<td colspan="5" class="centeralign">';
124*8f630140SSzymon Olewniczak        echo '<span class="medialeft">';
125*8f630140SSzymon Olewniczak        echo '<button type="submit" name="fn[delete]" id="tagging__del">'.$this->getLang('admin delete_selected').'</button>';
126*8f630140SSzymon Olewniczak        echo '</tr>';
1278a1a3846SAndreas Gohr
1288a1a3846SAndreas Gohr        echo '</table>';
129*8f630140SSzymon Olewniczak        echo '</form>';
130*8f630140SSzymon Olewniczak    }
131*8f630140SSzymon Olewniczak
132*8f630140SSzymon Olewniczak    /**
133*8f630140SSzymon Olewniczak     * Rename a tag
134*8f630140SSzymon Olewniczak     *
135*8f630140SSzymon Olewniczak     */
136*8f630140SSzymon Olewniczak    protected function _renameTag() {
137*8f630140SSzymon Olewniczak        global $INPUT;
138*8f630140SSzymon Olewniczak
139*8f630140SSzymon Olewniczak        if ($INPUT->post->has('old') && $INPUT->post->has('new')) {
140*8f630140SSzymon Olewniczak            $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new'));
141*8f630140SSzymon Olewniczak        }
142*8f630140SSzymon Olewniczak    }
143*8f630140SSzymon Olewniczak
144*8f630140SSzymon Olewniczak    /**
145*8f630140SSzymon Olewniczak     * Delete tags
146*8f630140SSzymon Olewniczak     *
147*8f630140SSzymon Olewniczak     */
148*8f630140SSzymon Olewniczak    protected function _deleteTags() {
149*8f630140SSzymon Olewniczak        global $INPUT;
150*8f630140SSzymon Olewniczak
151*8f630140SSzymon Olewniczak        if ($INPUT->post->has('tags')) {
152*8f630140SSzymon Olewniczak            $this->hlp->deleteTags(array_keys($INPUT->post->arr('tags')));
153*8f630140SSzymon Olewniczak        }
1548a1a3846SAndreas Gohr    }
155872edc7cSRené Corinth}
156