I'm working on an extension to be used on my wiki which would give classes showing their user groups to the user links that have the mw-userlink class. The reason I want to do this is because I want to format the links for certain user groups differently in CSS.
Here is the php code that I'm using for MediaWiki core:
$wgHooks['HtmlPageLinkRendererBegin'][] = 'handle_link';
function handle_link( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) {
if(strpos($customAttribs['class'], 'mw-userlink') !== false){
$username = explode(':',$target)[1];
if(strpos($username,'/') !== false){
$username = explode('/',$username)[1];
}
$customAttribs['class'] = $customAttribs['class'] . ' mw-userlink-user-' . $username . get_user_group_classes($username,'mw-userlink-group-');
}
return true;
}
function get_user_group_classes($username,$groupprefix,$commonclass){
$ret = '';
if($commonclass){
$ret = $ret . ' ' . $commonclass;
}
$user = User::newFromName( $username );
if(!$user){
$ret = $ret . ' ERROR-with-user-' . $username;
return $ret;
}
$groups = $user->getGroups();
foreach($groups as $key => $group){
$ret = $ret . ' ' . $groupprefix . $group;
}
return $ret;
}The only problem I have is I don't know what code I need to use in order to affect the user links that have the mw-userlink class on the Flow boards without directly modifiying the files of the Flow extension or other extensions. What should I do?