Page MenuHomePhabricator

Update action API to handle temporary users
Closed, ResolvedPublic1 Estimated Story Points

Description

The action API distinguishes between anonymous and registered users in a number of ways. We need to decide how to update these, given that temporary users will be considered a separate user type compared to anonymous and registered users (see also the discussion in T337103: Decide a standard approach for classifying temporary, IP and registered users).

  • Some modules flag or filter by anon users. Should there be a separate flag/filter for temporary users? Should we use user experience flags/filters instead? Examples:
    • ApiQueryUserInfo returns anon flag - T358683
    • ApiQueryWatchlist returns anon flag - T358693
    • ApiQueryContributors returns anons count
    • ApiFeedRecentChanges accepts hideanons param - T358249
    • T351636: APIs that return anon flag:
      • ApiQueryImageInfo
      • ApiQueryLogEvents
      • ApiQueryRecentChanges
      • anything that extends ApiQueryRevisionsBase
  • IP address blocks can be made against anonymous users only. How to update this will be worked out in T338836: How should blocks treat temporary users?.
  • ApiBlockInfoTrait returns blockanononly flag
  • ApiQueryBlocks and ApiBlock accept anononly param

These flags were documented as part of T343714: Soft blocks against an IP address should block temporary accounts using that IP address. We're unlikely to rename them, since it would be a large breaking change. If we were to rename them, it would be beyond the scope of this task.

  • T351632: ApiMain accepts assert param to define allowed callers (anon, user, or bot)
  • All action APIs can die with error code notloggedin. We could add an error code for temporary users who must register.

Will be covered in T339874: Show more helpful messages when temporary users can't access features, so no more to do in this task.

  • T350701: Action and REST APIs can specify allowed user types for a parameter, via UserDef::PARAM_ALLOWED_USER_TYPES. We should add a temp user type to this list:
UserDef::PARAM_ALLOWED_USER_TYPES
  'name': User names are allowed.
  'ip': IP ("anon") usernames are allowed.
  'cidr': IP ranges are allowed.
  'interwiki': Interwiki usernames are allowed.
  'id': Allow specifying user IDs, formatted like "#123".

Related Objects

Event Timeline

The watchlist / recent changes was updated to treat hideanon as also including temporary accounts in T343322. Therefore for the ApiFeedRecentChanges API all we should need to do is update the help description for the hideanon API parameter, as the API uses the same code that was updated in T343322 based on my local testing.

I propose that the ApiQueryContributors API needs no changes for temporary accounts. The reasons for this are below.

The anoncontributors returns the count of edits made by IPs but not the IPs used. This currently does not include the number of temporary accounts, as they are listed in the contributors array under their username and user ID. The commit which added this API talked about how having a a list of all non-anonymous contributors to the page is useful and that the reason why non-anonymous contributors were instead counted was because it was not realistically possible without further schema changes (e06ad6841901df582990718f885a5a655d8c7748).

As such, using a count over a list of the temporary accounts who have made edits is probably less useful for users of this API. Furthermore, the data the API provides in the contributors array is just the username and user ID (which temporary accounts have) so no data is left out when comparing named users to temporary accounts.

Splitting the contributors list so that temporary accounts have their own list is in my own opinion unnecessary (due to there being no difference in the data returned between named and temporary accounts) and because callers would need to update their code to read from this array too.

Therefore, I feel that the temporary accounts being in the contributors array is the best way forward and as this is the current behaviour, no changes should be needed to the code.

The API currently returns the following data which I think is reasonable:

{
    "continue": {
        "pccontinue": "2|23",
        "continue": "||"
    },
    "query": {
        "pages": [
            {
                "pageid": 2,
                "ns": 1,
                "title": "Talk:Main Page",
                "anoncontributors": 1,
                "contributors": [
                    {
                        "userid": 16,
                        "name": "Dreamyjazz"
                    },
                    {
                        "userid": 24,
                        "name": "*Unregistered 1"
                    },
                    {
                        "userid": 35,
                        "name": "*Unregistered 4"
                    },
                    {
                        "userid": 36,
                        "name": "*Unregistered 5"
                    },
                    {
                        "userid": 37,
                        "name": "*Unregistered 6"
                    },
                    {
                        "userid": 39,
                        "name": "*Unregistered 8"
                    },
                    {
                        "userid": 40,
                        "name": "*Unregistered 7"
                    },
                    {
                        "userid": 41,
                        "name": "*Unregistered 9"
                    },
                    {
                        "userid": 42,
                        "name": "*Unregistered 10"
                    },
                    {
                        "userid": 43,
                        "name": "*Unregistered 11"
                    }
                ]
            }
        ]
    }
}

