检查用户是否是sysop

时间:2013-06-10 15:09:33

标签: php mediawiki

如何检查用户是否具有sysop或其他权限(在文件LocalSettings.php或扩展名中)?

1 个答案:

答案 0 :(得分:1)

好的发现:

$wgHooks['ParserFirstCallInit'][] = 'ifUserSysop';
function ifUserSysop() {

    global $wgUser;

    if (in_array("sysop", $wgUser->getEffectiveGroups())) {
        // if sysop
    }

    if($wgUser->isLoggedIn()) {
        // is logged in
    }

    return true;

}

sysop的$wgUser->getEffectiveGroups()的完整内容:

Array
(
    [0] => bureaucrat
    [1] => editor
    [2] => sysop
    [3] => *
    [4] => user
)

对于用户:

Array
(
    [0] => *
    [1] => user
)

对于anon:

Array
(
    [0] => *
)

更有趣的事情($wgUser->isAnon(), isLoggedIn(), isBlocked())可用here