10470c28fSAndreas Gohr<?php 20470c28fSAndreas Gohrnamespace dokuwiki\Ui; 30470c28fSAndreas Gohr 42d85e841SAndreas Gohruse dokuwiki\Utf8\Sort; 52d85e841SAndreas Gohr 60470c28fSAndreas Gohr/** 70470c28fSAndreas Gohr * Class Admin 80470c28fSAndreas Gohr * 90470c28fSAndreas Gohr * Displays the Admin screen 100470c28fSAndreas Gohr * 110470c28fSAndreas Gohr * @package dokuwiki\Ui 120470c28fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 130470c28fSAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se> 140470c28fSAndreas Gohr */ 150470c28fSAndreas Gohrclass Admin extends Ui { 160470c28fSAndreas Gohr 1770cc2cbfSAndreas Gohr protected $forAdmins = array('usermanager', 'acl', 'extension', 'config', 'logviewer', 'styling'); 1864cdf779SAndreas Gohr protected $forManagers = array('revert', 'popularity'); 1964cdf779SAndreas Gohr /** @var array[] */ 200470c28fSAndreas Gohr protected $menu; 210470c28fSAndreas Gohr 220470c28fSAndreas Gohr /** 230470c28fSAndreas Gohr * Display the UI element 240470c28fSAndreas Gohr * 250470c28fSAndreas Gohr * @return void 260470c28fSAndreas Gohr */ 270470c28fSAndreas Gohr public function show() { 280470c28fSAndreas Gohr $this->menu = $this->getPluginList(); 295d2e38cbSAndreas Gohr echo '<div class="ui-admin">'; 300470c28fSAndreas Gohr echo p_locale_xhtml('admin'); 31*052e1c84SAndreas Gohr 3264cdf779SAndreas Gohr $this->showMenu('admin'); 3364cdf779SAndreas Gohr $this->showMenu('manager'); 34*052e1c84SAndreas Gohr $this->showSecurityCheck(); 350470c28fSAndreas Gohr $this->showVersion(); 3664cdf779SAndreas Gohr $this->showMenu('other'); 37713faa94SAndreas Gohr echo '</div>'; 380470c28fSAndreas Gohr } 390470c28fSAndreas Gohr 400470c28fSAndreas Gohr /** 4164cdf779SAndreas Gohr * Show the given menu of available plugins 4264cdf779SAndreas Gohr * 4364cdf779SAndreas Gohr * @param string $type admin|manager|other 440470c28fSAndreas Gohr */ 4564cdf779SAndreas Gohr protected function showMenu($type) { 4664cdf779SAndreas Gohr if (!$this->menu[$type]) return; 470470c28fSAndreas Gohr 4864cdf779SAndreas Gohr if ($type === 'other') { 490470c28fSAndreas Gohr echo p_locale_xhtml('adminplugins'); 5064cdf779SAndreas Gohr $class = 'admin_plugins'; 5164cdf779SAndreas Gohr } else { 5264cdf779SAndreas Gohr $class = 'admin_tasks'; 5364cdf779SAndreas Gohr } 5464cdf779SAndreas Gohr 5564cdf779SAndreas Gohr echo "<ul class=\"$class\">"; 5664cdf779SAndreas Gohr foreach ($this->menu[$type] as $item) { 570470c28fSAndreas Gohr $this->showMenuItem($item); 580470c28fSAndreas Gohr } 590470c28fSAndreas Gohr echo '</ul>'; 600470c28fSAndreas Gohr } 610470c28fSAndreas Gohr 620470c28fSAndreas Gohr /** 630470c28fSAndreas Gohr * Display the DokuWiki version 640470c28fSAndreas Gohr */ 650470c28fSAndreas Gohr protected function showVersion() { 660470c28fSAndreas Gohr echo '<div id="admin__version">'; 670470c28fSAndreas Gohr echo getVersion(); 680470c28fSAndreas Gohr echo '</div>'; 690470c28fSAndreas Gohr } 700470c28fSAndreas Gohr 710470c28fSAndreas Gohr /** 720470c28fSAndreas Gohr * data security check 730470c28fSAndreas Gohr * 740470c28fSAndreas Gohr * simple check if the 'savedir' is relative and accessible when appended to DOKU_URL 750470c28fSAndreas Gohr * 760470c28fSAndreas Gohr * it verifies either: 770470c28fSAndreas Gohr * 'savedir' has been moved elsewhere, or 780470c28fSAndreas Gohr * has protection to prevent the webserver serving files from it 79*052e1c84SAndreas Gohr * 80*052e1c84SAndreas Gohr * The actual check is carried out via JavaScript. See behaviour.js 810470c28fSAndreas Gohr */ 820470c28fSAndreas Gohr protected function showSecurityCheck() { 830470c28fSAndreas Gohr global $conf; 840470c28fSAndreas Gohr if(substr($conf['savedir'], 0, 2) !== './') return; 8564159a61SAndreas Gohr $img = DOKU_URL . $conf['savedir'] . 8664159a61SAndreas Gohr '/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png'; 87*052e1c84SAndreas Gohr echo '<a style="border:none; float:right;" id="security__check" 88*052e1c84SAndreas Gohr href="http://www.dokuwiki.org/security#web_access_security" data-src="' . $img . '">⚠</a>'; 890470c28fSAndreas Gohr } 900470c28fSAndreas Gohr 910470c28fSAndreas Gohr /** 920470c28fSAndreas Gohr * Display a single Admin menu item 930470c28fSAndreas Gohr * 940470c28fSAndreas Gohr * @param array $item 950470c28fSAndreas Gohr */ 960470c28fSAndreas Gohr protected function showMenuItem($item) { 970470c28fSAndreas Gohr global $ID; 980470c28fSAndreas Gohr if(blank($item['prompt'])) return; 990470c28fSAndreas Gohr echo '<li><div class="li">'; 100220b8a20SAndreas Gohr echo '<a href="' . wl($ID, 'do=admin&page=' . $item['plugin']) . '">'; 101220b8a20SAndreas Gohr echo '<span class="icon">'; 1024cd2074fSAndreas Gohr echo inlineSVG($item['icon']); 1030470c28fSAndreas Gohr echo '</span>'; 104220b8a20SAndreas Gohr echo '<span class="prompt">'; 1050470c28fSAndreas Gohr echo $item['prompt']; 106220b8a20SAndreas Gohr echo '</span>'; 1070470c28fSAndreas Gohr echo '</a>'; 1080470c28fSAndreas Gohr echo '</div></li>'; 1090470c28fSAndreas Gohr } 1100470c28fSAndreas Gohr 1110470c28fSAndreas Gohr /** 1120470c28fSAndreas Gohr * Build list of admin functions from the plugins that handle them 1130470c28fSAndreas Gohr * 1140470c28fSAndreas Gohr * Checks the current permissions to decide on manager or admin plugins 1150470c28fSAndreas Gohr * 1160470c28fSAndreas Gohr * @return array list of plugins with their properties 1170470c28fSAndreas Gohr */ 1180470c28fSAndreas Gohr protected function getPluginList() { 1190470c28fSAndreas Gohr global $conf; 1200470c28fSAndreas Gohr 1210470c28fSAndreas Gohr $pluginlist = plugin_list('admin'); 12264cdf779SAndreas Gohr $menu = ['admin' => [], 'manager' => [], 'other' => []]; 12364cdf779SAndreas Gohr 1240470c28fSAndreas Gohr foreach($pluginlist as $p) { 125e1d9dcc8SAndreas Gohr /** @var \dokuwiki\Extension\AdminPlugin $obj */ 1260470c28fSAndreas Gohr if(($obj = plugin_load('admin', $p)) === null) continue; 1270470c28fSAndreas Gohr 1280470c28fSAndreas Gohr // check permissions 12964cdf779SAndreas Gohr if (!$obj->isAccessibleByCurrentUser()) continue; 1300470c28fSAndreas Gohr 13164cdf779SAndreas Gohr if (in_array($p, $this->forAdmins, true)) { 13264cdf779SAndreas Gohr $type = 'admin'; 13364cdf779SAndreas Gohr } elseif (in_array($p, $this->forManagers, true)){ 13464cdf779SAndreas Gohr $type = 'manager'; 13564cdf779SAndreas Gohr } else { 13664cdf779SAndreas Gohr $type = 'other'; 13764cdf779SAndreas Gohr } 13864cdf779SAndreas Gohr 13964cdf779SAndreas Gohr $menu[$type][$p] = array( 1400470c28fSAndreas Gohr 'plugin' => $p, 1410470c28fSAndreas Gohr 'prompt' => $obj->getMenuText($conf['lang']), 1420470c28fSAndreas Gohr 'icon' => $obj->getMenuIcon(), 1430470c28fSAndreas Gohr 'sort' => $obj->getMenuSort(), 1440470c28fSAndreas Gohr ); 1450470c28fSAndreas Gohr } 1460470c28fSAndreas Gohr 1470470c28fSAndreas Gohr // sort by name, then sort 14864cdf779SAndreas Gohr uasort($menu['admin'], [$this, 'menuSort']); 14964cdf779SAndreas Gohr uasort($menu['manager'], [$this, 'menuSort']); 15064cdf779SAndreas Gohr uasort($menu['other'], [$this, 'menuSort']); 1510470c28fSAndreas Gohr 1520470c28fSAndreas Gohr return $menu; 1530470c28fSAndreas Gohr } 1540470c28fSAndreas Gohr 15564cdf779SAndreas Gohr /** 15664cdf779SAndreas Gohr * Custom sorting for admin menu 15764cdf779SAndreas Gohr * 15864cdf779SAndreas Gohr * We sort alphabetically first, then by sort value 15964cdf779SAndreas Gohr * 16064cdf779SAndreas Gohr * @param array $a 16164cdf779SAndreas Gohr * @param array $b 16264cdf779SAndreas Gohr * @return int 16364cdf779SAndreas Gohr */ 16464cdf779SAndreas Gohr protected function menuSort($a, $b) { 1652d85e841SAndreas Gohr $strcmp = Sort::strcmp($a['prompt'], $b['prompt']); 16664cdf779SAndreas Gohr if($strcmp != 0) return $strcmp; 16764cdf779SAndreas Gohr if($a['sort'] === $b['sort']) return 0; 16864cdf779SAndreas Gohr return ($a['sort'] < $b['sort']) ? -1 : 1; 16964cdf779SAndreas Gohr } 1700470c28fSAndreas Gohr} 171