Page MenuHomePhabricator

Show references with the same details as re-use in the Parsoid rendering (Merge Use Case)
Closed, ResolvedPublic

Description

Similar to T385666: Show references with the same details as re-use in the legacy rendering (Merge Use Case), specifically the small change in ReferenceStack.php.

User story:

As reader I want to see sub-references with the same main content and the same additional details content as re-uses of one sub-reference.

Acceptance criteria:

  • We want to merge sub-reference by comparing their Wikitext content similar to how it is done when two refs with the same name are "merged" if the content is identical
  • Duplicates should be merged in the reference list, and get the same number (e.g. [1.1]) in their corresponding footnote markers.
  • Since, we are aiming to roll this out without Parsoid, before we deploy we will need to discuss with Content Transform Team a solution to tweak tooling to ignore the visual diffs.
  • Mobile app rendering should be reasonable and ref previews must still work.

Parsoid -> VE data migration

Change to the document rendered by Parsoid

Wikitext (example page):

<ref name="main">Book</ref>
<ref name="main" details="page 1" />
<ref name="main" details="page 1" />

Current Parsoid rendering:

<sup class="mw-ref reference" id="cite_ref-main_1-0" typeof="mw:Extension/ref"
	data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;main&quot;},&quot;body&quot;:{&quot;id&quot;:&quot;mw-reference-text-cite_note-main-1&quot;}}">
	<a href="#cite_note-main-1">
		<span class="mw-reflink-text">[1]</span>
	</a>
</sup>
<sup class="mw-ref reference" id="cite_ref-2" typeof="mw:Extension/ref"
	data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;main&quot;,&quot;details&quot;:&quot;page 1&quot;},&quot;mainRef&quot;:&quot;main&quot;,&quot;body&quot;:{&quot;id&quot;:&quot;mw-reference-text-cite_note-2&quot;}}">
	<a href="#cite_note-2">
		<span class="mw-reflink-text">[1.1]</span></a></sup>
<sup class="mw-ref reference" id="cite_ref-3" typeof="mw:Extension/ref"
	data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;main&quot;,&quot;details&quot;:&quot;page 1&quot;},&quot;mainRef&quot;:&quot;main&quot;,&quot;body&quot;:{&quot;id&quot;:&quot;mw-reference-text-cite_note-3&quot;}}">
	<a href="#cite_note-3">
		<span class="mw-reflink-text">[1.2]</span>
	</a>
</sup>

<div class="mw-references-wrap" typeof="mw:Extension/references"
	data-mw="{&quot;name&quot;:&quot;references&quot;,&quot;attrs&quot;:{},&quot;autoGenerated&quot;:true,&quot;body&quot;:{&quot;html&quot;:&quot;\n&lt;sup typeof=\&quot;mw:Extension/ref\&quot; data-parsoid=\&quot;{}\&quot; data-mw='{\&quot;name\&quot;:\&quot;ref\&quot;,\&quot;attrs\&quot;:{\&quot;name\&quot;:\&quot;main\&quot;,\&quot;group\&quot;:\&quot;\&quot;},\&quot;body\&quot;:{\&quot;id\&quot;:\&quot;mw-reference-text-cite_note-main-1\&quot;},\&quot;isSyntheticMainRef\&quot;:1}'&gt;Book&lt;/sup&gt;&quot;}}">
	<ol class="mw-references references">
		<li id="cite_note-main-1" data-mw-footnote-number="1">
			<span class="mw-cite-backlink">...</span>
			<span id="mw-reference-text-cite_note-main-1"
				class="mw-reference-text reference-text">Book</span>
			<ol class="mw-subreference-list">
				<li id="cite_note-2" data-mw-footnote-number="1.1">
					<span class="mw-cite-backlink">...</span>
					<span id="mw-reference-text-cite_note-2"
						class="mw-reference-text reference-text">page 1</span>
				</li>
				<li id="cite_note-3" data-mw-footnote-number="1.2">
					<span class="mw-cite-backlink">...</span>
					<span id="mw-reference-text-cite_note-3"
						class="mw-reference-text reference-text">page 1</span>
				</li>
			</ol></li>
	</ol>
</div>

New Parsoid rendering (assumption):

<sup class="mw-ref reference" id="cite_ref-main_1-0" typeof="mw:Extension/ref"
	data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;main&quot;},&quot;body&quot;:{&quot;id&quot;:&quot;mw-reference-text-cite_note-main-1&quot;}}">
	<a href="#cite_note-main-1">
		<span class="mw-reflink-text">[1]</span>
	</a>
</sup>
<sup class="mw-ref reference" id="cite_ref-2" typeof="mw:Extension/ref"
	data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;main&quot;,&quot;details&quot;:&quot;page 1&quot;},&quot;mainRef&quot;:&quot;main&quot;,&quot;body&quot;:{&quot;id&quot;:&quot;mw-reference-text-cite_note-2&quot;}}">
	<a href="#cite_note-2">
		<span class="mw-reflink-text">[1.1]</span></a></sup>
<sup class="mw-ref reference" id="cite_ref-3" typeof="mw:Extension/ref"
	data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;main&quot;,&quot;details&quot;:&quot;page 1&quot;},&quot;mainRef&quot;:&quot;main&quot;,&quot;body&quot;:{&quot;id&quot;:&quot;mw-reference-text-cite_note-2&quot;}}">
	<a href="#cite_note-2">
		<span class="mw-reflink-text">[1.1]</span>
	</a>
