Remove Parsoid section wrappers before finding transclusions

The section wrappers can be marked as template-affected when the
previous or next section is transcluded, causing comments to be
unnecessarily uneditable. The new test case demonstrates this.

Depends-On: I03bc455d5484a6c51f3fa2397c64936b829fe7e3
Change-Id: I895a04990d79a3475d778b4fef054ea0bb076f0b
This commit is contained in:
Bartosz Dziewoński 2020-03-19 18:37:19 +01:00
parent bb2b2f2648
commit a14293c8e7
5 changed files with 48 additions and 0 deletions

View file

@ -151,6 +151,7 @@
"cases/en-big-parsoid/en-big-parsoid.json",
"cases/en-big-parsoid/en-big-parsoid-transcludedFrom.json",
"cases/en-bigafd-parsoid/en-bigafd-parsoid-transcludedFrom.json",
"cases/transclusions/transclusions-transcludedFrom.json",
"cases/pl-big-oldparser/pl-big-oldparser.json",
"cases/pl-big-parsoid/pl-big-parsoid.json",
"cases/no-heading/no-heading.json",
@ -166,6 +167,7 @@
"cases/en-big-parsoid/en-big-parsoid.html",
"cases/en-big-parsoid/en-big-parsoid-modified.html",
"cases/en-bigafd-parsoid/en-bigafd-parsoid.html",
"cases/transclusions/transclusions.html",
"cases/pl-big-oldparser/pl-big-oldparser.html",
"cases/pl-big-oldparser/pl-big-oldparser-modified.html",
"cases/pl-big-oldparser/pl-big-oldparser-reply.html",

View file

