1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Admin Plugin Prototype |
4
|
|
|
* |
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
6
|
|
|
* @author Christopher Smith <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
// must be run within Dokuwiki |
9
|
|
|
if(!defined('DOKU_INC')) die(); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* All DokuWiki plugins to extend the admin function |
13
|
|
|
* need to inherit from this class |
14
|
|
|
*/ |
15
|
|
|
class 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['hasAccess'] = false; |
|
|
|
|
84
|
|
|
|
85
|
|
|
$event = new Doku_Event('ADMINPLUGIN_ACCESS_CHECK', $data); |
86
|
|
|
if($event->advise_before()) { |
87
|
|
|
if ($this->forAdminOnly()) { |
88
|
|
|
$data['hasAccess'] = $INFO['isadmin']; |
89
|
|
|
} else { |
90
|
|
|
$data['hasAccess'] = $INFO['ismanager']; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
$event->advise_after(); |
94
|
|
|
|
95
|
|
|
return $data['hasAccess']; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Return true for access only by admins (config:superuser) or false if managers are allowed as well |
100
|
|
|
* |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
|
|
public function forAdminOnly() { |
104
|
|
|
return true; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Return array with ToC items. Items can be created with the html_mktocitem() |
109
|
|
|
* |
110
|
|
|
* @see html_mktocitem() |
111
|
|
|
* @see tpl_toc() |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function getTOC(){ |
116
|
|
|
return array(); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
//Setup VIM: ex: et ts=4 : |
120
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.