xref: /plugin/tagging/admin.php (revision 0cfde7e95dd57affd4edceef5a53c8f3c34b3c32)
1872edc7cSRené Corinth<?php
2872edc7cSRené Corinth// must be run within Dokuwiki
3*0cfde7e9SMichael Großeif (!defined('DOKU_INC')) {
4*0cfde7e9SMichael Große    die();
5*0cfde7e9SMichael 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    /**
288a1a3846SAndreas Gohr     * Handle tag renames
298a1a3846SAndreas Gohr     */
308a1a3846SAndreas Gohr    function handle() {
318b352fbcSRené Corinth        global $INPUT;
328a1a3846SAndreas Gohr        if ($INPUT->post->has('old') && $INPUT->post->has('new') && checkSecurityToken()) {
338a1a3846SAndreas Gohr            $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new'));
34872edc7cSRené Corinth        }
35872edc7cSRené Corinth    }
36872edc7cSRené Corinth
378a1a3846SAndreas Gohr    /**
388a1a3846SAndreas Gohr     * Draw the interface
398a1a3846SAndreas Gohr     */
40872edc7cSRené Corinth    function html() {
418a1a3846SAndreas Gohr        echo $this->locale_xhtml('intro');
428a1a3846SAndreas Gohr        $this->html_form();
438a1a3846SAndreas Gohr        echo '<br />';
448a1a3846SAndreas Gohr        $this->html_table();
45872edc7cSRené Corinth    }
46872edc7cSRené Corinth
478a1a3846SAndreas Gohr    /**
488a1a3846SAndreas Gohr     * Show form for renaming tags
498a1a3846SAndreas Gohr     */
508a1a3846SAndreas Gohr    protected function html_form() {
518a1a3846SAndreas Gohr        global $ID;
528a1a3846SAndreas Gohr
538a1a3846SAndreas Gohr        $form = new Doku_Form(array('action' => script(), 'method' => 'post', 'class' => 'plugin_tagging'));
548a1a3846SAndreas Gohr        $form->addHidden('do', 'admin');
558a1a3846SAndreas Gohr        $form->addHidden('page', 'tagging');
568a1a3846SAndreas Gohr        $form->addHidden('id', $ID);
578a1a3846SAndreas Gohr
588a1a3846SAndreas Gohr        $form->startFieldset($this->getLang('admin rename tag'));
598a1a3846SAndreas Gohr        $form->addElement(form_makeTextField('old', '', $this->getLang('admin find tag'), '', 'block'));
608a1a3846SAndreas Gohr        $form->addElement(form_makeTextField('new', '', $this->getLang('admin new name'), '', 'block'));
618a1a3846SAndreas Gohr        $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin save')));
628a1a3846SAndreas Gohr
638a1a3846SAndreas Gohr        $form->printForm();
648a1a3846SAndreas Gohr    }
658a1a3846SAndreas Gohr
668a1a3846SAndreas Gohr    /**
678a1a3846SAndreas Gohr     * Display ALL the tags!
688a1a3846SAndreas Gohr     */
698a1a3846SAndreas Gohr    protected function html_table() {
708a1a3846SAndreas Gohr        $tags = $this->hlp->getAllTags();
718a1a3846SAndreas Gohr
728a1a3846SAndreas Gohr        echo '<table class="inline plugin_tagging">';
738a1a3846SAndreas Gohr        echo '<tr>';
748a1a3846SAndreas Gohr        echo '<th>' . $this->getLang('admin tag') . '</th>';
758a1a3846SAndreas Gohr        echo '<th>' . $this->getLang('admin occurrence') . '</th>';
76fb1d0583SAndreas Gohr        echo '<th>' . $this->getLang('admin writtenas') . '</th>';
778a1a3846SAndreas Gohr        echo '<th>' . $this->getLang('admin taggers') . '</th>';
788a1a3846SAndreas Gohr        echo '</tr>';
798a1a3846SAndreas Gohr
808a1a3846SAndreas Gohr        foreach ($tags as $tagname => $taginfo) {
818a1a3846SAndreas Gohr            $taggers = array_unique($taginfo['tagger']);
828a1a3846SAndreas Gohr            sort($taggers);
83fb1d0583SAndreas Gohr            $written = array_unique($taginfo['orig']);
848a1a3846SAndreas Gohr            $taggers = join(', ', $taggers);
85fb1d0583SAndreas Gohr            $written = join(', ', $written);
868a1a3846SAndreas Gohr
878a1a3846SAndreas Gohr            echo '<tr>';
88302a38efSAndreas Gohr            echo '<td><a class="tagslist" href="' . $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>';
898a1a3846SAndreas Gohr            echo '<td>' . $taginfo['count'] . '</td>';
90fb1d0583SAndreas Gohr            echo '<td>' . hsc($written) . '</td>';
918a1a3846SAndreas Gohr            echo '<td>' . hsc($taggers) . '</td>';
928a1a3846SAndreas Gohr            echo '</tr>';
938a1a3846SAndreas Gohr        }
948a1a3846SAndreas Gohr
958a1a3846SAndreas Gohr        echo '</table>';
968a1a3846SAndreas Gohr    }
97872edc7cSRené Corinth}
98