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 $INPUT; 32 33 if (!$INPUT->has('fn')) return false; 34 if (!checkSecurityToken()) return false; 35 36 // extract the command and any specific parameters 37 // submit button name is of the form - fn[cmd][param(s)] 38 $fn = $INPUT->param('fn'); 39 40 if (is_array($fn)) { 41 $cmd = key($fn); 42 $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null; 43 } else { 44 $cmd = $fn; 45 $param = null; 46 } 47 48 switch ($cmd) { 49 case 'rename' : $this->_renameTag(); break; 50 case 'delete' : $this->_deleteTags(); break; 51 } 52 } 53 54 /** 55 * Draw the interface 56 */ 57 function html() { 58 echo $this->locale_xhtml('intro'); 59 $this->html_form(); 60 echo '<br />'; 61 $this->html_table(); 62 } 63 64 /** 65 * Show form for renaming tags 66 */ 67 protected function html_form() { 68 global $ID; 69 70 $form = new Doku_Form(array('action' => script(), 'method' => 'post', 'class' => 'plugin_tagging')); 71 $form->addHidden('do', 'admin'); 72 $form->addHidden('page', 'tagging'); 73 $form->addHidden('id', $ID); 74 $form->addHidden('fn', 'rename'); 75 76 $form->startFieldset($this->getLang('admin rename tag')); 77 $form->addElement(form_makeTextField('old', '', $this->getLang('admin find tag'), '', 'block')); 78 $form->addElement(form_makeTextField('new', '', $this->getLang('admin new name'), '', 'block')); 79 $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin save'))); 80 81 $form->printForm(); 82 } 83 84 /** 85 * Display ALL the tags! 86 */ 87 protected function html_table() { 88 global $ID; 89 90 $tags = $this->hlp->getAllTags(); 91 92 echo '<form action="'.wl().'" method="post" accept-charset="utf-8">'; 93 formSecurityToken(); 94 echo '<input type="hidden" name="do" value="admin" />'; 95 echo '<input type="hidden" name="page" value="tagging" />'; 96 echo '<input type="hidden" name="id" value="'.$ID.'" />'; 97 98 echo '<table class="inline plugin_tagging">'; 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 128 echo '</table>'; 129 echo '</form>'; 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