Page MenuHomePhabricator

mw.util.isTemporaryUser() should be gracious with anonymous users
Closed, ResolvedPublicFeature

Description

Feature summary
If somebody is checking user names by s = mw.config.get( "wgUserName" ) that s could be null today. When checked for future behaviour, mw.util.isTemporaryUser( s ) is crashing since the parameter is supposed to be a string.

Use case(s)
In case the parameter is null, this should be permitted and the result is true since this is an anonymous user. The process should continue for anonymous temporary users, which means not registered.

Benefits
Many people are rewriting codes now, which need to deal with the current null situation as before, but should be prepared for future answers when mw.config.get( "wgUserName" ) is always a string. This migration should be supported.

Event Timeline

Many people are rewriting codes now, which need to deal with the current null situation as before, but should be prepared for future answers when mw.config.get( "wgUserName" ) is always a string. This migration should be supported.

Is there a point in the future where mw.config.get( "wgUserName" ) will always return a string? Even with temporary accounts enabled, so long as no edits are made, then no temporary account is made.

No idea what will happen finally, but if I am reading only a temporary name might be put into cookie immediately.

Therefore all cookies will bear a user name? However, those would not appear in any database table as long no action like edit would leave traces.

Or the temporary account is created and put into cookie only when needed for database entry.

Then, there would be three cases in a JavaScript running for all page views:

  • registered, mw.config.get( "wgUserName" ) is a string and mw.util.isTemporaryUser( s ) is false.
  • not registered but already edited: mw.config.get( "wgUserName" ) is a temporary name and mw.util.isTemporaryUser( s ) is true.
  • not registered, no edits in browser sessions: mw.config.get( "wgUserName" ) is null and mw.util.isTemporaryUser( null ) is invalid.

To distinguish between registered and not registered people seems to become a challenge now. Temporary but not registered users do not have a watchlist etc., they must not move a page nor invited to touch such things.

If I understand correctly, the request here is to rework mw.util.isTemporaryUser() to return false if null is passed. That sounds fine to me.

Amdrel changed the task status from Open to In Progress.Aug 21 2024, 6:57 PM
Amdrel claimed this task.

Change #1064487 had a related patch set uploaded (by Amdrel; author: Amdrel):

[mediawiki/core@master] Update mw.util.isTemporaryUser() to return false for null usernames

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

Change #1064487 merged by jenkins-bot:

[mediawiki/core@master] Update mw.util.isTemporaryUser() to return false for null usernames

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

matmarex subscribed.

Note that mw.config.get( "wgUserIsTemp" ) is also available, as well as mw.user.isTemp(). They might be more convenient than calling this function. But this addition seems harmless to me, and will probably prevent some errors in scripts.