Page MenuHomePhabricator

[S] Make trait for APIs to create a temporary account
Closed, ResolvedPublic

Description

Background

Currently ApiEditPage is the only API that creates a temporary account.

Other APIs need to do the same. The general workflow is described here (from T340540#9201679):

  1. accept "returnto" parameters 2) if logged-out, create an unsaved temp user at the start 3) use it for permission checks throughout 4) once you've checked everything and are sure that the action will go through, save the user 5) return whether a temp user was created, and the result of running the onTempUserCreatedRedirect() hook with the "returnto" parameters. However, a lot of this logic could probably be shared, using something similar to ApiWatchlistTrait.
What needs doing

This example shows what another API needed to copy from ApiEditPage, that should be moved into a trait :

QA Results - Local

Event Timeline

Tchanders renamed this task from Make trait for APIs to create a temporary account to [S] Make trait for APIs to create a temporary account.Oct 30 2023, 4:31 PM

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

[mediawiki/core@master] Add ApiCreateTempUserTrait for APIs that create temporary users

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

Change 970438 merged by jenkins-bot:

[mediawiki/core@master] Add ApiCreateTempUserTrait for APIs that create temporary users

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

Testing steps

  • Enable and configure CentralAuth (probably easiest with Docker: https://www.mediawiki.org/wiki/MediaWiki-Docker/Extension/CentralAuth)
  • Set $wgAutoCreateTempUser['enabled'] = true;
  • As a logged-out user, perform an edit using ApiEdit (e.g. from Special:ApiSandbox#action=edit&format=json&title=Main_page&appendtext=.&token=%2B%5C&formatversion=2)
  • The result should be successful and should contain:
    • "tempusercreated": true,
    • "tempusercreatedredirect": "http://localhost/mediawiki/core/index.php/Special:CentralLogin/start?token=cb5faba93edf9bd980af196d9409e8c7" <--- or some similar URL
  • Visiting that URL should redirect you to the page you edited
  • You should now be logged in as a temporary user

You should also be able to control where the URL returns you to by using the API parameters returnto, returntoquery and returntoanchor.

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

[mediawiki/core@master] ApiCreateTempUserTrait: Pass a default value to redirect hook

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

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

[mediawiki/core@master] Add test for ApiCreateTempUserTrait

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

Change 971513 merged by jenkins-bot:

[mediawiki/core@master] ApiCreateTempUserTrait: Pass a default value to redirect hook

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

Change 971983 merged by jenkins-bot:

[mediawiki/core@master] Add test for ApiCreateTempUserTrait

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

@Tchanders "tempusercreated" is set to true and "tempusercreatedredirect" is the URL that you have edited. Also returnto, returntoquery and returntoanchor goes to the URL specified as seen in the .webm's below. This will be moved to Done. Thanks for the testing steps and all your work!

Status: ✅PASS
Environment: Local: 1.42.0-alpha (16d56c4)14:31, 7 November 2023. CentralAuth: (8967265) 08:07, 7 November 2023. AntiSpoof: (d67b5ab) 18:56, 4 November 2023
OS: macOS Sonoma 14.0
Browser: Chrome 119
Device: MBA M2
Emulated Device:: n/a
Test Links:
http://loginwiki.localhost:8081/wiki/index.php/Special:ApiSandbox#action=edit&format=json&title=Main_page&appendtext=.&token=%2B%5C&returnto=Dog&returntoanchor=%23Tail&formatversion=2

✅AC1:https://phabricator.wikimedia.org/T349223#9304729

API_Editreturntoreturntoqueryreturntoanchor