[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace dokuwiki\Ui; 4 5 use dokuwiki\Extension\AdminPlugin; 6 use dokuwiki\Extension\PluginInterface; 7 use dokuwiki\Utf8\Sort; 8 9 /** 10 * Class Admin 11 * 12 * Displays the Admin screen 13 * 14 * @package dokuwiki\Ui 15 * @author Andreas Gohr <andi@splitbrain.org> 16 * @author HÃ¥kan Sandell <hakan.sandell@home.se> 17 */ 18 class Admin extends Ui 19 { 20 protected $forAdmins = ['usermanager', 'acl', 'extension', 'config', 'logviewer', 'styling']; 21 protected $forManagers = ['revert', 'popularity']; 22 /** @var array[] */ 23 protected $menu; 24 25 /** 26 * Display the UI element 27 * 28 * @return void 29 */ 30 public function show() 31 { 32 $this->menu = $this->getPluginList(); 33 echo '<div class="ui-admin">'; 34 echo p_locale_xhtml('admin'); 35 36 $this->showMenu('admin'); 37 $this->showMenu('manager'); 38 $this->showSecurityCheck(); 39 $this->showVersion(); 40 $this->showMenu('other'); 41 echo '</div>'; 42 } 43 44 /** 45 * Show the given menu of available plugins 46 * 47 * @param string $type admin|manager|other 48 */ 49 protected function showMenu($type) 50 { 51 if (!$this->menu[$type]) return; 52 53 if ($type === 'other') { 54 echo p_locale_xhtml('adminplugins'); 55 $class = 'admin_plugins'; 56 } else { 57 $class = 'admin_tasks'; 58 } 59 60 echo "<ul class=\"$class\">"; 61 foreach ($this->menu[$type] as $item) { 62 $this->showMenuItem($item); 63 } 64 echo '</ul>'; 65 } 66 67 /** 68 * Display the DokuWiki version 69 */ 70 protected function showVersion() 71 { 72 echo '<div id="admin__version">'; 73 echo getVersion(); 74 echo '</div>'; 75 } 76 77 /** 78 * data security check 79 * 80 * simple check if the 'savedir' is relative and accessible when appended to DOKU_URL 81 * 82 * it verifies either: 83 * 'savedir' has been moved elsewhere, or 84 * has protection to prevent the webserver serving files from it 85 * 86 * The actual check is carried out via JavaScript. See behaviour.js 87 */ 88 protected function showSecurityCheck() 89 { 90 global $conf; 91 if (!str_starts_with($conf['savedir'], './')) return; 92 $img = DOKU_URL . $conf['savedir'] . 93 '/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png'; 94 echo '<div id="security__check" data-src="' . $img . '"></div>'; 95 } 96 97 /** 98 * Display a single Admin menu item 99 * 100 * @param array $item 101 */ 102 protected function showMenuItem($item) 103 { 104 global $ID; 105 if (blank($item['prompt'])) return; 106 echo '<li><div class="li">'; 107 echo '<a href="' . wl($ID, 'do=admin&page=' . $item['plugin']) . '">'; 108 echo '<span class="icon">'; 109 echo inlineSVG($item['icon']); 110 echo '</span>'; 111 echo '<span class="prompt">'; 112 echo $item['prompt']; 113 echo '</span>'; 114 echo '</a>'; 115 echo '</div></li>'; 116 } 117 118 /** 119 * Build list of admin functions from the plugins that handle them 120 * 121 * Checks the current permissions to decide on manager or admin plugins 122 * 123 * @return array list of plugins with their properties 124 */ 125 protected function getPluginList() 126 { 127 global $conf; 128 129 $pluginlist = plugin_list('admin'); 130 $menu = ['admin' => [], 'manager' => [], 'other' => []]; 131 132 foreach ($pluginlist as $p) { 133 /** @var AdminPlugin $obj */ 134 if (!($obj = plugin_load('admin', $p)) instanceof PluginInterface) continue; 135 136 // check permissions 137 if (!$obj->isAccessibleByCurrentUser()) continue; 138 139 if (in_array($p, $this->forAdmins, true)) { 140 $type = 'admin'; 141 } elseif (in_array($p, $this->forManagers, true)) { 142 $type = 'manager'; 143 } else { 144 $type = 'other'; 145 } 146 147 $menu[$type][$p] = [ 148 'plugin' => $p, 149 'prompt' => $obj->getMenuText($conf['lang']), 150 'icon' => $obj->getMenuIcon(), 151 'sort' => $obj->getMenuSort() 152 ]; 153 } 154 155 // sort by name, then sort 156 uasort($menu['admin'], [$this, 'menuSort']); 157 uasort($menu['manager'], [$this, 'menuSort']); 158 uasort($menu['other'], [$this, 'menuSort']); 159 160 return $menu; 161 } 162 163 /** 164 * Custom sorting for admin menu 165 * 166 * We sort alphabetically first, then by sort value 167 * 168 * @param array $a 169 * @param array $b 170 * @return int 171 */ 172 protected function menuSort($a, $b) 173 { 174 $strcmp = Sort::strcmp($a['prompt'], $b['prompt']); 175 if ($strcmp != 0) return $strcmp; 176 return $a['sort'] <=> $b['sort']; 177 } 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body