Page MenuHomePhabricator

DOMDiff'ing doesn't traverse into galleries
Closed, ResolvedPublic

Description

Here's a simple manual test that fails,

!! test
Selser is broken on native galleries
!! options
parsoid= {
  "modes": ["selser"],
  "changes": [
    ["div.gallerytext", "contents", "text", "456"]
  ]
}
!! wikitext
<gallery>
File:Foobar.jpg|123
</gallery>
!! wikitext/edited
<gallery>
File:Foobar.jpg|456
</gallery>
!! end

where the changes get applied,

INPUT:
<body data-parsoid='{"dsr":[0,40,0,0]}' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr"><ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt3" data-parsoid='{"dsr":[0,40,9,10]}' data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><figure-inline typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></figure-inline></div><div class="gallerytext">456</div></li>
</ul></body>

but disappear in the output.

Refs has special support in DOMDiff for HTML editing them,
https://github.com/wikimedia/parsoid/blob/master/lib/html2wt/DOMDiff.js#L115-L148

but the gallery extension is treated like any other extension and isn't recursed into,
https://github.com/wikimedia/parsoid/blob/master/lib/html2wt/DOMDiff.js#L359-L368

Things worked in production because we previously asked VE to drop the "extsrc" and "caption" from data-mw when editing the HTML,
https://www.mediawiki.org/w/index.php?title=Specs/HTML/2.0.0/Extensions/Gallery&type=revision&diff=3065335&oldid=3065332&diffmode=source

which was enough for the DOMDiff algorithm to indicate that the node should be serialized from the HTML,
https://github.com/wikimedia/parsoid/blob/master/lib/html2wt/DOMDiff.js#L82

Recently, Parsoid stopped emitting the "extsrc",
https://github.com/wikimedia/parsoid/commit/e748b8ec831bf6c86487ca8e551274d62be16b1d .

Reverted in https://gerrit.wikimedia.org/r/c/mediawiki/services/parsoid/+/486395

so you'd think editing would be impossible since there's no longer wrapper change, however, VE's output differs slightly for the input, enough so that selser is never applied to galleries,

In,

<body id="mwAA" lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr"><ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt3" data-mw="{&quot;name&quot;:&quot;gallery&quot;,&quot;attrs&quot;:{},&quot;body&quot;:{}}" id="mwAg">
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><figure-inline typeof="mw:Image"><a href="./File:Test.jpg"><img resource="./File:Test.jpg" src="//upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Name.jpg/120px-Name.jpg" data-file-width="350" data-file-height="210" data-file-type="bitmap" height="72" width="120" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Name.jpg/240px-Name.jpg 2x, //upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Name.jpg/180px-Name.jpg 1.5x"></a></figure-inline></div><div class="gallerytext">123</div></li>
</ul>

<p id="mwAw">456</p></body>

Out,

<body id="mwAA" lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr"><ul class="gallery" typeof="mw:Extension/gallery" data-mw="{&quot;name&quot;:&quot;gallery&quot;,&quot;attrs&quot;:{},&quot;body&quot;:{}}" about="#mwt3" id="mwAg"><li class="gallerybox"><div><div class="thumb"><div><a><img resource="File:Test.jpg" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Name.jpg/200px-Name.jpg"></a></div></div></div><div class="gallerytext">1234</div></li></ul>

<p id="mwAw">456</p></body>

The class list changed. A separate bug is filed for that in T214649.

Event Timeline

Change 486395 had a related patch set uploaded (by Arlolra; owner: Arlolra):
[mediawiki/services/parsoid@master] Revert "Get rid of nativeGallery option and enable it by default"

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

Change 486395 merged by jenkins-bot:
[mediawiki/services/parsoid@master] Revert "Get rid of nativeGallery option and enable it by default"

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

ssastry triaged this task as Medium priority.Apr 22 2019, 1:26 PM
ssastry edited projects, added Parsoid-Edit-Support; removed Parsoid.

Change 735081 had a related patch set uploaded (by Arlolra; author: Arlolra):

[mediawiki/services/parsoid@master] [WIP] DOM diff galleries

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

Change 735081 merged by jenkins-bot:

[mediawiki/services/parsoid@master] DOM diff galleries

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

Change 738988 had a related patch set uploaded (by Sbailey; author: Sbailey):

[mediawiki/vendor@master] Bump Parsoid to 0.15.0-a10

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

Change 738988 merged by jenkins-bot:

[mediawiki/vendor@master] Bump Parsoid to 0.15.0-a10

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