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

我的未来我决定 提交于 2019-12-20 01:45:13

问题


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 myskin.php file and dont know how to do it. I have been using something like this to check if a user is logged in,

<?php if($this->data['loggedin']) { ?> 

Is there anything similar to that to check if that user is a sysop?


回答1:


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';
}



回答2:


I think I got it. I added the following to my skin template to add special conditions for sysops and non sysops:

     <?php 

      global $wgUser;

      if($wgUser->isAllowed('protect')) {
         // if sysop
            echo 'Hello People';
        }

        else {
            echo 'Yo';
        }
      ?>            

I got the idea from here: Check if user is sysop

If there is a better way to do this, please do let me know. But so far, the above seems to work when I added that code to the basetemplate of my skin.



来源:https://stackoverflow.com/questions/18548706/how-to-check-if-user-is-sysop-using-php-in-mediawiki

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!