Page MenuHomePhabricator

Show references with the same details as re-use in the legacy rendering (Merge Use Case)
Open, Needs TriagePublic

Description

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.

Mock

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

Notes

  • Main ref content can be repeated for named refs, and this is used extensively by templates such as {{sfn}}. Unfortunately, this can create a fragile situation in manually-entered wikitext, for example when a ref tag is copy-pasted. The fragility is caused by any small change to the ref body causing an error to be displayed, and only one copy of the content being rendered. Named refs with and without details can take advantage of this deduplication.
<ref name="abc">def</ref>
<ref name="abc">def</ref>
  • The only type of reuse that can be offered for details is more like "duplication and deduplication" like this, which could be rendered as a single subref with two backlinks:
<ref details="abc" name="def">ghi</ref>
<ref details="abc" name="def" />
  • It would be wise to do some more UX discovery before implementation. If subrefs appear to be reused, there may also be an expectation to deduplicate them and treat as reuses in the visual editor. We can also gauge how important it is to users to have subref reuse.
  • The mechanism to deduplicate subrefs will probably need to index details content by wikitext. It's unsafe to implement as a simple comparison loop, because this will slow down by N^2. Note that subrefs should only be compared within each top-level ref.

Out of scope

  • VE is out of scope
  • This is only for the legacy parser, for now.
  • Top-level refs should not have this behavior, in fact we'll probably be adding an error if two named, top-level refs both include content.

Event Timeline

Change #1119176 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/Cite@master] [WIP] Experiment with merging identical sub-references

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

WMDE-Fisch renamed this task from Merge references with details in the legacy rendering to Merge references with the same details in the legacy rendering.Feb 14 2025, 9:13 AM
WMDE-Fisch renamed this task from Merge references with the same details in the legacy rendering to Show references with the same details as re-use in the legacy rendering.

We may also introduce a new error when the main ref content is repeated in named refs, since this creates a fragile situation in wikitext. This would also apply to refs without details:

<ref name="abc">def</ref>
<ref name="abc">def</ref>

Introducing an error here would break literally every use of sfn, which under the hood emits identical content with identical names (because it cannot know what other template instances are doing).

awight renamed this task from Show references with the same details as re-use in the legacy rendering to Investigation: Show references with the same details as re-use in the legacy rendering.Feb 18 2025, 8:52 AM

We may also introduce a new error when the main ref content is repeated in named refs, since this creates a fragile situation in wikitext. This would also apply to refs without details:

<ref name="abc">def</ref>
<ref name="abc">def</ref>

Introducing an error here would break literally every use of sfn, which under the hood emits identical content with identical names (because it cannot know what other template instances are doing).

Thanks! Thiemo pointed this out as well, and I totally agree. This might have been something to consider carefully when Cite was first being developed, but at this point we need to just support existing usage. I'll edit the task description to reflect the point.

WMDE-Fisch renamed this task from Investigation: Show references with the same details as re-use in the legacy rendering to Show references with the same details as re-use in the legacy rendering.Mar 13 2025, 7:32 AM
Lina_Farid_WMDE renamed this task from Show references with the same details as re-use in the legacy rendering to Show references with the same details as re-use in the legacy rendering (Merge Use Case).Jul 10 2025, 9:34 AM

Can you create separate subtasks for VE and Parsoid support, so we can track work on those?

Change #1194181 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/Cite@master] [WIP] Start implementing sub-ref merging in legacy parser

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

Change #1119176 abandoned by Thiemo Kreuz (WMDE):

[mediawiki/extensions/Cite@master] [WIP] Experiment with merging identical sub-references

Reason:

Squashed into I9602447.

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

Change #1194929 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/Cite@master] Replace slow sub-ref body loop with lookup table

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

Change #1195643 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/Cite@master] Extract more code from large ReferenceStack::pushRef method

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

Change #1194181 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Start implementing sub-ref merging in legacy parser

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

Test wiki created on Patch demo by Thiemo Kreuz (WMDE) using patch(es) linked to this task:
https://11a6e896b4.catalyst.wmcloud.org/w/

Test wiki on Patch demo by Thiemo Kreuz (WMDE) using patch(es) linked to this task was deleted:

https://11a6e896b4.catalyst.wmcloud.org/w/

Change #1196265 had a related patch set uploaded (by Awight; author: Awight):

[operations/mediawiki-config@master] [beta] Enable subref merge

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

Change #1196265 merged by jenkins-bot:

[operations/mediawiki-config@master] [beta] Enable subref merge

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

Change #1194929 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Replace slow sub-ref body loop with lookup table

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

Change #1195643 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Extract more code from large ReferenceStack::pushRef method

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

Change #1196399 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/Cite@master] Move sub-ref merging in legacy parser out of dev-only branch

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

Change #1196399 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Move sub-ref merging in legacy parser out of dev-only branch

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