How to check if user is Sysop using Php in Mediawiki?

后端 未结 2 496
醉话见心
醉话见心 2021-01-21 00:12

I am trying to add a div to my sidebar and I only want this block to show to administrators. How can I check if a user is an administrator in php? I am trying to add this to mys

2条回答
  •  感动是毒
    2021-01-21 00:44

    The code in the answer by *blackops_programmer* checks whether the user can protect pages. Per default, that would be sysops, but the permission can be assigned or removed from any group.

    If what you want to do depends on the right to protect pages, then checking the permission is the correct way (except you should use $this->getUser(), not $wgUser). However, if you really want to check for the sysop group, use this:

    if ( in_array( 'sysop', $this->getUser()->getEffectiveGroups() ) {
      echo 'Hello People';
    }
    

提交回复
热议问题