phpmediawiki

How do I list which groups a user is in for my MediaWiki extension?


I'm writing an extension that will allow me to add the magic words: CURRENTUSER, CURRENTUSERREALNAME, CURRENTUSERLANGABBR, and I wanted CURRENTUSERGROUPS. That section of my code is currently:

function wfGetCustomVariable(&$parser,&$cache,&$index,&$ret) {
    switch ($index) {
        case MAG_CURRENTUSER:
            $parser->disableCache(); # Mark this content as uncacheable
            $ret = $GLOBALS['wgUser']->mName;
            break;
        case MAG_CURRENTUSERREALNAME:
            $parser->disableCache(); # Mark this content as uncacheable
            $ret = $GLOBALS['wgUser']->mRealName;
            break;
        case MAG_CURRENTUSERLANGABBR
            $parser->disableCache(); # Mark this content as uncacheable
            $ret = $GLOBALS['wgLang']->getCode();
            break;
    }
    return true;
}

However, I can't seem to find the $GLOBAL for the array of groups the user is in anywhere in the MediaWiki documentation. I've looked in Manual:Configuration_settings, Manual:LocalSettings.php, Manual:CommonSettings.php, Manual:$wgGroupPermissions, and Help:User_rights. In none of them do I see any explanation of how to get a simple (comma/semi-colon/etc..) delimited list of the current user's groups. Can anyone help me please?


Solution

  • Have a look at http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/User.php?view=markup#l2300:

    $GLOBALS['wgUser']->getGroups()
    

    ...which of course will return an array, not delimiter-separated string.