Skip to content

Commit c408a2a

Browse files
authored
Merge pull request dokuwiki#4374 from dokuwiki/extensionlabels
Extension Manager: use characters for messages
2 parents 18c84d9 + f17690f commit c408a2a

File tree

13 files changed

+109
-29
lines changed

13 files changed

+109
-29
lines changed

lib/plugins/extension/GuiAdmin.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public function tabPlugins()
6464
$html .= '</div>';
6565

6666
$plugins = (new Local())->getPlugins();
67+
try {
68+
// initialize remote data in one go
69+
Repository::getInstance()->initExtensions(array_keys($plugins));
70+
} catch (Exception $e) {
71+
msg($e->getMessage(), -1); // this should not happen
72+
}
6773

6874
$html .= '<div id="extension__list">';
6975
$html .= '<form action="' . $this->tabURL('plugins') . '" method="post">';
@@ -91,6 +97,12 @@ public function tabTemplates()
9197
$html .= '</div>';
9298

9399
$templates = (new Local())->getTemplates();
100+
try {
101+
// initialize remote data in one go
102+
Repository::getInstance()->initExtensions(array_keys($templates));
103+
} catch (Exception $e) {
104+
msg($e->getMessage(), -1); // this should not happen
105+
}
94106

95107
$html .= '<div id="extension__list">';
96108
$html .= '<form action="' . $this->tabURL('templates') . '" method="post">';

lib/plugins/extension/GuiExtension.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ protected function thumbnail()
7575
$img = [
7676
'width' => self::THUMB_WIDTH,
7777
'height' => self::THUMB_HEIGHT,
78+
'class' => 'shot',
79+
'loading' => 'lazy',
7880
'alt' => '',
7981
];
8082

@@ -144,8 +146,12 @@ protected function notices()
144146
foreach ($messages as $message) {
145147
$message = hsc($message);
146148
$message = nl2br($message);
147-
$message = '<span>' . Notice::ICONS[$type] . '</span> ' . $message;
148149
$message = preg_replace('/`([^`]+)`/', '<bdi>$1</bdi>', $message);
150+
$message = sprintf(
151+
'<span class="icon">%s</span><span>%s</span>',
152+
inlineSVG(Notice::icon($type)),
153+
$message
154+
);
149155
$html .= '<li class="' . $type . '"><div class="li">' . $message . '</div></li>';
150156
}
151157
}
@@ -313,15 +319,17 @@ protected function popularity()
313319
if (!$popularity) return '';
314320
if ($this->extension->isBundled()) return '';
315321

322+
$popimg = '<img src="' . DOKU_BASE . 'lib/plugins/extension/images/fire.svg" alt="🔥" />';
323+
316324
if ($popularity > 0.25) {
317325
$title = $this->getLang('popularity_high');
318-
$emoji = '🔥🔥🔥';
326+
$emoji = str_repeat($popimg, 3);
319327
} elseif ($popularity > 0.15) {
320328
$title = $this->getLang('popularity_medium');
321-
$emoji = '🔥🔥';
329+
$emoji = str_repeat($popimg, 2);
322330
} elseif ($popularity > 0.05) {
323331
$title = $this->getLang('popularity_low');
324-
$emoji = '🔥';
332+
$emoji = str_repeat($popimg, 1);
325333
} else {
326334
return '';
327335
}

lib/plugins/extension/Installer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,17 @@ public function downloadArchive($url)
288288
// download
289289
$http = new DokuHTTPClient();
290290
$http->max_bodysize = 0;
291-
$http->timeout = 25; //max. 25 sec
292291
$http->keep_alive = false; // we do single ops here, no need for keep-alive
293292
$http->agent = 'DokuWiki HTTP Client (Extension Manager)';
294293

294+
// large downloads may take a while on slow connections, so we try to extend the timeout to 4 minutes
295+
// 4 minutes was chosen, because HTTP servers and proxies often have a 5 minute timeout
296+
if (php_sapi_name() === 'cli' || @set_time_limit(60 * 4)) {
297+
$http->timeout = 60 * 4 - 5; // nearly 4 minutes
298+
} else {
299+
$http->timeout = 25; // max. 25 sec (a bit less than default execution time)
300+
}
301+
295302
$data = $http->get($url);
296303
if ($data === false) throw new Exception('error_download', [$url, $http->error, $http->status]);
297304

lib/plugins/extension/Notice.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class Notice
99
public const ERROR = 'error';
1010
public const SECURITY = 'security';
1111

