Page MenuHomePhabricator

Make it possible to specify what to do on edit conflict on action=edit
Open, MediumPublic

Description

Currently mediawiki auto-merge edits on edit conflict. It would be more useful if it was possible to specify what should happen, for example there could be variable

&editconflictresolution=[automerge|fail|overwrite]

automerge - would do what it does now
fail - would return an error in case there was any kind of edit conflict
overwrite - would ignore all edits of other people and would overwrite the page with new content

This is useful for things like antivandalism tools which need to deliver a message to users based on current content of their talkpage (the warning template level get adjusted based on templates currently present on the page). When two users post in same moment, the edit conflict get resolved by merging both messages, that have same level. Being able to fail on edit conflict would allow tool to redownload content of talk page and parse it again.

I believe that other bots / tools could use this as well when they edit the page based on current content of a page. Especially bots that are doing similar tasks.

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:54 AM
bzimport added a project: MediaWiki-API.
bzimport set Reference to bz62698.
bzimport added a subscriber: Unknown Object (MLST).
Petrb created this task.Mar 15 2014, 4:43 PM

Just for info: auto merge is mostly provided by diff3, which must not be not part of all mediawiki installation, but exist for wmf wikis. So the documentation for auto-merge should be mention, that merge is only done, when the software is there and it is a trivial merge without merge conflicts.

Note that this would need changes to EditPage::internalAttemptSave, it can't easily be done only in ApiEditPage. One additional test in the 'if' at https://git.wikimedia.org/blob/mediawiki%2Fcore.git/97a4ad45/includes%2FEditPage.php#L1697 should do it. We could either turn the "$bot" parameter into a flag parameter or add a new local for no-merge to EditPage that ApiEditPage would set.

Ideally we'd do the following:

  • editconflictresolution=automerge as default. Requires starttimestamp and basetimestamp.
  • editconflictresolution=fail would be the new code. It also would require starttimestamp and basetimestamp, and would pass the no-merge flag to EditPage.
  • editconflictresolution=overwrite would be the same as what currently happens if you omit starttimestamp and basetimestamp. It would ignore starttimestamp and basetimestamp, and the docs would say something like "Using this mode is probably wrong, automerge should be used isntead.".

As for getting there from here (i.e. without breaking BC right away), we'd need to add a fourth case: rather than defaulting to automerge, editconflictresolution not given at all would do what the API does now and additionally include a warning if starttimestamp and basetimestamp weren't both specified.

Anomie moved this task from Unsorted to Needs Code on the MediaWiki-API board.Feb 19 2015, 6:39 PM
Rillke added a subscriber: Rillke.Jun 29 2015, 7:44 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 26 2015, 7:57 AM
Elitre added a subscriber: Elitre.Nov 18 2015, 8:07 PM
Addshore updated the task description. (Show Details)
Addshore set Security to None.
Addshore added subscribers: Sj, bzimport.
SD0001 added a subscriber: SD0001.Dec 20 2019, 4:54 PM

@Anomie that link is no longer accessible, but I guess the if condition you were referring to is around L2242? Just changing that condition to if ( !$this->noAutoMerge && $this->mergeChangesIntoContent( $content ) ), and adding a noAutoMerge flag (set by ApiEditPage) would be acceptable?

Restricted Application added a project: Platform Engineering. · View Herald TranscriptDec 20 2019, 4:54 PM

That's the line, yes.

And that would be the solution proposed. It's somewhat hacky, but the real solution involves a major refactor along the lines of what was started in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/460436/ so "somewhat hacky" is good enough for now.

Change 560048 had a related patch set uploaded (by SD0001; owner: SD0001):
[mediawiki/core@master] Allow API users to opt out of auto-merge on edit conflict

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

@Anomie I've uploaded a simple patch that adds the autoMerge and fail options. For the overwrite option, I think it would be acceptable to merely null the basetimestamp and starttimestamp fields, since it seems that these two fields are only being used for conflict resolution?

My point was that those parameters are required for the conflict resolution to actually function. Unfortunately they weren't made required when the API module was first implemented, so now we need to be a bit more roundabout to get sensible behavior without breaking existing code.

Elitre removed a subscriber: Elitre.Jan 21 2020, 7:01 PM