Page MenuHomePhabricator

API: allow moving pages over redirects, like Special:MovePage
Open, Needs TriagePublicFeature

Description

Feature summary: Editors with the appropriate permissions should by able to use the API to move a page over an existing page. Specifically, page movers should be able to move a page over a single-edit redirect that points elsewhere, and admins should be able to move a page over any page.

Use case(s): I attempted to use the API to move a page over a single-edit redirect that pointed elsewhere. This failed. The underlying issue is that this functionality is not implemented in the API.

Benefits: This would allow developers to use the API to support move and delete actions, rather than requiring them to post through the Special:Move page.

Event Timeline

Reedy renamed this task from moveAndDelete via API to move and delete via API.May 19 2024, 1:51 PM
Reedy updated the task description. (Show Details)

Change #1034605 had a related patch set uploaded (by Sohom Datta; author: Sohom Datta):

[mediawiki/core@master] [WIP] Add ability to overwrite page on move

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

I got nerd-sniped by this task and created a rough implementation for this API parameter.

Pushing this to MediaWiki-Engineering to help figure out code review since (based on the Maintainers docs) they own the API component.

daniel renamed this task from move and delete via API to API: allow moving pages over redirects, like Special:MovePage.Thu, May 30, 3:46 PM

I did a bunch of testing of current, pre-patch behavior. It ended up being pretty complicated. Here's the results.

https://en.wikipedia.org/wiki/User_talk:Novem_Linguae#Test_results

Moving over one revision redirects pointing back to the original page

API and Special:MovePage behave identically

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

Moving over one revision redirects pointing back to a different page

API and Special:MovePage behave differently. Special:MovePage prompts the person with the page mover perm for confirmation first, then does it. API errors out.

image.png (746×1 px, 130 KB)

Moving over any page

API and Special:MovePage behave differently. Special:MovePage prompts the admin for confirmation first, then does it. API errors out.

Thoughts

I'm glad the proposed patch has the API boolean deletetarget. I think this is important for mimicking the "prompt the user" behavior mentioned above. deletetarget should default to false, and need to be set to true by the user in the API query.

Change #1040131 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] API: add tests for moving over redirects

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

Reviewing @Soda's patch I realized that there is a conceptual issue to be decided first.

The new deletetarget option proposed in the patch will delete any target page, redirect or not, if the user has the "delete" permission. That may lead to unintended deletions. Consider that, on the special page, the user is always looking at the page they are deleting. But with the API, it may be a gadget or something, running over a list of pages without supervision.

To avoid accidental deletion of "real" pages, I would suggest to make two parameters: overwrite-redirect and overwrite-anything. That way, overwrite-redirect would be safe to use even by admins, since it would refuse to delete non-redirects, even when the user has the permission to do so.

Or maybe this can be done with a single (enum) parameter: overwrite=redirects and overwrite=anything.