1<?php 2namespace dokuwiki\Ui; 3 4/** 5 * Class Admin 6 * 7 * Displays the Admin screen 8 * 9 * @package dokuwiki\Ui 10 * @author Andreas Gohr <andi@splitbrain.org> 11 * @author Håkan Sandell <hakan.sandell@home.se> 12 */ 13class Admin extends Ui { 14 15 protected $menu; 16 17 /** 18 * Display the UI element 19 * 20 * @return void 21 */ 22 public function show() { 23 $this->menu = $this->getPluginList(); 24 echo '<div class="UI-admin">'; 25 echo p_locale_xhtml('admin'); 26 $this->showSecurityCheck(); 27 $this->showAdminMenu(); 28 $this->showManagerMenu(); 29 $this->showVersion(); 30 $this->showPluginMenu(); 31 echo '</div>'; 32 } 33 34 /** 35 * Display the standard admin tasks 36 */ 37 protected function showAdminMenu() { 38 /** @var \DokuWiki_Auth_Plugin $auth */ 39 global $auth; 40 global $INFO; 41 42 if(!$INFO['isadmin']) return; 43 44 // user manager only if the auth backend supports it 45 if(!$auth || !$auth->canDo('getUsers') ) { 46 if(isset($this->menu['usermanager'])) unset($this->menu['usermanager']); 47 } 48 49 echo '<ul class="admin_tasks">'; 50 foreach(array('usermanager','acl', 'extension', 'config', 'styling') as $plugin) { 51 if(!isset($this->menu[$plugin])) continue; 52 $this->showMenuItem($this->menu[$plugin]); 53 unset($this->menu[$plugin]); 54 } 55 echo '</ul>'; 56 } 57 58 /** 59 * Display the standard manager tasks 60 */ 61 protected function showManagerMenu() { 62 echo '<ul class="admin_tasks">'; 63 foreach(array('revert','popularity') as $plugin) { 64 if(!isset($this->menu[$plugin])) continue; 65 $this->showMenuItem($this->menu[$plugin]); 66 unset($this->menu[$plugin]); 67 } 68 echo '</ul>'; 69 } 70 71 /** 72 * Display all the remaining plugins 73 */ 74 protected function showPluginMenu() { 75 if(!count($this->menu)) return; 76 echo '<div class="clearer"></div>'; 77 echo p_locale_xhtml('adminplugins'); 78 echo '<ul class="admin_plugins">'; 79 foreach ($this->menu as $item) { 80 $this->showMenuItem($item); 81 } 82 echo '</ul>'; 83 } 84 85 /** 86 * Display the DokuWiki version 87 */ 88 protected function showVersion() { 89 echo '<div id="admin__version">'; 90 echo getVersion(); 91 echo '</div>'; 92 } 93 94 /** 95 * data security check 96 * 97 * simple check if the 'savedir' is relative and accessible when appended to DOKU_URL 98 * 99 * it verifies either: 100 * 'savedir' has been moved elsewhere, or 101 * has protection to prevent the webserver serving files from it 102 */ 103 protected function showSecurityCheck() { 104 global $conf; 105 if(substr($conf['savedir'], 0, 2) !== './') return; 106 echo '<a style="border:none; float:right;" 107 href="http://www.dokuwiki.org/security#web_access_security"> 108 <img src="' . DOKU_URL . $conf['savedir'] . '/security.png" alt="Your data directory seems to be protected properly." 109 onerror="this.parentNode.style.display=\'none\'" /></a>'; 110 } 111 112 /** 113 * Display a single Admin menu item 114 * 115 * @param array $item 116 */ 117 protected function showMenuItem($item) { 118 global $ID; 119 if(blank($item['prompt'])) return; 120 echo '<li><div class="li">'; 121 echo '<a href="' . wl($ID, 'do=admin&page=' . $item['plugin']) . '">'; 122 echo '<span class="icon">'; 123 embedSVG($item['icon']); 124 echo '</span>'; 125 echo '<span class="prompt">'; 126 echo $item['prompt']; 127 echo '</span>'; 128 echo '</a>'; 129 echo '</div></li>'; 130 } 131 132 /** 133 * Build list of admin functions from the plugins that handle them 134 * 135 * Checks the current permissions to decide on manager or admin plugins 136 * 137 * @return array list of plugins with their properties 138 */ 139 protected function getPluginList() { 140 global $INFO; 141 global $conf; 142 143 $pluginlist = plugin_list('admin'); 144 $menu = array(); 145 foreach($pluginlist as $p) { 146 /** @var \DokuWiki_Admin_Plugin $obj */ 147 if(($obj = plugin_load('admin', $p)) === null) continue; 148 149 // check permissions 150 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 151 152 $menu[$p] = array( 153 'plugin' => $p, 154 'prompt' => $obj->getMenuText($conf['lang']), 155 'icon' => $obj->getMenuIcon(), 156 'sort' => $obj->getMenuSort(), 157 ); 158 } 159 160 // sort by name, then sort 161 uasort( 162 $menu, 163 function ($a, $b) { 164 $strcmp = strcasecmp($a['prompt'], $b['prompt']); 165 if($strcmp != 0) return $strcmp; 166 if($a['sort'] == $b['sort']) return 0; 167 return ($a['sort'] < $b['sort']) ? -1 : 1; 168 } 169 ); 170 171 return $menu; 172 } 173 174} 175