Page MenuHomePhabricator

Modernize and replace Linker::userLink
Closed, ResolvedPublic

Description

The method has a weird signature:

public static function userLink( $userId, $userName, $altUserName = false ) {

which requires the caller to pass the ID and name separately. Additionally, the case with ID==0 can be used to link to external users (via ExternalUserNames). In fact, the ID is only used to detect anons and external users.

Instead, I believe that the function should simply accept a UserIdentity object, to derive the name, whether the user is anonymous, and whether it's external (with getWikiId()). I also wonder whether the method should be moved to LinkRenderer, or perhaps a new service.

Event Timeline

I guess this is the same as or related to T12663, which is slightly older. In that tasks there are some concerns about User object being heavy, which is a problem with the User class (not Linker), and the reason why nowadays we have UserIdentity to use here.

This method is just the tip of the Linker iceberg: ::userToolLinks, ::userToolLinksRedContribs, ::userTalkLink, etc. have the same pattern, and some of them are wrappers (or wrappers of wrappers). So

perhaps a new service.

would indeed be desirable for all of them.

This method is just the tip of the Linker iceberg: ::userToolLinks, ::userToolLinksRedContribs, ::userTalkLink, etc. have the same pattern, and some of them are wrappers (or wrappers of wrappers).

Good point.

So

perhaps a new service.

would indeed be desirable for all of them.

WFM. Something like UserLinker? I assume it could also share some logic with LinkRenderer (either by using LinkRenderer directly, or creating a common trait if necessary).

whether it's external (with getWikiId())

UserIdentityValue
public static function newExternal( string $prefix, string $name, $wikiId = self::LOCAL ): self {
	// > is a standard separator for external users in the database, see ExternalUserNames
	return new self( 0, "$prefix>$name", $wikiId );
}

getWikiId apparently is not the clue you discover an external user with.

Change 793716 had a related patch set uploaded (by Matěj Suchánek; author: Matěj Suchánek):

[mediawiki/core@master] [POC] UserLinker

https://gerrit.wikimedia.org/r/793716

Change #1118847 had a related patch set uploaded (by Máté Szabó; author: Máté Szabó):

[mediawiki/core@master] linker: Introduce UserLinkRenderer service

https://gerrit.wikimedia.org/r/1118847

Change #1118847 merged by jenkins-bot:

[mediawiki/core@master] linker: Introduce UserLinkRenderer service

https://gerrit.wikimedia.org/r/1118847

Change #793716 abandoned by Matěj Suchánek:

[mediawiki/core@master] [POC] UserLinker

https://gerrit.wikimedia.org/r/793716