Page MenuHomePhabricator

[DOT] Add redirect-related parameters to API modules and return redirect URL (if any) in Wikibase editing APIs
Closed, ResolvedPublic

Description

Since Add temporary user support to most API modules, most Wikibase editing APIs automatically create a test user and return its name; however, they don’t call the TempUserCreatedRedirect hook, and so the temporary user has no chance to be persisted in CentralAuth and will soon be lost. We should return a redirect URL in the API result; the trait ApiCreateTempUserTrait from MediaWiki core can be used to get the redirect URL and add the related API parameters.

This means that every affected API will gain three parameters: returnto, returntoquery, and returntoanchor.

Related Objects

Event Timeline

Lucas_Werkmeister_WMDE renamed this task from Add redirect-related parameters to API modules and return redirect URL (if any) in Wikibase editing APIs to [DOT] Add redirect-related parameters to API modules and return redirect URL (if any) in Wikibase editing APIs.Feb 9 2024, 2:34 PM

Hm, there’s an interesting nuance here that I only realized while writing T357152. Suppose you’re an API user who’s using wbeditentity to create a new entity (e.g. with new=item), and you would like to redirect the user to the newly created entity after the edit is done. What do you set the returnto parameter to? You can’t set it to the title of the entity that’s going to be created, because you don’t yet know which entity ID the repo will assign…

IMHO it would be reasonable for wbeditentity to let the returnto parameter default to the title of the newly created entity if it wasn’t specified. (Otherwise, CentralAuth would default to the main page; if someone really desperately wants the user to be redirected to the main page, they can still put that into returnto explicitly.) I thought about instead treating the empty string specially, or some other special value, but then we have to mess with the way the parameter is validated by the API, because by default it has to be a valid title.

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

[mediawiki/extensions/Wikibase@master] Make edit APIs return temp user redirect URL

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

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

[mediawiki/extensions/Wikibase@master] Default returnto= to title for newly created entity

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

Change 1003378 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Make edit APIs return temp user redirect URL

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

Change 1003387 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Default returnto= to title for newly created entity

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

I think this is done and can be seen in the Beta Wikidata API sandbox:

image.png (338×1 px, 55 KB)

Remains to be tested that the redirect actually does the right thing.

Also, note that this will be visible on Wikidata with next week’s train – we’re adding the parameters regardless of whether IP Masking is enabled or not (they just won’t have any effect until then).

Hm, I’m not sure if CentralAuth is fully doing the right thing… I made a request with these parameters:

image.png (455×1 px, 75 KB)

It created the item and returned a tempuserredirect URL like https://login.wikimedia.beta.wmflabs.org/wiki/Special:CentralLogin/start?token=[redacted], and when I went there, I successfully ended up at the item in question, with the query and anchor preserved – but on beta dewiki I’m still not logged in. Isn’t CentralAuth supposed to automatically log me in there? (It does log me in automatically once I go to Special:UserLogin, at least.)

But anyway, that’s a CentralAuth issue at worst. In Wikibase, I think this is working \o/

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

[mediawiki/extensions/Wikibase@master] Remove dead code in LinkTitles

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

Sorry, one small follow-up that I just noticed while looking over the code again.

Change 1005561 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Remove dead code in LinkTitles

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

This is done for most API modules; wbcreateredirect and wbmergeitems are being done as part of this Gerrit change for T356149.