Page MenuHomePhabricator

Allow easily extending the diff mode switcher in page history
Open, MediumPublic

Description

TL;DR: It would be nice it the switcher for the diff modes (visual and wikitext) would be easily extensible, especially for historical diffs.

Long version:
I have a user script, https://de.wikipedia.org/wiki/Benutzer:Schnark/js/diff, that adds an additional diff mode (similar to WikEdDiff). Currently, it uses it's own switcher (the tabs visible in the screenshot). This causes a bad user experience with the two different switchers, so eventually I want to adapt my script to add to the diff mode switcher provided by VE.
For the diff in the save dialog this is actually quite easy, all I'd have to do is to extend ve.ui.MWSaveDialog.prototype.initialize to add to this.reviewModeButtonSelect, and ​ve.ui.MWSaveDialog.prototype.updateReviewMode to add my listeners.
But for historical diffs, the situation is much less ideal: Not only is it impossible to reuse any of the code for the save dialog, nor is the switcher there accessible and thus extensible.
Of course, just one user script isn't enough to justify some complex code in VE, but VE is designed in most of its parts to be easily extensible, so I'd be really happy if that applied to ve.init.mw.DiffPage.init.js, too.

Event Timeline

Schnark created this task.Jul 24 2017, 8:21 AM
Restricted Application added a project: VisualEditor. · View Herald TranscriptJul 24 2017, 8:21 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Deskana renamed this task from Allow easily extending the diff mode switcher to Allow easily extending the diff mode switcher in page history.Jul 24 2017, 12:43 PM
Deskana triaged this task as Medium priority.Jul 24 2017, 12:53 PM
Deskana moved this task from To Triage to Freezer on the VisualEditor board.

I now did this in a very hacky way, see https://de.wikipedia.org/wiki/Benutzer:Schnark/js/diff.js, with such really ugly code like

$switcherContainer.find('[role="button"]').eq(currentMode === 'visual' ? 0 : 1)
	.trigger($.Event('mousedown', {which: 1}))[0].dispatchEvent(new MouseEvent('mouseup'));

to pass on clicks from my switcher to the other switcher.

Actually, due to the fact that my script supports 4 modes (diff while editing in VE, diff while editing in OWE, historical diff without VisualDiff, and historical diff including VisualDiff), but can combine the last 3 into one function, I'm not so sure, whether I'd actually any advanced features to extend the VisualDiff for historical diffs, as this would just force me to maintain 3 ways instead of 2.
So I think the only issues worth considering are:

  • The ButtonSelectWidget for switching the mode should be accessible from scripts (which would allow me to interact with it without triggering simulated click events).
  • The code that enforces a valid mode (line 19ff) should allow me to specify my own mode. Currently, when I add diffmode=schnark to the URL (which would be handled by my script), the code will reset it to source and also adapt the URL before I have a chance to react to that URL parameter.