The API description probably doesn't need a change either because it talks about how the contributors array is for logged-in users and AFAIK temporary accounts would be included in this description. This is shown in the screenshot below:

image.png (186×1 px, 19 KB)


Therefore, given the above and that all other points in the ticket description were done in other tasks, this task can probably be closed as resolved. Moving to Needs review for thoughts on this.

Thanks @Dreamy_Jazz.

Therefore, I feel that the temporary accounts being in the contributors array is the best way forward and as this is the current behaviour, no changes should be needed to the code.

I agree that we'd be taking information away if we hid the temp account contributions behind the anon count.

I suppose we could make a separate the temporary users into a separate list ("anoncontributors", "temporarycontributors", "anoncontributors"), but I'm happy to do nothing unless we hear that there's a need for that.

image.png (186×1 px, 19 KB)

We could add something about temporary accounts, just to be abundantly clear. Although temporary users are technically logged in, some might find the term "logged-in" ambiguous, in which case they might not know without trying whether temp users would be in the user list or the anon user count. Something like "Get the list of logged-in contributors (including temporary users) and the count of anonymous contributors to a page."?

Change 1006556 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/core@master] Update summary message for ApiQueryContributors for temp accounts

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

image.png (186×1 px, 19 KB)

We could add something about temporary accounts, just to be abundantly clear. Although temporary users are technically logged in, some might find the term "logged-in" ambiguous, in which case they might not know without trying whether temp users would be in the user list or the anon user count. Something like "Get the list of logged-in contributors (including temporary users) and the count of anonymous contributors to a page."?

I've updated the summary following your suggestion in the change https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1006556/

Thanks @Dreamy_Jazz.

I suppose we could make a separate the temporary users into a separate list ("anoncontributors", "temporarycontributors", "anoncontributors"), but I'm happy to do nothing unless we hear that there's a need for that.

That seems like it would be keeping the spirit of the existing anon/registered split of contributions to a particular page. That said, I don't really know who is using it or the motivations for why this anon count / anon/registered user split was introduced ~10 years ago in rMWe06ad6841901: API: Add prop=contributors. So, I agree with @Tchanders that we can leave it until someone asks for a change.

Thanks @Dreamy_Jazz.

I suppose we could make a separate the temporary users into a separate list ("anoncontributors", "temporarycontributors", "anoncontributors"), but I'm happy to do nothing unless we hear that there's a need for that.

That seems like it would be keeping the spirit of the existing anon/registered split of contributions to a particular page. That said, I don't really know who is using it or the motivations for why this anon count / anon/registered user split was introduced ~10 years ago in rMWe06ad6841901: API: Add prop=contributors. So, I agree with @Tchanders that we can leave it until someone asks for a change.

Based on the commit summary it seems that it was because it wasn't possible without schema changes.

Dreamy_Jazz set the point value for this task to 1.Feb 28 2024, 12:12 AM

Testing notes that I used to test this change which may be useful for QA:

  1. Enable temporary accounts on your wiki
  2. Open Special:ApiSandbox
  3. Select 'query' as the action and contributors as the prop
  4. Verify that the description looks like the following:

image.png (502×1 px, 66 KB)

  1. Disable temporary accounts on your wiki
  2. Repeat steps 2 and 3
  3. Verify that the description now looks like the following:

image.png (420×1 px, 47 KB)

Change 1006556 merged by jenkins-bot:

[mediawiki/core@master] Update summary message for ApiQueryContributors for temp accounts

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

Tchanders updated the task description. (Show Details)

ApiQueryWatchlist returns recent changes information, including an anon flag. I think this needs to stay as-is, to keep in line with RecentChanges - see T343322: IP Masking: Update Recent changes filters user registration filters for IP Masking. I wondered about documenting this somewhere, but I can't see anywhere obvious.

Here is where the flag is added: https://gerrit.wikimedia.org/g/mediawiki/core/+/277e4ea01e50d64768bfb5acd26f823df4dc58a3/includes/api/ApiQueryWatchlist.php#367

ApiQueryWatchlist returns recent changes information, including an anon flag. I think this needs to stay as-is, to keep in line with RecentChanges - see T343322: IP Masking: Update Recent changes filters user registration filters for IP Masking. I wondered about documenting this somewhere, but I can't see anywhere obvious.

Here is where the flag is added: https://gerrit.wikimedia.org/g/mediawiki/core/+/277e4ea01e50d64768bfb5acd26f823df4dc58a3/includes/api/ApiQueryWatchlist.php#367

Actually, it currently returns 'anon': false for a temporary user. I've filed a separate task for this: T358693: Update ApiQueryWatchlist to handle temporary users.

dom_walden subscribed.

Testing notes that I used to test this change which may be useful for QA:

I can confirm.

Test environments: