1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
<?php
namespace dokuwiki\plugin\extension;
class Notice
{
const INFO = 'info';
const WARNING = 'warning';
const ERROR = 'error';
const SECURITY = 'security';
public const ICONS = [
self::INFO => 'ⓘ',
self::WARNING => '↯',
self::ERROR => '⚠',
self::SECURITY => '☠',
];
protected $notices = [
self::INFO => [],
self::WARNING => [],
self::ERROR => [],
self::SECURITY => [],
];
/** @var \helper_plugin_extension */
protected $helper;
/** @var Extension */
protected Extension $extension;
/**
* Not public, use list() instead
* @param Extension $extension
*/
protected function __construct(Extension $extension)
{
$this->helper = plugin_load('helper', 'extension');
$this->extension = $extension;
// FIXME sort sensibly
$this->checkDependencies();
$this->checkConflicts();
$this->checkSecurity();
$this->checkFolder();
$this->checkPHPVersion();
$this->checkUpdateMessage();
$this->checkURLChange();
$this->checkPermissions();
$this->checkUnusedAuth();
$this->checkGit();
}
/**
* Get all notices for the extension
*
* @return string[][] array of notices grouped by type
*/
public static function list(Extension $extension): array
{
$self = new self($extension);
return $self->notices;
}
/**
* Access a language string
*
* @param string $msg
* @return string
*/
protected function getLang($msg)
{
return strip_tags(preg_replace('/<br ?\/?>/', "\n", $this->helper->getLang($msg))); // FIXME existing strings should be adjusted
}
/**
* Check that all dependencies are met
* @return void
*/
protected function checkDependencies()
{
if (!$this->extension->isInstalled()) return;
$dependencies = $this->extension->getDependencyList();
$missing = [];
foreach ($dependencies as $dependency) {
$dep = Extension::createFromId($dependency);
if (!$dep->isInstalled()) $missing[] = $dep;
}
if (!$missing) return;
$this->notices[self::ERROR][] = sprintf(
$this->getLang('missing_dependency'),
join(', ', array_map(static fn(Extension $dep) => $dep->getId(true), $missing))
);
}
/**
* Check if installed dependencies are conflicting
* @return void
*/
protected function checkConflicts()
{
$conflicts = $this->extension->getConflictList();
$found = [];
foreach ($conflicts as $conflict) {
$dep = Extension::createFromId($conflict);
if ($dep->isInstalled()) $found[] = $dep;
}
if (!$found) return;
$this->notices[self::WARNING][] = sprintf(
$this->getLang('found_conflict'),
join(', ', array_map(static fn(Extension $dep) => $dep->getId(true), $found))
);
}
/**
* Check for security issues
* @return void
*/
protected function checkSecurity()
{
if ($issue = $this->extension->getSecurityIssue()) {
$this->notices[self::SECURITY][] = sprintf($this->getLang('security_issue'), $issue);
}
if ($issue = $this->extension->getSecurityWarning()) {
$this->notices[self::SECURITY][] = sprintf($this->getLang('security_issue'), $issue);
}
}
/**
* Check if the extension is installed in correct folder
* @return void
*/
protected function checkFolder()
{
if (!$this->extension->isInWrongFolder()) return;
$this->notices[self::ERROR][] = sprintf(
$this->getLang('wrong_folder'),
basename($this->extension->getCurrentDir()),
basename($this->extension->getInstallDir())
);
}
/**
* Check PHP requirements
* @return void
*/
protected function checkPHPVersion()
{
try {
Installer::ensurePhpCompatibility($this->extension);
} catch (\Exception $e) {
$this->notices[self::ERROR][] = $e->getMessage();
}
}
/**
* Check for update message
* @return void
*/
protected function checkUpdateMessage()
{
// FIXME should we only display this for installed extensions?
if ($msg = $this->extension->getUpdateMessage()) {
$this->notices[self::WARNING][] = sprintf($this->getLang('update_message'), $msg);
}
}
/**
* Check for URL changes
* @return void
*/
protected function checkURLChange()
{
if (!$this->extension->hasChangedURL()) return;
$this->notices[self::WARNING][] = sprintf(
$this->getLang('url_change'),
$this->extension->getDownloadURL(),
$this->extension->getManager()->getDownloadURL()
);
}
/**
* Check if the extension dir has the correct permissions to change
*
* @return void
*/
protected function checkPermissions()
{
try {
Installer::ensurePermissions($this->extension);
} catch (\Exception $e) {
$this->notices[self::ERROR][] = $e->getMessage();
}
}
/**
* Hint about unused auth plugins
*
* @return void
*/
protected function checkUnusedAuth()
{
global $conf;
if (
$this->extension->isEnabled() &&
in_array('Auth', $this->extension->getComponentTypes()) &&
$conf['authtype'] != $this->extension->getID()
) {
$this->notices[self::INFO][] = $this->getLang('auth');
}
}
/**
* Hint about installations by git
*
* @return void
*/
protected function checkGit()
{
if ($this->extension->isGitControlled()) {
$this->notices[self::INFO][] = $this->getLang('git');
}
}
}
|