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 /** 28a99b66c1SSzymon Olewniczak * Handle tag renames 298a1a3846SAndreas Gohr */ 308a1a3846SAndreas Gohr function handle() { 318b352fbcSRené Corinth global $INPUT; 32a99b66c1SSzymon Olewniczak if ($INPUT->post->has('old') && $INPUT->post->has('new') && checkSecurityToken()) { 33a99b66c1SSzymon 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() { 51a99b66c1SSzymon 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() { 70a99b66c1SSzymon Olewniczak global $ID, $INPUT; 718f630140SSzymon Olewniczak 72a99b66c1SSzymon Olewniczak //by default use current page namespace 73a99b66c1SSzymon Olewniczak if (!$INPUT->has('filter')) $INPUT->set('filter', getNS($ID)); 74a99b66c1SSzymon Olewniczak 75a99b66c1SSzymon Olewniczak $tags = $this->hlp->getAllTags($INPUT->str('filter')); 76a99b66c1SSzymon Olewniczak 77a99b66c1SSzymon Olewniczak echo '<table class="inline plugin_tagging">'; 78a99b66c1SSzymon Olewniczak echo '<tr>'; 79a99b66c1SSzymon Olewniczak echo '<th colspan="5">'; 80a99b66c1SSzymon Olewniczak /** 81a99b66c1SSzymon Olewniczak * Show form for filtering the tags by namespaces 82a99b66c1SSzymon Olewniczak */ 83a99b66c1SSzymon Olewniczak $form = new dokuwiki\Form\Form(); 84a99b66c1SSzymon Olewniczak $form->setHiddenField('do', 'admin'); 85a99b66c1SSzymon Olewniczak $form->setHiddenField('page', 'tagging'); 86a99b66c1SSzymon Olewniczak $form->setHiddenField('id', $ID); 87a99b66c1SSzymon Olewniczak $form->addTextInput('filter', $this->getLang('admin filter').': '); 88a99b66c1SSzymon Olewniczak $form->addButton('fn[filter]', $this->getLang('admin filter button')); 89a99b66c1SSzymon Olewniczak echo $form->toHTML(); 90a99b66c1SSzymon Olewniczak echo '</th>'; 91a99b66c1SSzymon 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>'; 100*a0c45f7bSSzymon Olewniczak echo '<th> </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*a0c45f7bSSzymon 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 } 1228f630140SSzymon Olewniczak echo '<tr>'; 1238f630140SSzymon Olewniczak echo '<td colspan="5" class="centeralign">'; 1248f630140SSzymon Olewniczak echo '<span class="medialeft">'; 1258f630140SSzymon Olewniczak echo '<button type="submit" name="fn[delete]" id="tagging__del">'.$this->getLang('admin delete_selected').'</button>'; 1268f630140SSzymon Olewniczak echo '</tr>'; 1278f630140SSzymon Olewniczak echo '</form>'; 128a99b66c1SSzymon Olewniczak echo '</table>'; 129a99b66c1SSzymon Olewniczak 1308f630140SSzymon Olewniczak } 1318f630140SSzymon Olewniczak 1328f630140SSzymon Olewniczak /** 1338f630140SSzymon Olewniczak * Rename a tag 1348f630140SSzymon Olewniczak * 1358f630140SSzymon Olewniczak */ 1368f630140SSzymon Olewniczak protected function _renameTag() { 1378f630140SSzymon Olewniczak global $INPUT; 1388f630140SSzymon Olewniczak 1398f630140SSzymon Olewniczak if ($INPUT->post->has('old') && $INPUT->post->has('new')) { 1408f630140SSzymon Olewniczak $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new')); 1418f630140SSzymon Olewniczak } 1428f630140SSzymon Olewniczak } 1438f630140SSzymon Olewniczak 1448f630140SSzymon Olewniczak /** 1458f630140SSzymon Olewniczak * Delete tags 1468f630140SSzymon Olewniczak * 1478f630140SSzymon Olewniczak */ 1488f630140SSzymon Olewniczak protected function _deleteTags() { 1498f630140SSzymon Olewniczak global $INPUT; 1508f630140SSzymon Olewniczak 1518f630140SSzymon Olewniczak if ($INPUT->post->has('tags')) { 1528f630140SSzymon Olewniczak $this->hlp->deleteTags(array_keys($INPUT->post->arr('tags'))); 1538f630140SSzymon Olewniczak } 1548a1a3846SAndreas Gohr } 155872edc7cSRené Corinth} 156