some cleanup in the usertool handling

do not display unavailable actions
This commit is contained in:
Andreas Gohr 2023-07-10 13:40:06 +02:00
commit 621124b325

View file

@ -1,4 +1,10 @@
<?php <?php
use dokuwiki\Menu\Item\AbstractItem;
use dokuwiki\Menu\Item\Admin;
use dokuwiki\Menu\Item\Login;
use dokuwiki\Menu\Item\Register;
if (!defined('DOKU_INC')) die(); if (!defined('DOKU_INC')) die();
if ($conf['useacl']): ?> if ($conf['useacl']): ?>
@ -6,39 +12,38 @@
<nav id="dokuwiki__usertools" class="nav-usertools <?php echo $navClass ?>"> <nav id="dokuwiki__usertools" class="nav-usertools <?php echo $navClass ?>">
<h6 class="sr-only" role="heading" aria-level="2"><?php echo $lang['user_tools']; ?></h6> <h6 class="sr-only" role="heading" aria-level="2"><?php echo $lang['user_tools']; ?></h6>
<ul> <ul>
<li class="log"><?php <?php
try { try {
if (empty($_SERVER['REMOTE_USER'])) { $item = new Login();
echo (new \dokuwiki\Menu\Item\Login())->asHtmlLink(); if ($item->visibleInContext(AbstractItem::CTX_DESKTOP))
} else { echo '<li class="log">' . $item->asHtmlButton() . '</li>';
echo (new \dokuwiki\Menu\Item\Login())->asHtmlButton(); } catch (RuntimeException $ignored) {
}
} catch (\RuntimeException $ignored) {
// item not available // item not available
} }
?>
</li>
<?php
if (!empty($_SERVER['REMOTE_USER'])) { if (!empty($_SERVER['REMOTE_USER'])) {
echo '<li class="user"><span class="sr-only">' . $lang['loggedinas'] . ' </span>' . userlink() . '</li>'; echo '<li class="user"><span class="sr-only">' . $lang['loggedinas'] . ' </span>' . userlink() . '</li>';
}?> }
<?php /* dokuwiki user tools */
try { try {
echo '<li class="admin">' . (new \dokuwiki\Menu\Item\Admin())->asHtmlLink() . '</li>'; $item = new Admin();
} catch(\RuntimeException $ignored) { if ($item->visibleInContext(AbstractItem::CTX_DESKTOP)) {
echo '<li class="admin">' . $item->asHtmlLink() . '</li>';
}
} catch (RuntimeException $ignored) {
// item not available // item not available
} }
try { try {
echo '<li class="register">' . (new \dokuwiki\Menu\Item\Register())->asHtmlLink() . '</li>'; $item = new Register();
} catch(\RuntimeException $ignored) { if ($item->visibleInContext(AbstractItem::CTX_DESKTOP)) {
echo '<li class="register">' . $item->asHtmlLink() . '</li>';
}
} catch (RuntimeException $ignored) {
// item not available // item not available
} }
?>
<?php /* tasks do Plug-In */ /** @var helper_plugin_do $doplugin */
/** @var \helper_plugin_do $doplugin */
$doplugin = plugin_load('helper', 'do'); $doplugin = plugin_load('helper', 'do');
if ($doplugin !== null && isset($_SERVER['REMOTE_USER'])) { if ($doplugin !== null && isset($_SERVER['REMOTE_USER'])) {
$icon = $doplugin->tpl_getUserTasksIconHTML(); $icon = $doplugin->tpl_getUserTasksIconHTML();