|
1
|
|
|
<?php |
|
2
|
|
|
namespace dokuwiki\Ui; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class Admin |
|
6
|
|
|
* |
|
7
|
|
|
* Displays the Admin screen |
|
8
|
|
|
* |
|
9
|
|
|
* @package dokuwiki\Ui |
|
10
|
|
|
* @author Andreas Gohr <[email protected]> |
|
11
|
|
|
* @author Håkan Sandell <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Admin extends Ui { |
|
14
|
|
|
|
|
15
|
|
|
protected $menu; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Display the UI element |
|
19
|
|
|
* |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
public function show() { |
|
23
|
|
|
$this->menu = $this->getPluginList(); |
|
24
|
|
|
echo '<div class="UI-admin">'; |
|
25
|
|
|
echo p_locale_xhtml('admin'); |
|
26
|
|
|
$this->showSecurityCheck(); |
|
27
|
|
|
$this->showAdminMenu(); |
|
28
|
|
|
$this->showManagerMenu(); |
|
29
|
|
|
$this->showVersion(); |
|
30
|
|
|
$this->showPluginMenu(); |
|
31
|
|
|
echo '</div>'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Display the standard admin tasks |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function showAdminMenu() { |
|
38
|
|
|
/** @var \DokuWiki_Auth_Plugin $auth */ |
|
39
|
|
|
global $auth; |
|
40
|
|
|
global $INFO; |
|
41
|
|
|
|
|
42
|
|
|
if(!$INFO['isadmin']) return; |
|
43
|
|
|
|
|
44
|
|
|
// user manager only if the auth backend supports it |
|
45
|
|
|
if(!$auth || !$auth->canDo('getUsers') ) { |
|
46
|
|
|
if(isset($menu['usermanager'])) unset($menu['usermanager']); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
echo '<ul class="admin_tasks">'; |
|
50
|
|
|
foreach(array('usermanager','acl', 'extension', 'config', 'styling') as $plugin) { |
|
51
|
|
|
if(!isset($this->menu[$plugin])) continue; |
|
52
|
|
|
$this->showMenuItem($this->menu[$plugin]); |
|
53
|
|
|
unset($this->menu[$plugin]); |
|
54
|
|
|
} |
|
55
|
|
|
echo '</ul>'; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Display the standard manager tasks |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function showManagerMenu() { |
|
62
|
|
|
echo '<ul class="admin_tasks">'; |
|
63
|
|
|
foreach(array('revert','popularity') as $plugin) { |
|
64
|
|
|
if(!isset($this->menu[$plugin])) continue; |
|
65
|
|
|
$this->showMenuItem($this->menu[$plugin]); |
|
66
|
|
|
unset($this->menu[$plugin]); |
|
67
|
|
|
} |
|
68
|
|
|
echo '</ul>'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Display all the remaining plugins |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function showPluginMenu() { |
|
75
|
|
|
if(!count($this->menu)) return; |
|
76
|
|
|
echo '<div class="clearer"></div>'; |
|
77
|
|
|
echo p_locale_xhtml('adminplugins'); |
|
78
|
|
|
echo '<ul class="admin_plugins">'; |
|
79
|
|
|
foreach ($this->menu as $item) { |
|
80
|
|
|
$this->showMenuItem($item); |
|
81
|
|
|
} |
|
82
|
|
|
echo '</ul>'; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Display the DokuWiki version |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function showVersion() { |
|
89
|
|
|
echo '<div id="admin__version">'; |
|
90
|
|
|
echo getVersion(); |
|
91
|
|
|
echo '</div>'; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* data security check |
|
96
|
|
|
* |
|
97
|
|
|
* simple check if the 'savedir' is relative and accessible when appended to DOKU_URL |
|
98
|
|
|
* |
|
99
|
|
|
* it verifies either: |
|
100
|
|
|
* 'savedir' has been moved elsewhere, or |
|
101
|
|
|
* has protection to prevent the webserver serving files from it |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function showSecurityCheck() { |
|
104
|
|
|
global $conf; |
|
105
|
|
|
if(substr($conf['savedir'], 0, 2) !== './') return; |
|
106
|
|
|
echo '<a style="border:none; float:right;" |
|
107
|
|
|
href="http://www.dokuwiki.org/security#web_access_security"> |
|
108
|
|
|
<img src="' . DOKU_URL . $conf['savedir'] . '/security.png" alt="Your data directory seems to be protected properly." |
|
109
|
|
|
onerror="this.parentNode.style.display=\'none\'" /></a>'; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Display a single Admin menu item |
|
114
|
|
|
* |
|
115
|
|
|
* @param array $item |
|
116
|
|
|
*/ |
|
117
|
|
|
protected function showMenuItem($item) { |
|
118
|
|
|
global $ID; |
|
119
|
|
|
if(blank($item['prompt'])) return; |
|
120
|
|
|
echo '<li><div class="li">'; |
|
121
|
|
|
echo '<span>'; |
|
122
|
|
|
embedSVG($item['icon']); |
|
123
|
|
|
echo '</span>'; |
|
124
|
|
|
echo '<a href="' . wl($ID, 'do=admin&page=' . $item['plugin']) . '">'; |
|
125
|
|
|
echo $item['prompt']; |
|
126
|
|
|
echo '</a>'; |
|
127
|
|
|
echo '</div></li>'; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Build list of admin functions from the plugins that handle them |
|
132
|
|
|
* |
|
133
|
|
|
* Checks the current permissions to decide on manager or admin plugins |
|
134
|
|
|
* |
|
135
|
|
|
* @return array list of plugins with their properties |
|
136
|
|
|
*/ |
|
137
|
|
|
protected function getPluginList() { |
|
138
|
|
|
global $INFO; |
|
139
|
|
|
global $conf; |
|
140
|
|
|
|
|
141
|
|
|
$pluginlist = plugin_list('admin'); |
|
142
|
|
|
$menu = array(); |
|
143
|
|
|
foreach($pluginlist as $p) { |
|
144
|
|
|
/** @var \DokuWiki_Admin_Plugin $obj */ |
|
145
|
|
|
if(($obj = plugin_load('admin', $p)) === null) continue; |
|
146
|
|
|
|
|
147
|
|
|
// check permissions |
|
148
|
|
|
if($obj->forAdminOnly() && !$INFO['isadmin']) continue; |
|
149
|
|
|
|
|
150
|
|
|
$menu[$p] = array( |
|
151
|
|
|
'plugin' => $p, |
|
152
|
|
|
'prompt' => $obj->getMenuText($conf['lang']), |
|
153
|
|
|
'icon' => $obj->getMenuIcon(), |
|
154
|
|
|
'sort' => $obj->getMenuSort(), |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
// sort by name, then sort |
|
159
|
|
|
uasort( |
|
160
|
|
|
$menu, |
|
161
|
|
|
function ($a, $b) { |
|
162
|
|
|
$strcmp = strcasecmp($a['prompt'], $b['prompt']); |
|
163
|
|
|
if($strcmp != 0) return $strcmp; |
|
164
|
|
|
if($a['sort'] == $b['sort']) return 0; |
|
165
|
|
|
return ($a['sort'] < $b['sort']) ? -1 : 1; |
|
166
|
|
|
} |
|
167
|
|
|
); |
|
168
|
|
|
|
|
169
|
|
|
return $menu; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
This check looks for calls to
isset(...)orempty()on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.