12-
public const ICONS = [
13-
self::INFO => '',
14-
self::WARNING => '',
15-
self::ERROR => '',
16-
self::SECURITY => '',
12+
protected const ICONS = [
13+
self::INFO => 'I',
14+
self::WARNING => 'W',
15+
self::ERROR => 'E',
16+
self::SECURITY => 'S',
1717
];
1818

1919
protected $notices = [
@@ -61,6 +61,30 @@ public static function list(Extension $extension): array
6161
return $self->notices;
6262
}
6363

64+
/**
65+
* Return the icon path for a notice type
66+
*
67+
* @param string $type The notice type constant
68+
* @return string
69+
*/
70+
public static function icon($type): string
71+
{
72+
if (!isset(self::ICONS[$type])) throw new \RuntimeException('Unknown notice type: ' . $type);
73+
return __DIR__ . '/images/' . $type . '.svg';
74+
}
75+
76+
/**
77+
* Return the character symbol for a notice type used on CLI
78+
*
79+
* @param string $type The notice type constant
80+
* @return string
81+
*/
82+
public static function symbol($type): string
83+
{
84+
if (!isset(self::ICONS[$type])) throw new \RuntimeException('Unknown notice type: ' . $type);
85+
return self::ICONS[$type][0] ?? '';
86+
}
87+
6488
/**
6589
* Access a language string
6690
*

lib/plugins/extension/Repository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function initExtensions($ids)
135135
// first get all that are cached
136136
foreach ($ids as $id) {
137137
$data = $this->retrieveCache($id);
138-
if ($data === null) {
138+
if ($data === null || $data === []) {
139139
$toload[] = $id;
140140
} else {
141141
$result[$id] = Extension::createFromRemoteData($data);
@@ -147,7 +147,7 @@ public function initExtensions($ids)
147147
$this->fetchExtensions($toload);
148148
foreach ($toload as $id) {
149149
$data = $this->retrieveCache($id);
150-
if ($data === null) {
150+
if ($data === null || $data === []) {
151151
$result[$id] = null;
152152
} else {
153153
$result[$id] = Extension::createFromRemoteData($data);

lib/plugins/extension/cli.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ protected function setup(Options $options)
3030
$options->setHelp(
3131
"Manage plugins and templates for this DokuWiki instance\n\n" .
3232
"Status codes:\n" .
33-
" i - installed " . Notice::ICONS[Notice::SECURITY] . " - security issue\n" .
34-
" b - bundled with DokuWiki " . Notice::ICONS[Notice::ERROR] . " - extension error\n" .
35-
" g - installed via git " . Notice::ICONS[Notice::WARNING] . " - extension warning\n" .
36-
" d - disabled " . Notice::ICONS[Notice::INFO] . " - extension info\n" .
33+
" i - installed " . Notice::symbol(Notice::SECURITY) . " - security issue\n" .
34+
" b - bundled with DokuWiki " . Notice::symbol(Notice::ERROR) . " - extension error\n" .
35+
" g - installed via git " . Notice::symbol(Notice::WARNING) . " - extension warning\n" .
36+
" d - disabled " . Notice::symbol(Notice::INFO) . " - extension info\n" .
3737
" u - update available\n"
3838
);
3939

@@ -258,7 +258,11 @@ protected function cmdSearch($query, $showdetails, $max)
258258
*/
259259
protected function cmdList($showdetails, $filter)
260260
{
261-
$this->listExtensions((new Local())->getExtensions(), $showdetails, $filter);
261+
$extensions = (new Local())->getExtensions();
262+
// initialize remote data in one go
263+
Repository::getInstance()->initExtensions(array_keys($extensions));
264+
265+
$this->listExtensions($extensions, $showdetails, $filter);
262266
return 0;
263267
}
264268

@@ -309,10 +313,10 @@ protected function listExtensions($list, $details, $filter = '')
309313
}
310314

311315
$notices = Notice::list($ext);
312-
if ($notices[Notice::SECURITY]) $status .= Notice::ICONS[Notice::SECURITY];
313-
if ($notices[Notice::ERROR]) $status .= Notice::ICONS[Notice::ERROR];
314-
if ($notices[Notice::WARNING]) $status .= Notice::ICONS[Notice::WARNING];
315-
if ($notices[Notice::INFO]) $status .= Notice::ICONS[Notice::INFO];
316+
if ($notices[Notice::SECURITY]) $status .= Notice::symbol(Notice::SECURITY);
317+
if ($notices[Notice::ERROR]) $status .= Notice::symbol(Notice::ERROR);
318+
if ($notices[Notice::WARNING]) $status .= Notice::symbol(Notice::WARNING);
319+
if ($notices[Notice::INFO]) $status .= Notice::symbol(Notice::INFO);
316320

317321
echo $tr->format(
318322
[20, 5, 12, '*'],
@@ -347,7 +351,7 @@ protected function listExtensions($list, $details, $filter = '')
347351
foreach ($msgs as $msg) {
348352
echo $tr->format(
349353
[7, '*'],
350-
['', Notice::ICONS[$type] . ' ' . $msg],
354+
['', Notice::symbol($type) . ' ' . $msg],
351355
[null, Colors::C_LIGHTBLUE]
352356
);
353357
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
enabled.png - CC0, (c) Tanguy Ortolo
2-
disabled.png - public domain, (c) Tango Desktop Project http://commons.wikimedia.org/wiki/File:Dialog-information.svg
31
plugin.png - public domain, (c) nicubunu, http://openclipart.org/detail/15093/blue-jigsaw-piece-07-by-nicubunu
42
template.png - public domain, (c) mathec, http://openclipart.org/detail/166596/palette-by-mathec
53

6-
coffee.png - CC0, (c) Office 31, https://www.svgrepo.com/svg/301068/coffee-cup-coffee
4+
coffee.svg - CC0, (c) Office 31, https://www.svgrepo.com/svg/301068/coffee-cup-coffee
75
bug.svg - PD, (c) Mary Akveo, https://www.svgrepo.com/svg/468140/bug
6+
fire.svg - CC0, (c) SVG Repo, https://www.svgrepo.com/svg/404501/burn-fire-flame-hot

0 commit comments

Comments
 (0)