Page MenuHomePhabricator

Review changes button does not show diff in Visual mode
Closed, ResolvedPublic

Assigned To
Authored By
kostajh
Apr 23 2021, 1:01 PM
Referenced Files
F34451024: Screen Shot 2021-05-11 at 5.48.20 PM.png
May 12 2021, 1:09 AM
F34451022: Screen Shot 2021-05-11 at 5.23.28 PM.png
May 12 2021, 1:09 AM
F34451032: Screen Shot 2021-05-11 at 6.03.32 PM.png
May 12 2021, 1:09 AM
F34451012: Screen Shot 2021-05-11 at 5.39.03 PM.png
May 12 2021, 1:09 AM
F34451019: Screen Shot 2021-05-11 at 5.44.54 PM.png
May 12 2021, 1:09 AM
F34451010: Screen Shot 2021-05-11 at 5.32.44 PM.png
May 12 2021, 1:09 AM
F34448990: image.png
May 10 2021, 10:20 AM
F34448005: addlink-visual-diff.png
May 9 2021, 7:31 PM

Description

If the user accepts a link recommendation, the AddLink plugin will make an edit to the page and the save dialog (T269657: Add a link: edit summary and publish) shows the standard VE dialog with the main contents overridden, and a "Review your changes" button.

grafik.png (505×689 px, 91 KB)

The "Review your changes" dialog for changes created by the AddLink plugin won't show the visual changes.

grafik.png (378×964 px, 90 KB)

Viewing in wikitext will work though:

grafik.png (861×955 px, 156 KB)

On a regular VisualEditor edit, adding a link results in Visual diff changes like this:

grafik.png (861×955 px, 362 KB)

Details

Event Timeline

kostajh triaged this task as Medium priority.

If you add a normal link and look at the visual diff, there is a small "Link added: XXX" annotation on the right side. (Is that a new feature? I don't recall seeing it in the past.) Looks like we'd need to implement the describeChange or describeAdded/describeRemoved methods on the annotation data model for that. Maybe that would solve this issue as well.

In terms of effort to lines of code written ratio, this was pretty extreme. The process for generating a visual diff is something like:

  • the recommended link annotations are applied to the DOM via their Annotation.toDomElements method (which wraps the link text in an <a> tag for accepted annotations, and is a no-op otherwise)
  • ve.dm.Converter.getModelFromDom converts the DOM to the linear model, via ve.dm.Converter.getDataFromDomSubtree which very roughly does a preorder DOM tree traversal, turns DOM nodes to model objects (based on model properties like matchTagNames, matchRdfaTypes or matchFunction, and then ve.dm.Model.toDataElement as a second pass), and then turns model objects to object literals with ve.dm.Model.toDataElement.
  • ve.dm.Document.buildNodeTree converts the linear data back to the data model (a ve.dm.Node tree)
  • that node tree and the node tree representing the original, unedited document are compared via ve.dm.VisualDiff.diffList which finds which are the matching nodes between the original and the new document, and identifies changed nodes by comparing their linear data via ve.dm.ElementLinearData.compareElements, which relies on diffing the plain objects given by ve.dm.Annotation.getComparableObject for all the annotations on the text.

That last step is where things went wrong. Because we use the Parsoid load hook to include the initial annotations in the document, VE considered it part of the original revision, so it all came down to comparing the getComparableObject() output of an undecided and an accepted/rejected annotation, and the acceptance state of course was not represented in that object.

One very painful gotcha that was that the visual diff code has a timer and if it decides diffing goes slowly (which of course is always the case when stepping through it in a debugger), it switches to a dumber alternative algorithm which more or less just compares top-level nodes of the node tree, and in that comparison annotations are completely ignored (so the patch seemingly has no effect when viewed in a debugger).

@RHo some notes:

addlink-visual-diff.png (761×898 px, 173 KB)

  • Only added links are shown in the diff, not rejected ones - I figured those aren't really changes to the article, and don't show up in the wikitext diff either, so it would be less confusing this way. Easy to change though.
  • There's a sidebar with a message "Link accepted", much like how the visual diff would show "Link added" etc. for other, non-addlink types of changes. If it's not considered useful (given that there is only really one kind of change - although that won't be the case once we implement editing the link target), we can just skip returning the message and the sidebar won't show up. (Also let me know if you prefer a different text.)
  • The visual diff uses green for additions, red for deletions and blue for changes. For reasons to do with internals of the diff logic, link suggestions count as changes, even if conceptually it would be more correct to say we are adding something to the document. I don't think there's a clean way to change that. If it's considered a big problem, we could probably hack around it with custom CSS rules.

Change 687783 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/extensions/GrowthExperiments@master] Add Link: Fix visual diff

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

Thanks for the notes @Tgr - replies inline.

@RHo some notes:

addlink-visual-diff.png (761×898 px, 173 KB)

  • Only added links are shown in the diff, not rejected ones - I figured those aren't really changes to the article, and don't show up in the wikitext diff either, so it would be less confusing this way. Easy to change though.

Agree that rejections and skips should not be shown. This corresponds to the logic for the scenario where no links are added, where we do not show the "review your changes" button at all:

image.png (976×1 px, 91 KB)

  • There's a sidebar with a message "Link accepted", much like how the visual diff would show "Link added" etc. for other, non-addlink types of changes. If it's not considered useful (given that there is only really one kind of change - although that won't be the case once we implement editing the link target), we can just skip returning the message and the sidebar won't show up. (Also let me know if you prefer a different text.)

I'd prefer to not show the message or sidebar at all please.

  • The visual diff uses green for additions, red for deletions and blue for changes. For reasons to do with internals of the diff logic, link suggestions count as changes, even if conceptually it would be more correct to say we are adding something to the document. I don't think there's a clean way to change that. If it's considered a big problem, we could probably hack around it with custom CSS rules.

This is fine as is.

Change 687783 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] Add Link: Fix visual diff

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

Etonkovidova subscribed.

All looks and works according to the specs (no issues) - also I ran a comparison check with VE diffs for when normal links are added.

Moving for @RHo for design review.
Noitce:

  • the edit summary fo Add link is automatically populated with the info on how many links are marked with 'yes', 'no' and how many
  • (different from VE) for Add link Review your changes dialog doesn't have options for marking edits as minor and adds automatically the edited page to a user's Watchlist.
VE links addedSuggested links added
Screen Shot 2021-05-11 at 5.23.28 PM.png (1×2 px, 933 KB)
Screen Shot 2021-05-11 at 5.48.20 PM.png (1×1 px, 242 KB)
Screen Shot 2021-05-11 at 5.32.44 PM.png (1×2 px, 707 KB)
Screen Shot 2021-05-11 at 6.03.32 PM.png (1×2 px, 476 KB)
Screen Shot 2021-05-11 at 5.39.03 PM.png (1×1 px, 818 KB)
Screen Shot 2021-05-11 at 5.44.54 PM.png (1×2 px, 460 KB)

Thanks @Etonkovidova for the VE comparison, that's really helpful. LGTM