nomadjimbob / mikio

Customizable, Bootstrap 4 inspired template for Dokuwiki
GNU General Public License v2.0
24 stars 6 forks source link

Hide edit page button #93

Open armandostyl opened 2 months ago

armandostyl commented 2 months ago

Hi,

If I were to hide the edit page button from all users except for a certain group (e.g. "moderators"), how would I go about editing the template? I tried adding a conditional $_SERVER['REMOTE_USER'] == "@moderators" at

    if (
        $ACT === 'show' && ($showPageTools === 'always' || $TEMPLATE->userCanEdit() === true &&
        $showPageTools === 'page editors')
    ) {
        $TEMPLATE->includePageTools(true, true);
    }

but it didn't work.

nomadjimbob commented 2 months ago

Checking if a user is in a group is a little more complex from what I can see in the documentation. To achieve this you will need to modify the includePageTools method within the mikio.php file (note this will be overwritten in updates so not the best approach).


public function includePageTools(bool $print = true, bool $includeId = false): string
    {
        global $USERINFO;

        // START CUSTOM CODE
        // determine if the current user is in the moderators group and
        // set $showEditPage
        global $_SESSION;
        $showEditPage = false;

        if (isset($_SESSION[DOKU_COOKIE]['auth']['info']['grps']) && 
            is_array($_SESSION[DOKU_COOKIE]['auth']['info']['grps']) &&
            in_array('moderators', $_SESSION[DOKU_COOKIE]['auth']['info']['grps'], true)) {
            $showEditPage = true;
        }
        // END CUSTOM CODE

        // ......

            $classes = array_unique($classes);
            $title = isset($attr['title']) && $attr['title'] !== 0 ? $attr['title'] : $item->getTitle();

            // START CUSTOM CODE
            // if we are working with the page edit button, check if we should
            // show it to the current user
            if(!$showEditPage && in_array('edit', $classes)) {
                continue;
            }
            // END CUSTOM CODE

        // ......
armandostyl commented 1 month ago

Is there a better way to implement this though?

nomadjimbob commented 1 month ago

No, not without building it into the template itself as a configuration option