Page MenuHomePhabricator

Create a temporary user from ApiSetClaim
Closed, ResolvedPublic

Description

Background

Using ApiSetClaim as an (anonymous) IP user causes the creation of an actor with an IP address as their user name, which is then visible in Special:RecentChanges. This happens even with temporary accounts enabled, because temporary accounts are only currently created for workflows that go via EditPage.

After T345578: Ensure that an IP address cannot be saved permanently if IP Masking is enabled, this would throw an error.

Instead, we should create a temporary user actor, similar to EditPage.

Event Timeline

This is a problem that will likely affect many workflows (see parent task). We're using this particular workflow to provide an example of what to do, mainly because @Cparle first raised it to me while investigating T340540: Update WikibaseMediaInfo for IP Masking.

The draft example patch takes the approach outlined by @matmarex in T340540#9201679.

Change 966585 had a related patch set uploaded (by Tchanders; author: Tchanders):

[mediawiki/extensions/Wikibase@master] WIP example: Create a temporary user from ApiSetClaim

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

The draft example patch takes the approach outlined by @matmarex in T340540#9201679.

I don't have a good understanding of this API, but here's how I tested the patch:

  1. Create a new property from Special:NewProperty
  2. Log out (or end the temp user session)
  3. As an anon user, make an API call to ApiSetClaim. I used Special:APISandbox, with the following claim (which might well be nonsense!):
{
    "type": "statement",
    "mainsnak": {
      "snaktype": "novalue",
      "property": <ID of my new property prefixed with P, e.g. P13>
    },
    "id": <something in a valid format, though it was meaningless to my wiki, e.g. Q1$5627445f-43cb-ed6d-3adb-760e85bd17ep>
}
  1. On success, I am now a temporary user and the API returns a redirect URL, where the token encodes any returnto (etc) parameters:
{
    "pageinfo": {
        "lastrevid": 1613
    },
    "success": 1,
    "claim": {
        "mainsnak": {
            "snaktype": "novalue",
            "property": "P13",
            "hash": "e7d6827df23a6077c04b3b03a87a028e620b3583",
            "datatype": "wikibase-property"
        },
        "type": "statement",
        "id": "Q1$5627445f-43cb-ed6d-3adb-760e85bd17ep",
        "rank": "normal"
    },
    "tempusercreated": true,
    "tempusercreatedredirect": "http://localhost/mediawiki/core/index.php/Special:CentralLogin/start?token=cb3f1d49726e38d06f56fd5472caf5be"
}

Config:

  • CentralAuth loaded and configured
  • $wgAutoCreateTempUser['enabled'] = true;
  • $wgAutoCreateTempUser['actions'] contains 'edit' (i.e. I didn't override the default)

Change 966585 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Add temporary user support to most API modules

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

Change 992400 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[operations/mediawiki-config@master] beta: Don’t prevent * from editing if IP masking enabled

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

Change 992400 merged by jenkins-bot:

[operations/mediawiki-config@master] beta: Don’t prevent * from editing if IP masking enabled

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

kostajh claimed this task.