xref: /dokuwiki/inc/Ui/Admin.php (revision 220b8a20866d9b7398996bd30dbc61f61345209c)
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();
24713faa94SAndreas 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 '<div class="clearer"></div>';
770470c28fSAndreas Gohr        echo p_locale_xhtml('adminplugins');
780470c28fSAndreas Gohr        echo '<ul class="admin_plugins">';
790470c28fSAndreas Gohr        foreach ($this->menu as $item) {
800470c28fSAndreas Gohr            $this->showMenuItem($item);
810470c28fSAndreas Gohr        }
820470c28fSAndreas Gohr        echo '</ul>';
830470c28fSAndreas Gohr    }
840470c28fSAndreas Gohr
850470c28fSAndreas Gohr    /**
860470c28fSAndreas Gohr     * Display the DokuWiki version
870470c28fSAndreas Gohr     */
880470c28fSAndreas Gohr    protected function showVersion() {
890470c28fSAndreas Gohr        echo '<div id="admin__version">';
900470c28fSAndreas Gohr        echo getVersion();
910470c28fSAndreas Gohr        echo '</div>';
920470c28fSAndreas Gohr    }
930470c28fSAndreas Gohr
940470c28fSAndreas Gohr    /**
950470c28fSAndreas Gohr     * data security check
960470c28fSAndreas Gohr     *
970470c28fSAndreas Gohr     * simple check if the 'savedir' is relative and accessible when appended to DOKU_URL
980470c28fSAndreas Gohr     *
990470c28fSAndreas Gohr     * it verifies either:
1000470c28fSAndreas Gohr     *   'savedir' has been moved elsewhere, or
1010470c28fSAndreas Gohr     *   has protection to prevent the webserver serving files from it
1020470c28fSAndreas Gohr     */
1030470c28fSAndreas Gohr    protected function showSecurityCheck() {
1040470c28fSAndreas Gohr        global $conf;
1050470c28fSAndreas Gohr        if(substr($conf['savedir'], 0, 2) !== './') return;
1060470c28fSAndreas Gohr        echo '<a style="border:none; float:right;"
1070470c28fSAndreas Gohr                href="http://www.dokuwiki.org/security#web_access_security">
1080470c28fSAndreas Gohr                <img src="' . DOKU_URL . $conf['savedir'] . '/security.png" alt="Your data directory seems to be protected properly."
1090470c28fSAndreas Gohr                onerror="this.parentNode.style.display=\'none\'" /></a>';
1100470c28fSAndreas Gohr    }
1110470c28fSAndreas Gohr
1120470c28fSAndreas Gohr    /**
1130470c28fSAndreas Gohr     * Display a single Admin menu item
1140470c28fSAndreas Gohr     *
1150470c28fSAndreas Gohr     * @param array $item
1160470c28fSAndreas Gohr     */
1170470c28fSAndreas Gohr    protected function showMenuItem($item) {
1180470c28fSAndreas Gohr        global $ID;
1190470c28fSAndreas Gohr        if(blank($item['prompt'])) return;
1200470c28fSAndreas Gohr        echo '<li><div class="li">';
121*220b8a20SAndreas Gohr        echo '<a href="' . wl($ID, 'do=admin&amp;page=' . $item['plugin']) . '">';
122*220b8a20SAndreas Gohr        echo '<span class="icon">';
1230470c28fSAndreas Gohr        embedSVG($item['icon']);
1240470c28fSAndreas Gohr        echo '</span>';
125*220b8a20SAndreas Gohr        echo '<span class="prompt">';
1260470c28fSAndreas Gohr        echo $item['prompt'];
127*220b8a20SAndreas Gohr        echo '</span>';
1280470c28fSAndreas Gohr        echo '</a>';
1290470c28fSAndreas Gohr        echo '</div></li>';
1300470c28fSAndreas Gohr    }
1310470c28fSAndreas Gohr
1320470c28fSAndreas Gohr    /**
1330470c28fSAndreas Gohr     * Build  list of admin functions from the plugins that handle them
1340470c28fSAndreas Gohr     *
1350470c28fSAndreas Gohr     * Checks the current permissions to decide on manager or admin plugins
1360470c28fSAndreas Gohr     *
1370470c28fSAndreas Gohr     * @return array list of plugins with their properties
1380470c28fSAndreas Gohr     */
1390470c28fSAndreas Gohr    protected function getPluginList() {
1400470c28fSAndreas Gohr        global $INFO;
1410470c28fSAndreas Gohr        global $conf;
1420470c28fSAndreas Gohr
1430470c28fSAndreas Gohr        $pluginlist = plugin_list('admin');
1440470c28fSAndreas Gohr        $menu = array();
1450470c28fSAndreas Gohr        foreach($pluginlist as $p) {
1460470c28fSAndreas Gohr            /** @var \DokuWiki_Admin_Plugin $obj */
1470470c28fSAndreas Gohr            if(($obj = plugin_load('admin', $p)) === null) continue;
1480470c28fSAndreas Gohr
1490470c28fSAndreas Gohr            // check permissions
1500470c28fSAndreas Gohr            if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1510470c28fSAndreas Gohr
1520470c28fSAndreas Gohr            $menu[$p] = array(
1530470c28fSAndreas Gohr                'plugin' => $p,
1540470c28fSAndreas Gohr                'prompt' => $obj->getMenuText($conf['lang']),
1550470c28fSAndreas Gohr                'icon' => $obj->getMenuIcon(),
1560470c28fSAndreas Gohr                'sort' => $obj->getMenuSort(),
1570470c28fSAndreas Gohr            );
1580470c28fSAndreas Gohr        }
1590470c28fSAndreas Gohr
1600470c28fSAndreas Gohr        // sort by name, then sort
1610470c28fSAndreas Gohr        uasort(
1620470c28fSAndreas Gohr            $menu,
1630470c28fSAndreas Gohr            function ($a, $b) {
1640470c28fSAndreas Gohr                $strcmp = strcasecmp($a['prompt'], $b['prompt']);
1650470c28fSAndreas Gohr                if($strcmp != 0) return $strcmp;
1660470c28fSAndreas Gohr                if($a['sort'] == $b['sort']) return 0;
1670470c28fSAndreas Gohr                return ($a['sort'] < $b['sort']) ? -1 : 1;
1680470c28fSAndreas Gohr            }
1690470c28fSAndreas Gohr        );
1700470c28fSAndreas Gohr
1710470c28fSAndreas Gohr        return $menu;
1720470c28fSAndreas Gohr    }
1730470c28fSAndreas Gohr
1740470c28fSAndreas Gohr}
175