Skip to content

Commit 59a6ba9

Browse files
authored
Merge pull request dokuwiki#4428 from dokuwiki/menucontext
Menu: check context visibility after assembling items
2 parents 15a1533 + d9672f6 commit 59a6ba9

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

inc/Menu/AbstractMenu.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public function getItems()
4343
{
4444
$data = ['view' => $this->view, 'items' => []];
4545
Event::createAndTrigger('MENU_ITEMS_ASSEMBLY', $data, [$this, 'loadItems']);
46+
47+
$data['items'] = array_filter(
48+
$data['items'],
49+
fn($item) => $item instanceof AbstractItem && $item->visibleInContext($this->context)
50+
);
51+
4652
return $data['items'];
4753
}
4854

@@ -59,7 +65,6 @@ public function loadItems(&$data)
5965
$class = "\\dokuwiki\\Menu\\Item\\$class";
6066
/** @var AbstractItem $item */
6167
$item = new $class();
62-
if (!$item->visibleInContext($this->context)) continue;
6368
$data['items'][] = $item;
6469
} catch (\RuntimeException $ignored) {
6570
// item not available

inc/Menu/Item/Admin.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ class Admin extends AbstractItem
1212
/** @inheritdoc */
1313
public function __construct()
1414
{
15+
global $INPUT;
16+
global $INFO;
17+
1518
parent::__construct();
1619

17-
$this->svg = DOKU_INC . 'lib/images/menu/settings.svg';
18-
}
20+
if (!$INPUT->server->str('REMOTE_USER')) {
21+
throw new \RuntimeException("admin is only for logged in users");
22+
}
1923

20-
/** @inheritdoc */
21-
public function visibleInContext($ctx)
22-
{
23-
global $INFO;
24-
if (!$INFO['ismanager']) return false;
24+
if (!isset($INFO) || !$INFO['ismanager']) {
25+
throw new \RuntimeException("admin is only for managers and above");
26+
}
2527

26-
return parent::visibleInContext($ctx);
28+
$this->svg = DOKU_INC . 'lib/images/menu/settings.svg';
2729
}
2830
}

lib/exe/detail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if (!defined('DOKU_MEDIADETAIL')) define('DOKU_MEDIADETAIL', 1);
77

88
// define all DokuWiki globals here (needed within test requests but also helps to keep track)
9-
global $INPUT, $IMG, $ID, $REV, $SRC, $ERROR, $AUTH;
9+
global $INPUT, $INFO, $IMG, $ID, $REV, $SRC, $ERROR, $AUTH;
1010

1111
require_once(DOKU_INC . 'inc/init.php');
1212

0 commit comments

Comments
 (0)