10470c28fSAndreas Gohr<?php 20470c28fSAndreas Gohrnamespace dokuwiki\Ui; 30470c28fSAndreas Gohr 40470c28fSAndreas Gohr/** 50470c28fSAndreas Gohr * Class Admin 60470c28fSAndreas Gohr * 70470c28fSAndreas Gohr * Displays the Admin screen 80470c28fSAndreas Gohr * 90470c28fSAndreas Gohr * @package dokuwiki\Ui 100470c28fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 110470c28fSAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se> 120470c28fSAndreas Gohr */ 130470c28fSAndreas Gohrclass Admin extends Ui { 140470c28fSAndreas Gohr 150470c28fSAndreas Gohr protected $menu; 160470c28fSAndreas Gohr 170470c28fSAndreas Gohr /** 180470c28fSAndreas Gohr * Display the UI element 190470c28fSAndreas Gohr * 200470c28fSAndreas Gohr * @return void 210470c28fSAndreas Gohr */ 220470c28fSAndreas Gohr public function show() { 230470c28fSAndreas Gohr $this->menu = $this->getPluginList(); 245d2e38cbSAndreas Gohr echo '<div class="ui-admin">'; 250470c28fSAndreas Gohr echo p_locale_xhtml('admin'); 260470c28fSAndreas Gohr $this->showSecurityCheck(); 270470c28fSAndreas Gohr $this->showAdminMenu(); 280470c28fSAndreas Gohr $this->showManagerMenu(); 290470c28fSAndreas Gohr $this->showVersion(); 300470c28fSAndreas Gohr $this->showPluginMenu(); 31713faa94SAndreas Gohr echo '</div>'; 320470c28fSAndreas Gohr } 330470c28fSAndreas Gohr 340470c28fSAndreas Gohr /** 350470c28fSAndreas Gohr * Display the standard admin tasks 360470c28fSAndreas Gohr */ 370470c28fSAndreas Gohr protected function showAdminMenu() { 380470c28fSAndreas Gohr /** @var \DokuWiki_Auth_Plugin $auth */ 390470c28fSAndreas Gohr global $auth; 400470c28fSAndreas Gohr global $INFO; 410470c28fSAndreas Gohr 420470c28fSAndreas Gohr if(!$INFO['isadmin']) return; 430470c28fSAndreas Gohr 440470c28fSAndreas Gohr // user manager only if the auth backend supports it 450470c28fSAndreas Gohr if(!$auth || !$auth->canDo('getUsers') ) { 46eb8a8555SAndreas Gohr if(isset($this->menu['usermanager'])) unset($this->menu['usermanager']); 470470c28fSAndreas Gohr } 480470c28fSAndreas Gohr 490470c28fSAndreas Gohr echo '<ul class="admin_tasks">'; 500470c28fSAndreas Gohr foreach(array('usermanager','acl', 'extension', 'config', 'styling') as $plugin) { 510470c28fSAndreas Gohr if(!isset($this->menu[$plugin])) continue; 520470c28fSAndreas Gohr $this->showMenuItem($this->menu[$plugin]); 530470c28fSAndreas Gohr unset($this->menu[$plugin]); 540470c28fSAndreas Gohr } 550470c28fSAndreas Gohr echo '</ul>'; 560470c28fSAndreas Gohr } 570470c28fSAndreas Gohr 580470c28fSAndreas Gohr /** 590470c28fSAndreas Gohr * Display the standard manager tasks 600470c28fSAndreas Gohr */ 610470c28fSAndreas Gohr protected function showManagerMenu() { 620470c28fSAndreas Gohr echo '<ul class="admin_tasks">'; 630470c28fSAndreas Gohr foreach(array('revert','popularity') as $plugin) { 640470c28fSAndreas Gohr if(!isset($this->menu[$plugin])) continue; 650470c28fSAndreas Gohr $this->showMenuItem($this->menu[$plugin]); 660470c28fSAndreas Gohr unset($this->menu[$plugin]); 670470c28fSAndreas Gohr } 680470c28fSAndreas Gohr echo '</ul>'; 690470c28fSAndreas Gohr } 700470c28fSAndreas Gohr 710470c28fSAndreas Gohr /** 720470c28fSAndreas Gohr * Display all the remaining plugins 730470c28fSAndreas Gohr */ 740470c28fSAndreas Gohr protected function showPluginMenu() { 750470c28fSAndreas Gohr if(!count($this->menu)) return; 760470c28fSAndreas Gohr echo p_locale_xhtml('adminplugins'); 770470c28fSAndreas Gohr echo '<ul class="admin_plugins">'; 780470c28fSAndreas Gohr foreach ($this->menu as $item) { 790470c28fSAndreas Gohr $this->showMenuItem($item); 800470c28fSAndreas Gohr } 810470c28fSAndreas Gohr echo '</ul>'; 820470c28fSAndreas Gohr } 830470c28fSAndreas Gohr 840470c28fSAndreas Gohr /** 850470c28fSAndreas Gohr * Display the DokuWiki version 860470c28fSAndreas Gohr */ 870470c28fSAndreas Gohr protected function showVersion() { 880470c28fSAndreas Gohr echo '<div id="admin__version">'; 890470c28fSAndreas Gohr echo getVersion(); 900470c28fSAndreas Gohr echo '</div>'; 910470c28fSAndreas Gohr } 920470c28fSAndreas Gohr 930470c28fSAndreas Gohr /** 940470c28fSAndreas Gohr * data security check 950470c28fSAndreas Gohr * 960470c28fSAndreas Gohr * simple check if the 'savedir' is relative and accessible when appended to DOKU_URL 970470c28fSAndreas Gohr * 980470c28fSAndreas Gohr * it verifies either: 990470c28fSAndreas Gohr * 'savedir' has been moved elsewhere, or 1000470c28fSAndreas Gohr * has protection to prevent the webserver serving files from it 1010470c28fSAndreas Gohr */ 1020470c28fSAndreas Gohr protected function showSecurityCheck() { 1030470c28fSAndreas Gohr global $conf; 1040470c28fSAndreas Gohr if(substr($conf['savedir'], 0, 2) !== './') return; 105*64159a61SAndreas Gohr $img = DOKU_URL . $conf['savedir'] . 106*64159a61SAndreas Gohr '/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png'; 1070470c28fSAndreas Gohr echo '<a style="border:none; float:right;" 1080470c28fSAndreas Gohr href="http://www.dokuwiki.org/security#web_access_security"> 109*64159a61SAndreas Gohr <img src="' . $img . '" alt="Your data directory seems to be protected properly." 1100470c28fSAndreas Gohr onerror="this.parentNode.style.display=\'none\'" /></a>'; 1110470c28fSAndreas Gohr } 1120470c28fSAndreas Gohr 1130470c28fSAndreas Gohr /** 1140470c28fSAndreas Gohr * Display a single Admin menu item 1150470c28fSAndreas Gohr * 1160470c28fSAndreas Gohr * @param array $item 1170470c28fSAndreas Gohr */ 1180470c28fSAndreas Gohr protected function showMenuItem($item) { 1190470c28fSAndreas Gohr global $ID; 1200470c28fSAndreas Gohr if(blank($item['prompt'])) return; 1210470c28fSAndreas Gohr echo '<li><div class="li">'; 122220b8a20SAndreas Gohr echo '<a href="' . wl($ID, 'do=admin&page=' . $item['plugin']) . '">'; 123220b8a20SAndreas Gohr echo '<span class="icon">'; 1244cd2074fSAndreas Gohr echo inlineSVG($item['icon']); 1250470c28fSAndreas Gohr echo '</span>'; 126220b8a20SAndreas Gohr echo '<span class="prompt">'; 1270470c28fSAndreas Gohr echo $item['prompt']; 128220b8a20SAndreas Gohr echo '</span>'; 1290470c28fSAndreas Gohr echo '</a>'; 1300470c28fSAndreas Gohr echo '</div></li>'; 1310470c28fSAndreas Gohr } 1320470c28fSAndreas Gohr 1330470c28fSAndreas Gohr /** 1340470c28fSAndreas Gohr * Build list of admin functions from the plugins that handle them 1350470c28fSAndreas Gohr * 1360470c28fSAndreas Gohr * Checks the current permissions to decide on manager or admin plugins 1370470c28fSAndreas Gohr * 1380470c28fSAndreas Gohr * @return array list of plugins with their properties 1390470c28fSAndreas Gohr */ 1400470c28fSAndreas Gohr protected function getPluginList() { 1410470c28fSAndreas Gohr global $INFO; 1420470c28fSAndreas Gohr global $conf; 1430470c28fSAndreas Gohr 1440470c28fSAndreas Gohr $pluginlist = plugin_list('admin'); 1450470c28fSAndreas Gohr $menu = array(); 1460470c28fSAndreas Gohr foreach($pluginlist as $p) { 1470470c28fSAndreas Gohr /** @var \DokuWiki_Admin_Plugin $obj */ 1480470c28fSAndreas Gohr if(($obj = plugin_load('admin', $p)) === null) continue; 1490470c28fSAndreas Gohr 1500470c28fSAndreas Gohr // check permissions 1510470c28fSAndreas Gohr if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1520470c28fSAndreas Gohr 1530470c28fSAndreas Gohr $menu[$p] = array( 1540470c28fSAndreas Gohr 'plugin' => $p, 1550470c28fSAndreas Gohr 'prompt' => $obj->getMenuText($conf['lang']), 1560470c28fSAndreas Gohr 'icon' => $obj->getMenuIcon(), 1570470c28fSAndreas Gohr 'sort' => $obj->getMenuSort(), 1580470c28fSAndreas Gohr ); 1590470c28fSAndreas Gohr } 1600470c28fSAndreas Gohr 1610470c28fSAndreas Gohr // sort by name, then sort 1620470c28fSAndreas Gohr uasort( 1630470c28fSAndreas Gohr $menu, 1640470c28fSAndreas Gohr function ($a, $b) { 1650470c28fSAndreas Gohr $strcmp = strcasecmp($a['prompt'], $b['prompt']); 1660470c28fSAndreas Gohr if($strcmp != 0) return $strcmp; 1670470c28fSAndreas Gohr if($a['sort'] == $b['sort']) return 0; 1680470c28fSAndreas Gohr return ($a['sort'] < $b['sort']) ? -1 : 1; 1690470c28fSAndreas Gohr } 1700470c28fSAndreas Gohr ); 1710470c28fSAndreas Gohr 1720470c28fSAndreas Gohr return $menu; 1730470c28fSAndreas Gohr } 1740470c28fSAndreas Gohr 1750470c28fSAndreas Gohr} 176