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 renames 29 */ 30 function handle() { 31 global $INPUT; 32 if ($INPUT->post->has('old') && $INPUT->post->has('new') && checkSecurityToken()) { 33 $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new')); 34 } 35 } 36 37 /** 38 * Draw the interface 39 */ 40 function html() { 41 echo $this->locale_xhtml('intro'); 42 $this->html_form(); 43 echo '<br />'; 44 $this->html_table(); 45 } 46 47 /** 48 * Show form for renaming tags 49 */ 50 protected function html_form() { 51 global $ID, $INPUT; 52 53 $form = new Doku_Form(array('action' => script(), 'method' => 'post', 'class' => 'plugin_tagging')); 54 $form->addHidden('do', 'admin'); 55 $form->addHidden('page', 'tagging'); 56 $form->addHidden('id', $ID); 57 58 $form->startFieldset($this->getLang('admin rename tag')); 59 $form->addElement(form_makeTextField('old', '', $this->getLang('admin find tag'), '', 'block')); 60 $form->addElement(form_makeTextField('new', '', $this->getLang('admin new name'), '', 'block')); 61 $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin save'))); 62 63 $form->printForm(); 64 } 65 66 /** 67 * Display ALL the tags! 68 */ 69 protected function html_table() { 70 global $ID, $INPUT; 71 72 //by default use current page namespace 73 if (!$INPUT->has('filter')) $INPUT->set('filter', getNS($ID)); 74 75 $tags = $this->hlp->getAllTags($INPUT->str('filter')); 76 77 echo '<table class="inline plugin_tagging">'; 78 echo '<tr>'; 79 echo '<th colspan="5">'; 80 /** 81 * Show form for filtering the tags by namespaces 82 */ 83 $form = new dokuwiki\Form\Form(); 84 $form->setHiddenField('do', 'admin'); 85 $form->setHiddenField('page', 'tagging'); 86 $form->setHiddenField('id', $ID); 87 $form->addTextInput('filter', $this->getLang('admin filter').': '); 88 $form->addButton('fn[filter]', $this->getLang('admin filter button')); 89 echo $form->toHTML(); 90 echo '</th>'; 91 echo '</tr>'; 92 93 echo '<form action="'.wl().'" method="post" accept-charset="utf-8">'; 94 formSecurityToken(); 95 echo '<input type="hidden" name="do" value="admin" />'; 96 echo '<input type="hidden" name="page" value="tagging" />'; 97 echo '<input type="hidden" name="id" value="'.$ID.'" />'; 98 99 echo '<tr>'; 100 echo '<th> </th>'; 101 echo '<th>' . $this->getLang('admin tag') . '</th>'; 102 echo '<th>' . $this->getLang('admin occurrence') . '</th>'; 103 echo '<th>' . $this->getLang('admin writtenas') . '</th>'; 104 echo '<th>' . $this->getLang('admin taggers') . '</th>'; 105 echo '</tr>'; 106 107 foreach ($tags as $tagname => $taginfo) { 108 $taggers = array_unique($taginfo['tagger']); 109 sort($taggers); 110 $written = array_unique($taginfo['orig']); 111 $taggers = join(', ', $taggers); 112 $written = join(', ', $written); 113 114 echo '<tr>'; 115 echo '<td class="centeralign"><input type="checkbox" name="tags['.hsc($tagname).']" /></td>'; 116 echo '<td><a class="tagslist" href="' . $this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>'; 117 echo '<td>' . $taginfo['count'] . '</td>'; 118 echo '<td>' . hsc($written) . '</td>'; 119 echo '<td>' . hsc($taggers) . '</td>'; 120 echo '</tr>'; 121 } 122 echo '<tr>'; 123 echo '<td colspan="5" class="centeralign">'; 124 echo '<span class="medialeft">'; 125 echo '<button type="submit" name="fn[delete]" id="tagging__del">'.$this->getLang('admin delete_selected').'</button>'; 126 echo '</tr>'; 127 echo '</form>'; 128 echo '</table>'; 129 130 } 131 132 /** 133 * Rename a tag 134 * 135 */ 136 protected function _renameTag() { 137 global $INPUT; 138 139 if ($INPUT->post->has('old') && $INPUT->post->has('new')) { 140 $this->hlp->renameTag($INPUT->post->str('old'), $INPUT->post->str('new')); 141 } 142 } 143 144 /** 145 * Delete tags 146 * 147 */ 148 protected function _deleteTags() { 149 global $INPUT; 150 151 if ($INPUT->post->has('tags')) { 152 $this->hlp->deleteTags(array_keys($INPUT->post->arr('tags'))); 153 } 154 } 155} 156