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*a99b66c1SSzymon Olewniczak * Handle tag renames 298a1a3846SAndreas Gohr */ 308a1a3846SAndreas Gohr function handle() { 318b352fbcSRené Corinth global $INPUT; 32*a99b66c1SSzymon Olewniczak if ($INPUT->post->has('old') && $INPUT->post->has('new') && checkSecurityToken()) { 33*a99b66c1SSzymon Olewniczak $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() { 51*a99b66c1SSzymon Olewniczak global $ID, $INPUT; 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() { 70*a99b66c1SSzymon Olewniczak global $ID, $INPUT; 718f630140SSzymon Olewniczak 72*a99b66c1SSzymon Olewniczak //by default use current page namespace 73*a99b66c1SSzymon Olewniczak if (!$INPUT->has('filter')) $INPUT->set('filter', getNS($ID)); 74*a99b66c1SSzymon Olewniczak 75*a99b66c1SSzymon Olewniczak $tags = $this->hlp->getAllTags($INPUT->str('filter')); 76*a99b66c1SSzymon Olewniczak 77*a99b66c1SSzymon Olewniczak echo '<table class="inline plugin_tagging">'; 78*a99b66c1SSzymon Olewniczak echo '<tr>'; 79*a99b66c1SSzymon Olewniczak echo '<th colspan="5">'; 80*a99b66c1SSzymon Olewniczak /** 81*a99b66c1SSzymon Olewniczak * Show form for filtering the tags by namespaces 82*a99b66c1SSzymon Olewniczak */ 83*a99b66c1SSzymon Olewniczak $form = new dokuwiki\Form\Form(); 84*a99b66c1SSzymon Olewniczak $form->setHiddenField('do', 'admin'); 85*a99b66c1SSzymon Olewniczak $form->setHiddenField('page', 'tagging'); 86*a99b66c1SSzymon Olewniczak $form->setHiddenField('id', $ID); 87*a99b66c1SSzymon Olewniczak $form->addTextInput('filter', $this->getLang('admin filter').': '); 88*a99b66c1SSzymon Olewniczak $form->addButton('fn[filter]', $this->getLang('admin filter button')); 89*a99b66c1SSzymon Olewniczak echo $form->toHTML(); 90*a99b66c1SSzymon Olewniczak echo '</th>'; 91*a99b66c1SSzymon Olewniczak echo '</tr>'; 928a1a3846SAndreas Gohr 938f630140SSzymon Olewniczak echo '<form action="'.wl().'" method="post" accept-charset="utf-8">'; 948f630140SSzymon Olewniczak formSecurityToken(); 958f630140SSzymon Olewniczak echo '<input type="hidden" name="do" value="admin" />'; 968f630140SSzymon Olewniczak echo '<input type="hidden" name="page" value="tagging" />'; 978f630140SSzymon Olewniczak echo '<input type="hidden" name="id" value="'.$ID.'" />'; 988f630140SSzymon Olewniczak 998a1a3846SAndreas Gohr echo '<tr>'; 1008a1a3846SAndreas Gohr echo '<th>' . $this->getLang('admin tag') . '</th>'; 1018a1a3846SAndreas Gohr echo '<th>' . $this->getLang('admin occurrence') . '</th>'; 102fb1d0583SAndreas Gohr echo '<th>' . $this->getLang('admin writtenas') . '</th>'; 1038a1a3846SAndreas Gohr echo '<th>' . $this->getLang('admin taggers') . '</th>'; 1048a1a3846SAndreas Gohr echo '</tr>'; 1058a1a3846SAndreas Gohr 1068a1a3846SAndreas Gohr foreach ($tags as $tagname => $taginfo) { 1078a1a3846SAndreas Gohr $taggers = array_unique($taginfo['tagger']); 1088a1a3846SAndreas Gohr sort($taggers); 109fb1d0583SAndreas Gohr $written = array_unique($taginfo['orig']); 1108a1a3846SAndreas Gohr $taggers = join(', ', $taggers); 111fb1d0583SAndreas Gohr $written = join(', ', $written); 1128a1a3846SAndreas Gohr 1138a1a3846SAndreas Gohr echo '<tr>'; 114302a38efSAndreas Gohr echo '<td><a class="tagslist" href="' . $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>'; 1158a1a3846SAndreas Gohr echo '<td>' . $taginfo['count'] . '</td>'; 116fb1d0583SAndreas Gohr echo '<td>' . hsc($written) . '</td>'; 1178a1a3846SAndreas Gohr echo '<td>' . hsc($taggers) . '</td>'; 1188a1a3846SAndreas Gohr echo '</tr>'; 1198a1a3846SAndreas Gohr } 1208f630140SSzymon Olewniczak echo '<tr>'; 1218f630140SSzymon Olewniczak echo '<td colspan="5" class="centeralign">'; 1228f630140SSzymon Olewniczak echo '<span class="medialeft">'; 1238f630140SSzymon Olewniczak echo '<button type="submit" name="fn[delete]" id="tagging__del">'.$this->getLang('admin delete_selected').'</button>'; 1248f630140SSzymon Olewniczak echo '</tr>'; 1258f630140SSzymon Olewniczak echo '</form>'; 126*a99b66c1SSzymon Olewniczak echo '</table>'; 127*a99b66c1SSzymon Olewniczak 1288f630140SSzymon Olewniczak } 1298f630140SSzymon Olewniczak 1308f630140SSzymon Olewniczak /** 1318f630140SSzymon Olewniczak * Rename a tag 1328f630140SSzymon Olewniczak * 1338f630140SSzymon Olewniczak */ 1348f630140SSzymon Olewniczak protected function _renameTag() { 1358f630140SSzymon Olewniczak global $INPUT; 1368f630140SSzymon Olewniczak 1378f630140SSzymon Olewniczak if ($INPUT->post->has('old') && $INPUT->post->has('new')) { 1388f630140SSzymon Olewniczak $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new')); 1398f630140SSzymon Olewniczak } 1408f630140SSzymon Olewniczak } 1418f630140SSzymon Olewniczak 1428f630140SSzymon Olewniczak /** 1438f630140SSzymon Olewniczak * Delete tags 1448f630140SSzymon Olewniczak * 1458f630140SSzymon Olewniczak */ 1468f630140SSzymon Olewniczak protected function _deleteTags() { 1478f630140SSzymon Olewniczak global $INPUT; 1488f630140SSzymon Olewniczak 1498f630140SSzymon Olewniczak if ($INPUT->post->has('tags')) { 1508f630140SSzymon Olewniczak $this->hlp->deleteTags(array_keys($INPUT->post->arr('tags'))); 1518f630140SSzymon Olewniczak } 1528a1a3846SAndreas Gohr } 153872edc7cSRené Corinth} 154