Currently:
/** * Generate standard user tool links (talk, contributions, block link, etc.) * * @since 1.16.3 * @param int $userId User identifier * @param string $userText User name or IP address * @param bool $redContribsWhenNoEdits Should the contributions link be * red if the user has no edits? * @param int $flags Customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK * and Linker::TOOL_LINKS_EMAIL). * @param int|null $edits User edit count (optional, for performance) * @param bool $useParentheses (optional) Wrap comments in parentheses where needed * @return string HTML fragment */ public static function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null, $useParentheses = true ) { [...] global $wgUser, $wgDisableAnonTalk, $wgLang; [...] $userCanBlock = MediaWikiServices::getInstance()->getPermissionManager() ->userHasRight( $wgUser, 'block' ); if ( $blockable && $userCanBlock ) { $items[] = self::blockLink( $userId, $userText ); } if ( $addEmailLink && $wgUser->canSendEmail() ) { $items[] = self::emailLink( $userId, $userText ); } [...] }
This should requires a User $viewer to be passed, to avoid using the global state
However, this function has many callers outside of core, so a user cannot be easily added as a required variable before the optional variables, and adding it to the end means that callers will need to duplicate the defaults
Proposal:
Create a new function, Linker::userToolLinksForViewer, that accepts a User parameter.
Convert Linker::userToolLinks to a wrapper for the new function that accesses global $wgUser (or RequestContext::getMain()->getUser(), not much better but allows progress on removing $wgUser in the meanwhile)
Replace uses
The new function makes it clear that the links return depend on the context user viewing the tool links