Pergunta

In skins/Vector.php I can hide toolbox from logged out user

by adding

global $wgUser;

then

                            case 'TOOLBOX':
                               if ( $wgUser->isLoggedIn() ) {
                                    $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
               }

but User::isSysop() and similar are deprecated. It is recommended to use $user->isAllowed instead to specify a right, but how do I use this to specify the admin and bureaucrat group? Should I use some other function?

MediaWiki 1.22.2
PHP 5.3.6-13ubuntu3.10 (apache2handler)
MySQL 5.1.69-0ubuntu0.11.10.1-log
Foi útil?

Solução

User::isAllowed() asks for a permission to do something, not for a user group (which leaves it up to the wiki admin to assign different rights to different user groups). In your case, you would want a new user permission, “see-toolbar”,or something like that, that you assign to e.g. the sysop user group in LocalSettings.php:

$wgGroupPermissions['sysop']['see-toolbar']    = true;

Your extension will also have to add the right to the list of available rights: $wgAvailableRights[] = 'see-toolbar';

Finally, you will ask for the permission like this:

if ( $user->isAllowed('see-toolbar') ) {

    print toolbar here

}

Be aware that any user will still be able to bypass this restriction in a number of ways, e.g. by switching skin in their settings (or by appending ?useskin=skinname in the url). You probably want to make sure that sidebar caching is switched off too (it is off by default).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top