1<?php 2// must be run within Dokuwiki 3if (!defined('DOKU_INC')) { 4 die(); 5} 6 7class admin_plugin_tagging extends DokuWiki_Admin_Plugin { 8 9 /** @var helper_plugin_tagging */ 10 private $hlp; 11 /** @var string message to show */ 12 private $message; 13 14 public function __construct() { 15 $this->hlp = plugin_load('helper', 'tagging'); 16 } 17 18 /** 19 * We allow use by managers 20 * 21 * @return bool always false 22 */ 23 function forAdminOnly() { 24 return false; 25 } 26 27 /** 28 * Handle tag actions 29 */ 30 function handle() { 31 global $ID, $INPUT; 32 33 //by default use current page namespace 34 if (!$INPUT->has('filter')) $INPUT->set('filter', getNS($ID)); 35 36 //now starts functions handle 37 if (!$INPUT->has('fn')) return false; 38 if (!checkSecurityToken()) return false; 39 40 // extract the command and any specific parameters 41 // submit button name is of the form - fn[cmd][param(s)] 42 $fn = $INPUT->param('fn'); 43 44 if (is_array($fn)) { 45 $cmd = key($fn); 46 $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null; 47 } else { 48 $cmd = $fn; 49 $param = null; 50 } 51 52 switch ($cmd) { 53 case 'rename' : $this->_renameTag(); break; 54 case 'delete' : $this->_deleteTags(); break; 55 } 56 } 57 58 /** 59 * Draw the interface 60 */ 61 function html() { 62 echo $this->locale_xhtml('intro'); 63 $this->html_form(); 64 echo '<br />'; 65 $this->html_table(); 66 } 67 68 /** 69 * Show form for renaming tags 70 */ 71 protected function html_form() { 72 global $ID, $INPUT; 73 74 $form = new dokuwiki\Form\Form(); 75 $form->addClass('plugin_tagging'); 76 77 $form->setHiddenField('do', 'admin'); 78 $form->setHiddenField('page', 'tagging'); 79 $form->setHiddenField('id', $ID); 80 $form->setHiddenField('filter', $INPUT->str('filter')); 81 82 $form->addFieldsetOpen($this->getLang('admin rename tag')); 83 $form->addTextInput('old', $this->getLang('admin find tag'))->addClass('block'); 84 $form->addTagClose('br'); 85 $form->addTextInput('new', $this->getLang('admin new name'))->addClass('block'); 86 $form->addTagClose('br'); 87 $form->addButton('fn[rename]', $this->getLang('admin save')); 88 $form->addFieldsetClose(); 89 90 echo $form->toHTML(); 91 } 92 93 /** 94 * Display ALL the tags! 95 */ 96 protected function html_table() { 97 global $ID, $INPUT; 98 99 $headers = array( 100 ' ', 101 $this->getLang('admin tag'), 102 $this->getLang('admin occurrence'), 103 $this->getLang('admin writtenas'), 104 $this->getLang('admin taggers') 105 ); 106 $tags = $this->hlp->getAllTags($INPUT->str('filter')); 107 108 $form = new dokuwiki\Form\Form(); 109 $form->setHiddenField('do', 'admin'); 110 $form->setHiddenField('page', 'tagging'); 111 $form->setHiddenField('id', $ID); 112 113 $form->addTagOpen('table')->addClass('inline plugin_tagging'); 114 $form->addTagOpen('tr'); 115 $form->addTagOpen('th')->attr('colspan', count($headers)); 116 117 /** 118 * Show form for filtering the tags by namespaces 119 */ 120 $form->addTextInput('filter', $this->getLang('admin filter').': '); 121 $form->addButton('fn[filter]', $this->getLang('admin filter button')); 122 123 $form->addTagClose('th'); 124 $form->addTagClose('tr'); 125 126 /** 127 * Table headers 128 */ 129 $form->addTagOpen('tr'); 130 foreach ($headers as $header) { 131 $form->addHTML('<th>' . $header . '</th>'); 132 } 133 $form->addTagClose('tr'); 134 135 foreach ($tags as $taginfo) { 136 $tagname = $taginfo['tid']; 137 $taggers = $taginfo['taggers']; 138 $written = $taginfo['orig']; 139 140 $form->addTagOpen('tr'); 141 $form->addTagOpen('td')->addClass('centeralign'); 142 $form->addCheckbox('tags['.hsc($tagname).']'); 143 $form->addTagClose('td'); 144 $form->addHTML('<td><a class="tagslist" href="' . 145 $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>'); 146 $form->addHTML('<td>' . $taginfo['count'] . '</td>'); 147 $form->addHTML('<td>' . hsc($written) . '</td>'); 148 $form->addHTML('<td>' . hsc($taggers) . '</td>'); 149 150 $form->addTagClose('tr'); 151 } 152 153 $form->addTagOpen('tr'); 154 $form->addHTML('<td colspan="5" class="centeralign"><span class="medialeft">'); 155 $form->addButton('fn[delete]', $this->getLang('admin delete_selected'))->id('tagging__del'); 156 $form->addHTML('</span></td>'); 157 $form->addTagClose('tr'); 158 159 $form->addTagClose('table'); 160 echo $form->toHTML(); 161 } 162 163 /** 164 * Rename a tag 165 * 166 */ 167 protected function _renameTag() { 168 global $INPUT; 169 170 if ($INPUT->post->has('old') && $INPUT->post->has('new')) { 171 $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new')); 172 } 173 } 174 175 /** 176 * Delete tags 177 * 178 */ 179 protected function _deleteTags() { 180 global $INPUT; 181 182 if ($INPUT->post->has('tags')) { 183 $this->hlp->deleteTags(array_keys($INPUT->post->arr('tags')), $INPUT->str('filter')); 184 } 185 } 186} 187