@ -335,6 +335,8 @@ function getParsoidCommentData( pageName, oldId, commentId ) {
data = response.visualeditor;
parsoidDoc = ve.parseXhtml( data.content );
// Remove section wrappers, they interfere with transclusion handling
mw.libs.ve.unwrapParsoidSections( parsoidDoc.body );
// Mirror VE's ve.init.mw.Target.prototype.fixBase behavior:
ve.fixBase( parsoidDoc, document, ve.resolveUrl(
// Don't replace $1 with the page name, because that'll break if

View file

@ -0,0 +1,12 @@
{
"Matma Rex|2020-03-04T20:11:00.000Z|0": false,
"Matma Rex|2020-03-04T20:12:00.000Z|0": false,
"Matma Rex|2020-03-04T20:13:00.000Z|0": false,
"Matma Rex|2020-03-04T20:21:00.000Z|0": "Talk:Transcluded subpage",
"Matma Rex|2020-03-04T20:22:00.000Z|0": "Talk:Transcluded subpage",
"Matma Rex|2020-03-04T20:23:00.000Z|0": "Talk:Transcluded subpage",
"Matma Rex|2020-03-04T20:30:00.000Z|0": true,
"Matma Rex|2020-03-04T20:31:00.000Z|0": true,
"Matma Rex|2020-03-04T20:32:00.000Z|0": true,
"Matma Rex|2020-03-04T20:33:00.000Z|0": true
}

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/wiki/Special:Redirect/revision/3769"><head prefix="mwr: http://localhost/wiki/Special:Redirect/"><meta charset="utf-8"/><meta property="mw:pageId" content="1420"/><meta property="mw:pageNamespace" content="1"/><link rel="dc:replaces" resource="mwr:revision/3766"/><meta property="mw:revisionSHA1" content="808db27c9c6bf5d60bb45231fc0744507bbdcf32"/><meta property="dc:modified" content="2020-03-19T18:00:08.000Z"/><meta property="mw:html:version" content="2.1.0"/><link rel="dc:isVersionOf" href="http://localhost/wiki/Talk%3ATranscluded"/><title>Talk:Transcluded</title><base href="http://localhost/wiki/"/><link rel="stylesheet" href="/w/load.php?modules=mediawiki.legacy.commonPrint%2Cshared%7Cmediawiki.skinning.content.parsoid%7Cmediawiki.skinning.interface%7Cskins.vector.styles%7Csite.styles%7Cext.cite.style%7Cext.cite.styles%7Cmediawiki.page.gallery.styles&amp;only=styles&amp;skin=vector"/><!--[if lt IE 9]><script src="/w/load.php?modules=html5shiv&amp;only=scripts&amp;skin=vector&amp;sync=1"></script><script>html5.addElements('figure-inline');</script><![endif]--><meta http-equiv="content-language" content="en"/><meta http-equiv="vary" content="Accept"/></head><body data-parsoid='{"dsr":[0,1065,0,0]}' lang="en" class="mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output" dir="ltr"><section data-mw-section-id="0" data-parsoid="{}"></section><section data-mw-section-id="1" about="#mwt6" typeof="mw:Transclusion" data-parsoid='{"pi":[[]],"dsr":[0,463,null,null]}' data-mw='{"parts":["== Not transcluded ==\nNormal comment. [[User:Matma Rex|Matma Rex]] ([[User talk:Matma Rex|&lt;font color=\"green\">&apos;&apos;talk&lt;/font>]]) 20:11, 4 March 2020 (UTC)\n: Normal comment 2. [[User:Matma Rex|Matma Rex]] ([[User talk:Matma Rex|&lt;font color=\"green\">&apos;&apos;talk&lt;/font>]]) 20:12, 4 March 2020 (UTC)\n: {{1x|Ping-like}} template. [[User:Matma Rex|Matma Rex]] ([[User talk:Matma Rex|&lt;font color=\"green\">&apos;&apos;talk&lt;/font>]]) 20:13, 4 March 2020 (UTC)\n\n",{"template":{"target":{"wt":"Talk:Transcluded subpage","href":"./Talk:Transcluded_subpage"},"params":{},"i":0}},"\n\n"]}'><h2 id="Not_transcluded" data-parsoid='{"dsr":[0,21,2,2]}'>Not transcluded</h2>
<p data-parsoid='{"dsr":[22,152,0,0]}'>Normal comment. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User:Matma_Rex"},"sa":{"href":"User:Matma Rex"},"dsr":[38,66,17,2]}'>Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User_talk:Matma_Rex"},"sa":{"href":"User talk:Matma Rex"},"dsr":[68,125,22,2]}'><font color="green" data-parsoid='{"stx":"html","dsr":[90,123,20,7]}'><i data-parsoid='{"autoInsertedEnd":true,"dsr":[110,116,2,0]}'>talk</i></font></a>) 20:11, 4 March 2020 (UTC)</p>
<dl data-parsoid='{"dsr":[153,431,0,0]}'><dd data-parsoid='{"dsr":[153,287,1,0]}'>Normal comment 2. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User:Matma_Rex"},"sa":{"href":"User:Matma Rex"},"dsr":[173,201,17,2]}'>Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User_talk:Matma_Rex"},"sa":{"href":"User talk:Matma Rex"},"dsr":[203,260,22,2]}'><font color="green" data-parsoid='{"stx":"html","dsr":[225,258,20,7]}'><i data-parsoid='{"autoInsertedEnd":true,"dsr":[245,251,2,0]}'>talk</i></font></a>) 20:12, 4 March 2020 (UTC)</dd>
<dd data-parsoid='{"dsr":[288,431,1,0]}'><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]],"dsr":[290,306,null,null]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Ping-like"}},"i":0}}]}'>Ping-like</span> template. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User:Matma_Rex"},"sa":{"href":"User:Matma Rex"},"dsr":[317,345,17,2]}'>Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User_talk:Matma_Rex"},"sa":{"href":"User talk:Matma Rex"},"dsr":[347,404,22,2]}'><font color="green" data-parsoid='{"stx":"html","dsr":[369,402,20,7]}'><i data-parsoid='{"autoInsertedEnd":true,"dsr":[389,395,2,0]}'>talk</i></font></a>) 20:13, 4 March 2020 (UTC)</dd></dl>
<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[]],"dsr":[433,461,null,null]}' data-mw='{"parts":[{"template":{"target":{"wt":"Talk:Transcluded subpage","href":"./Talk:Transcluded_subpage"},"params":{},"i":0}}]}'>
</span></section><section data-mw-section-id="-1" about="#mwt6" data-parsoid="{}"><h2 about="#mwt2" id="On_a_subpage" data-parsoid="{}">On a subpage</h2><span about="#mwt2" data-parsoid="{}">
</span><p about="#mwt2" data-parsoid="{}">Normal comment. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User:Matma_Rex"},"sa":{"href":"User:Matma Rex"}}'>Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User_talk:Matma_Rex"},"sa":{"href":"User talk:Matma Rex"}}'><font color="green" data-parsoid='{"stx":"html"}'><i data-parsoid='{"autoInsertedEnd":true}'>talk</i></font></a>) 20:21, 4 March 2020 (UTC)</p><span about="#mwt2" data-parsoid="{}">
</span><dl about="#mwt2" data-parsoid='{"dsr":[null,461,0,0]}'><dd data-parsoid="{}">Normal comment 2. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User:Matma_Rex"},"sa":{"href":"User:Matma Rex"}}'>Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User_talk:Matma_Rex"},"sa":{"href":"User talk:Matma Rex"}}'><font color="green" data-parsoid='{"stx":"html"}'><i data-parsoid='{"autoInsertedEnd":true}'>talk</i></font></a>) 20:22, 4 March 2020 (UTC)</dd>
<dd data-parsoid='{"dsr":[null,461,1,0]}'>Ping-like template. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User:Matma_Rex"},"sa":{"href":"User:Matma Rex"}}'>Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex" data-parsoid='{"stx":"piped","a":{"href":"./User_talk:Matma_Rex"},"sa":{"href":"User talk:Matma Rex"}}'><font color="green" data-parsoid='{"stx":"html"}'><i data-parsoid='{"autoInsertedEnd":true}'>talk</i></font></a>) 20:23, 4 March 2020 (UTC)</dd></dl>
</section><section data-mw-section-id="2" data-parsoid="{}"><h2 id="Archived" data-parsoid='{"dsr":[463,477,2,2]}'>Archived</h2>
<div class="boilerplate discussion-archived" style="background-color: #f5f3ef; overflow:auto; margin: 1em 0 0 0; padding: 0 10px 0 10px; border: 1px solid #aaa" about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"stx":"html","dsr":[478,1065,null,null],"pi":[[{"k":"1"}],[{"k":"1"}],[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"discussion top","href":"./Template:Discussion_top"},"params":{"1":{"wt":"Archived discussion. [[User:Matma Rex|Matma Rex]] ([[User talk:Matma Rex|&lt;font color=\"green\">&apos;&apos;talk&lt;/font>]]) 20:30, 4 March 2020 (UTC)"}},"i":0}},"\n\nNormal comment. [[User:Matma Rex|Matma Rex]] ([[User talk:Matma Rex|&lt;font color=\"green\">&apos;&apos;talk&lt;/font>]]) 20:31, 4 March 2020 (UTC)\n: Normal comment 2. [[User:Matma Rex|Matma Rex]] ([[User talk:Matma Rex|&lt;font color=\"green\">&apos;&apos;talk&lt;/font>]]) 20:32, 4 March 2020 (UTC)\n: ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Ping-like"}},"i":1}}," template. [[User:Matma Rex|Matma Rex]] ([[User talk:Matma Rex|&lt;font color=\"green\">&apos;&apos;talk&lt;/font>]]) 20:33, 4 March 2020 (UTC)\n",{"template":{"target":{"wt":"discussion bottom","href":"./Template:Discussion_bottom"},"params":{},"i":2}}]}'>
<dl><dd><i>The following discussion is closed. <span style="color:red"><b>Please do not modify it.</b></span> Subsequent comments should be made in a new section.</i> <i>A summary of the conclusions reached follows.</i>
<dl><dd>Archived discussion. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex">Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex"><font color="green"><i>talk</i></font></a>) 20:30, 4 March 2020 (UTC)</dd></dl></dd></dl>
<hr/>
<p>Normal comment. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex">Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex"><font color="green"><i>talk</i></font></a>) 20:31, 4 March 2020 (UTC)</p>
<dl><dd>Normal comment 2. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex">Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex"><font color="green"><i>talk</i></font></a>) 20:32, 4 March 2020 (UTC)</dd>
<dd>Ping-like template. <a rel="mw:WikiLink" href="./User:Matma_Rex" title="User:Matma Rex">Matma Rex</a> (<a rel="mw:WikiLink" href="./User_talk:Matma_Rex" title="User talk:Matma Rex"><font color="green"><i>talk</i></font></a>) 20:33, 4 March 2020 (UTC)</dd></dl>
<hr/>
<dl><dd><i>The above discussion is closed. <span style="color:red"><b>Please do not modify it.</b></span> Subsequent comments should be made in a new section.</i></dd></dl></div></section></body></html>

View file

@ -231,6 +231,13 @@ QUnit.test( '#getTranscludedFrom', function ( assert ) {
var i, j, cases, comments, transcludedFrom, fixture;
cases = [
{
name: 'transclusions',
dom: mw.template.get( 'test.DiscussionTools', 'cases/transclusions/transclusions.html' ).render(),
expected: require( './cases/transclusions/transclusions-transcludedFrom.json' ),
config: require( './data/enwiki-config.json' ),
data: require( './data/enwiki-data.json' )
},
{
name: 'enwiki parsoid',
dom: mw.template.get( 'test.DiscussionTools', 'cases/en-big-parsoid/en-big-parsoid.html' ).render(),
@ -251,6 +258,8 @@ QUnit.test( '#getTranscludedFrom', function ( assert ) {
for ( i = 0; i < cases.length; i++ ) {
$( fixture ).empty().append( cases[ i ].dom );
mw.libs.ve.unwrapParsoidSections( fixture );
testUtils.overrideMwConfig( cases[ i ].config );
testUtils.overrideParserData( cases[ i ].data );