UserFactory should have a method for constructing an anonymous User
Closed, ResolvedPublic

Description

The canonical way to construct a User instance representing an anonymous user is currently to directly call the constructor (and optionally calling setName() to set the IP address). To allow the construction of such User instances to be mocked for testing, UserFactory needs to get a method for constructing them.

Quick draft:

public function newAnonymous( $ip = null ) : User {
    $user = new User();
    if ( $ip ) {
      $user->setName( $ip );
    }
    return $user;
}

Event Timeline

DannyS712 renamed this task from UserFactory shouls have a method for constructing an anonymous User to UserFactory should have a method for constructing an anonymous User .Jul 8 2020, 3:35 PM
DannyS712 awarded a token.

Change 612672 had a related patch set uploaded (by Nikki Nikkhoui; owner: Nikki Nikkhoui):
[mediawiki/core@master] UserFactory method for getting anonymous user

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

Change 612672 merged by jenkins-bot:
[mediawiki/core@master] UserFactory method for getting anonymous user

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

daniel moved this task from Doing to Done on the Platform Team Workboards (Green) board.

@daniel can this be backported to 1.35 and change the User class to not be @newable in the 1.35 release?

@daniel can this be backported to 1.35 and change the User class to not be @newable in the 1.35 release?

There are too many usages in extensions. Removing the guarantee without giving extensions time to fix would go against the idea of a stable interface (which this was, until now). Deprecating the "newability" seems to be the appropriate approach. This just means we guarantee not to break the constructor signature before 1.36 is release.

Change 612920 had a related patch set uploaded (by DannyS712; owner: DannyS712):
[mediawiki/core@master] User is not @newable in 1.36

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

Change 612920 merged by jenkins-bot:
[mediawiki/core@master] User is not @newable in 1.36

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

Change 618296 had a related patch set uploaded (by Reedy; owner: Nikki Nikkhoui):
[mediawiki/core@REL1_35] UserFactory method for getting anonymous user

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

Change 616908 had a related patch set uploaded (by Nikki Nikkhoui; owner: Nikki Nikkhoui):
[mediawiki/core@master] UserDef DI

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

Change 616908 merged by jenkins-bot:
[mediawiki/core@master] UserDef DI

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

Change 618296 merged by jenkins-bot:
[mediawiki/core@REL1_35] UserFactory method for getting anonymous user

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