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