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 78a1a3846SAndreas Gohr /** @var helper_plugin_tagging */ 8872edc7cSRené Corinth private $hlp; 98a1a3846SAndreas Gohr /** @var string message to show */ 108b352fbcSRené Corinth private $message; 11872edc7cSRené Corinth 128a1a3846SAndreas Gohr public function __construct() { 13872edc7cSRené Corinth $this->hlp = plugin_load('helper', 'tagging'); 148a1a3846SAndreas Gohr } 15872edc7cSRené Corinth 168a1a3846SAndreas Gohr /** 178a1a3846SAndreas Gohr * We allow use by managers 188a1a3846SAndreas Gohr * 198a1a3846SAndreas Gohr * @return bool always false 208a1a3846SAndreas Gohr */ 218a1a3846SAndreas Gohr function forAdminOnly() { 228a1a3846SAndreas Gohr return false; 238a1a3846SAndreas Gohr } 248a1a3846SAndreas Gohr 258a1a3846SAndreas Gohr /** 268a1a3846SAndreas Gohr * Handle tag renames 278a1a3846SAndreas Gohr */ 288a1a3846SAndreas Gohr function handle() { 298b352fbcSRené Corinth global $INPUT; 308a1a3846SAndreas Gohr if($INPUT->post->has('old') && $INPUT->post->has('new') && checkSecurityToken()) { 318a1a3846SAndreas Gohr $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new')); 32872edc7cSRené Corinth } 33872edc7cSRené Corinth } 34872edc7cSRené Corinth 358a1a3846SAndreas Gohr /** 368a1a3846SAndreas Gohr * Draw the interface 378a1a3846SAndreas Gohr */ 38872edc7cSRené Corinth function html() { 398a1a3846SAndreas Gohr echo $this->locale_xhtml('intro'); 408a1a3846SAndreas Gohr $this->html_form(); 418a1a3846SAndreas Gohr echo '<br />'; 428a1a3846SAndreas Gohr $this->html_table(); 43872edc7cSRené Corinth } 44872edc7cSRené Corinth 458a1a3846SAndreas Gohr /** 468a1a3846SAndreas Gohr * Show form for renaming tags 478a1a3846SAndreas Gohr */ 488a1a3846SAndreas Gohr protected function html_form() { 498a1a3846SAndreas Gohr global $ID; 508a1a3846SAndreas Gohr 518a1a3846SAndreas Gohr $form = new Doku_Form(array('action' => script(), 'method' => 'post', 'class' => 'plugin_tagging')); 528a1a3846SAndreas Gohr $form->addHidden('do', 'admin'); 538a1a3846SAndreas Gohr $form->addHidden('page', 'tagging'); 548a1a3846SAndreas Gohr $form->addHidden('id', $ID); 558a1a3846SAndreas Gohr 568a1a3846SAndreas Gohr $form->startFieldset($this->getLang('admin rename tag')); 578a1a3846SAndreas Gohr $form->addElement(form_makeTextField('old', '', $this->getLang('admin find tag'), '', 'block')); 588a1a3846SAndreas Gohr $form->addElement(form_makeTextField('new', '', $this->getLang('admin new name'), '', 'block')); 598a1a3846SAndreas Gohr $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin save'))); 608a1a3846SAndreas Gohr 618a1a3846SAndreas Gohr $form->printForm(); 628a1a3846SAndreas Gohr } 638a1a3846SAndreas Gohr 648a1a3846SAndreas Gohr /** 658a1a3846SAndreas Gohr * Display ALL the tags! 668a1a3846SAndreas Gohr */ 678a1a3846SAndreas Gohr protected function html_table() { 688a1a3846SAndreas Gohr $tags = $this->hlp->getAllTags(); 698a1a3846SAndreas Gohr 708a1a3846SAndreas Gohr echo '<table class="inline plugin_tagging">'; 718a1a3846SAndreas Gohr echo '<tr>'; 728a1a3846SAndreas Gohr echo '<th>' . $this->getLang('admin tag') . '</th>'; 738a1a3846SAndreas Gohr echo '<th>' . $this->getLang('admin occurrence') . '</th>'; 748a1a3846SAndreas Gohr echo '<th>' . $this->getLang('admin taggers') . '</th>'; 758a1a3846SAndreas Gohr echo '</tr>'; 768a1a3846SAndreas Gohr 778a1a3846SAndreas Gohr foreach($tags as $tagname => $taginfo) { 788a1a3846SAndreas Gohr $taggers = array_unique($taginfo['tagger']); 798a1a3846SAndreas Gohr sort($taggers); 808a1a3846SAndreas Gohr $taggers = join(', ', $taggers); 818a1a3846SAndreas Gohr 828a1a3846SAndreas Gohr echo '<tr>'; 83*302a38efSAndreas Gohr echo '<td><a class="tagslist" href="' . $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>'; 848a1a3846SAndreas Gohr echo '<td>' . $taginfo['count'] . '</td>'; 858a1a3846SAndreas Gohr echo '<td>' . hsc($taggers) . '</td>'; 868a1a3846SAndreas Gohr echo '</tr>'; 878a1a3846SAndreas Gohr } 888a1a3846SAndreas Gohr 898a1a3846SAndreas Gohr echo '</table>'; 908a1a3846SAndreas Gohr } 91872edc7cSRené Corinth} 92