xref: /dokuwiki/lib/plugins/admin.php (revision 38a9f5072a745f01f3044a18f2051980e7740f76)
1<?php
2/**
3 * Admin Plugin Prototype
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Christopher Smith <chris@jalakai.co.uk>
7 */
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11/**
12 * All DokuWiki plugins to extend the admin function
13 * need to inherit from this class
14 */
15class DokuWiki_Admin_Plugin extends DokuWiki_Plugin {
16
17    /**
18     * Return the text that is displayed at the main admin menu
19     * (Default localized language string 'menu' is returned, override this function for setting another name)
20     *
21     * @param string $language language code
22     * @return string menu string
23     */
24    public function getMenuText($language) {
25        $menutext = $this->getLang('menu');
26        if (!$menutext) {
27            $info = $this->getInfo();
28            $menutext = $info['name'].' ...';
29        }
30        return $menutext;
31    }
32
33    /**
34     * Return the path to the icon being displayed in the main admin menu.
35     * By default it tries to find an 'admin.svg' file in the plugin directory.
36     * (Override this function for setting another image)
37     *
38     * Important: you have to return a single path, monochrome SVG icon! It has to be
39     * under 2 Kilobytes!
40     *
41     * We recommend icons from https://materialdesignicons.com/ or to use a matching
42     * style.
43     *
44     * @return string full path to the icon file
45     */
46    public function getMenuIcon() {
47        $plugin = $this->getPluginName();
48        return DOKU_PLUGIN . $plugin . '/admin.svg';
49    }
50
51    /**
52     * Determine position in list in admin window
53     * Lower values are sorted up
54     *
55     * @return int
56     */
57    public function getMenuSort() {
58        return 1000;
59    }
60
61    /**
62     * Carry out required processing
63     */
64    public function handle() {
65        trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING);
66    }
67
68    /**
69     * Output html of the admin page
70     */
71    public function html() {
72        trigger_error('html() not implemented in '.get_class($this), E_USER_WARNING);
73    }
74
75    /**
76     * Checks if access should be granted to this admin plugin
77     *
78     * @return bool true if the current user may access this admin plugin
79     */
80    public function isAccessibleByCurrentUser() {
81        global $INFO;
82
83        $data = [];
84        $data['instance'] = $this;
85        $data['hasAccess'] = false;
86
87        $event = new Doku_Event('ADMINPLUGIN_ACCESS_CHECK', $data);
88        if($event->advise_before()) {
89            if ($this->forAdminOnly()) {
90                $data['hasAccess'] = $INFO['isadmin'];
91            } else {
92                $data['hasAccess'] = $INFO['ismanager'];
93            }
94        }
95        $event->advise_after();
96
97        return $data['hasAccess'];
98    }
99
100    /**
101     * Return true for access only by admins (config:superuser) or false if managers are allowed as well
102     *
103     * @return bool
104     */
105    public function forAdminOnly() {
106        return true;
107    }
108
109    /**
110     * Return array with ToC items. Items can be created with the html_mktocitem()
111     *
112     * @see html_mktocitem()
113     * @see tpl_toc()
114     *
115     * @return array
116     */
117    public function getTOC(){
118        return array();
119    }
120}
121//Setup VIM: ex: et ts=4 :
122