</sup>

<div class="mw-references-wrap" typeof="mw:Extension/references"
	data-mw="{&quot;name&quot;:&quot;references&quot;,&quot;attrs&quot;:{},&quot;autoGenerated&quot;:true,&quot;body&quot;:{&quot;html&quot;:&quot;\n&lt;sup typeof=\&quot;mw:Extension/ref\&quot; data-parsoid=\&quot;{}\&quot; data-mw='{\&quot;name\&quot;:\&quot;ref\&quot;,\&quot;attrs\&quot;:{\&quot;name\&quot;:\&quot;main\&quot;,\&quot;group\&quot;:\&quot;\&quot;},\&quot;body\&quot;:{\&quot;id\&quot;:\&quot;mw-reference-text-cite_note-main-1\&quot;},\&quot;isSyntheticMainRef\&quot;:1}'&gt;Book&lt;/sup&gt;&quot;}}">
	<ol class="mw-references references">
		<li id="cite_note-main-1" data-mw-footnote-number="1">
			<span class="mw-cite-backlink">...</span>
			<span id="mw-reference-text-cite_note-main-1"
				class="mw-reference-text reference-text">Book</span>
			<ol class="mw-subreference-list">
				<li id="cite_note-2" data-mw-footnote-number="1.1">
					<span class="mw-cite-backlink">...</span>
					<span id="mw-reference-text-cite_note-2"
						class="mw-reference-text reference-text">page 1</span>
				</li>
			</ol></li>
	</ol>
</div>

Impact on VE

To investigate. We should probably create a lookup for each main ref, which lists its subrefs by reference list item ID. When two subrefs have the same refListItemId, they should share the same InternalList listIndex.

Attributes should be the same for deduplicated refs, and different for undeduplicated refs. If VE is not deduplicating, none of these attributes can overlap between subrefs, in other words we should never have a mix of same and different attributes.

  • listKey
  • listIndex
  • data-mw.body.id
  • mainBody

Mock

Sub-referencing_reuse_visual.png (703×1 px, 110 KB)

Next steps

  • Discuss if this can be done independently of according VE changes

Yes, Parsoid and VE changes are independent of each other. Tested with 1202996: Parsoid: Render sub-refs sharing the same details as reuse | https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Cite/+/1202996 . The patch also works on master ( apart from the Converter tests that depend on the stacked VE change )

  • If applicable use an internal feature switch

Implementation notes

  • Cite Parsoid integration extractRefFromNode is the function which decorates the ref node with metadata during wt2dom rendering.
  • This function should compare each new subref against already-known subrefs of the same main node, to find any with identical wikitext.
  • When identical wikitext is found, the reflist body->id and should be reused. *Maybe* this can be done using a mechanism similar to named ref reuse, which adopts the entire $ref from the previous matching ref:
$ref = $refGroup->lookupRefByName( $refName );

Currently, there is an unconditional addRef for each subref,

$ref = $referencesData->addRef( $refGroup, $refName, $refDir, $details );

We want to write a new code path which finds the old subref and assigns it to $ref.

Note:

  • We also need to change the converter code in VE to work with the merged sub-refs. Currently it's assuming that sub-refs always get a different listKey. We need to change that to make sure that sub-refs sharing the same reflistItemId also get the same listKey so they are recognized by VE as reuse.

Event Timeline

awight updated the task description. (Show Details)
awight updated the task description. (Show Details)

Change #1202996 had a related patch set uploaded (by Svantje Lilienthal; author: Svantje Lilienthal):

[mediawiki/extensions/Cite@master] [WIP] Subref merge

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

Change #1206825 had a related patch set uploaded (by WMDE-Fisch; author: WMDE-Fisch):

[mediawiki/extensions/Cite@master] VE: Add code to consider sub-ref reuses

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

Change #1207142 had a related patch set uploaded (by WMDE-Fisch; author: WMDE-Fisch):

[mediawiki/extensions/Cite@master] VE: Cleanup some code in MWReferenceNode.static.toDataElement

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

Change #1207142 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] VE: Cleanup some code in MWReferenceNode.static.toDataElement

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

Change #1207823 had a related patch set uploaded (by WMDE-Fisch; author: WMDE-Fisch):

[mediawiki/extensions/Cite@master] VE: Extend getSubRefs test to include reuses

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

Change #1207823 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] VE: Extend getSubRefs test to include reuses

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

Change #1206825 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] VE: Add code to consider sub-ref reuses

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

Change #1210632 had a related patch set uploaded (by WMDE-Fisch; author: WMDE-Fisch):

[mediawiki/extensions/Cite@master] VE: Add Converter test including sub-ref reuse

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

Change #1210632 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] VE: Add Converter test including sub-ref reuse

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

Change #1211149 had a related patch set uploaded (by WMDE-Fisch; author: Svantje Lilienthal):

[mediawiki/extensions/Cite@master] VE: Merge identical sub-refs based in reflistItemId

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

Change #1202996 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Parsoid: Render sub-refs sharing the same details as reuse

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

Display in iOS app still shows duplicate sub-refs

Search for Hohl.png (1×750 px, 103 KB)

Display in iOS app still shows duplicate sub-refs

It's defenitly caching. New articles show merged sub-refs.