Page MenuHomePhabricator

The VisualEditor cannot add or remove list-defined references
Open, Needs TriagePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

Adding a reference:

Removing a reference:

Removing citations to a reference:

What happens?:

What should have happened instead?:

Adding a reference:

  • The reference should be added between the "references" tags to the other list-defined references.
  • Ideally this should also work with the "reflist" template, but I don't believe that the VisualEditor does much with references within templates.

Removing a reference:

  • There are several ways to handle this; I'm not sure what the preferred method would be. The VisualEditor should offer some way to remove a list-defined reference. As of right now, an editor using the VisualEditor will cause an error when removing all citations to a list-defined reference, and they will have no way to resolve this from within the visual editor.

Software version (skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Fixing the removal of references would be really useful. Maybe this could be fixed in priority, potentially in a subtask?

For the addition, it could potentially be a big deal, but unlike for the removal it's more about readability than bug fix. It would mean that if there is a list-defined references list, the VisualEditor would put the reference there rather than inside the body of the article. Both placements are valid, but putting references inside the list-defined references list instead of the body may arguably cause less clutter and improve readability in the source code editor. I guess that would be an improvement, but it is a particularly impactful design change, so it probably needs an RfC on Wikipedia to determine if there is consensus in favor of that.

I definitely agree that us leaving it in the <references> after all uses on the page have been removed seems like bad form, given that it results in this:

CleanShot 2025-09-05 at 16.27.06@2x.png (656×2 px, 312 KB)

The other question of what to do when you remove a reference from within the reference list is more complicated, because both of these seem potentially valid:

  1. Remove the ref from references, and remove all uses of it from the page
  2. Remove the ref from references, and leave all uses of it in place, which will promote the first usage on the page into the full <ref>foo</foo> form when you save

The latter is consistent with other times when you delete a reused reference in VE... but it might make sense to treat deleting from the list differently? Or to offer an explicit "remove all uses of this reference" button?

For the addition, it could potentially be a big deal, but unlike for the removal it's more about readability than bug fix.

I do not understand. Readability of what? The wikicode?

It would mean that if there is a list-defined references list, the VisualEditor would put the reference there rather than inside the body of the article.

Yes, that is (part of) the definition of this bug in the OP, iiuc.

Both placements are valid, but ...

If placement in the LDR is the uniform choice in a given article, then other citations should also be there. Placing them in the body of the article is syntactically valid, but contrary to the WP:CITEVAR guideline.

...putting references inside the list-defined references list instead of the body may arguably cause less clutter and improve readability in the source code editor. I guess that would be an improvement, but....

All of that is O/T here. This bug has nothing to do with debating a preference about what seems like less clutter, and whether or not that is a good objective or not. You can take that up at Wikipedia.

...but it is a particularly impactful design change, so...

So? That may affect business decisions on timing and allocation of resources, but that is not our call.

...so it probably needs an RfC on Wikipedia to determine if there is consensus in favor of that.

Consensus in favor of what? Giving VE users the ability to manipulate LDRs the way wikicode users can? Are you saying, that functionality-wise, you believe that some VE users would *not* like to have the ability to add or delete LDR refs, and so we should ask them first via an Rfc before proceeding?

I see this as a bug, pure and simple: the wikicode editor has needed functionality (add and delete LDRs) that VE does not, which makes this a bug which should be fixed, therefore Phabricator is the proper venue to raise it. If you see this not as a bug, but rather as a choice to be presented to Wikipedia editors via Rfc, that would mean suspension of this task, and opening an Rfc instead. But I suspect I must have misinterpreted, so can you please elaborate on what you meant by an Rfc? For example, what would be the Rfc question, "Should VE users have the ability to add and delete LDR citations in place?" ? This seems like a slam-dunk bug to me, but if you see it differently, please refer to WP:RFCBEFORE before starting one.

Change #1185227 had a related patch set uploaded (by DLynch; author: DLynch):

[mediawiki/extensions/Cite@master] Remove refs from reference lists if there are no references left to them

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

The issue with the removal is clearly a bug (thanks @DLynch for the quick patch).

But for the addition, as pointed out by DLynch, both leaving the reference in the body or putting it as a LDR are valid. It's more about what people prefer, and people using the source code editor are most impacted. The VE could be modified so that it formats references as LDRs whenever there are already LDRs in the article. The purpose of LDRs is readability within the source editor, although it's hard to tell whether most users consider it more readable or less readable, that's why I was suggesting seeking consensus before making any change to the VE's default behavior. What the VE does by default can largely affect how widely used LDRs are. By the way, I would be rather opposed to having a button for VE users to manage LDRs, as most VE users may not even know what LDRs are, and shouldn't have to care, since it only affects readability within the source editor.

We'd need to be careful changing how VE approached that, because we probably don't want editing an article in VE to suddenly cause what looks like a massive dirty-diff as every reference is edited to move it into compliance in whatever direction we choose.

Change #1185227 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Remove refs from reference lists if there are no references left to them

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

"VisualEditor will no longer leave an orphaned list-defined <ref> inside the <references> if an editor removes all its reuses."

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

[mediawiki/extensions/Cite@master] Revert "Remove refs from reference lists if there are no references left to them"

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

Change #1185227 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Remove refs from reference lists if there are no references left to them

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

This apparently leads to unintended removal of list-defined references if all re-uses are within templates (e.g. infoboxes). See https://de.wikipedia.org/w/index.php?diff=259660776 which I could reproduce with minimal wikitext: https://test.wikipedia.org/w/index.php?diff=673857

Change #1187665 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Revert "Remove refs from reference lists if there are no references left to them"

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

We're reverting for now—there's currently no obvious way to get VE to recognize ref usages wrapped inside of a template, and the original patch is causing data loss in this case.

VE should have a Converter test covering this, but I'm not sure how to include template fixtures like {{1x}}.

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

[mediawiki/extensions/Cite@wmf/1.45.0-wmf.18] Revert "Remove refs from reference lists if there are no references left to them"

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

Change #1187741 merged by jenkins-bot:

[mediawiki/extensions/Cite@wmf/1.45.0-wmf.18] Revert "Remove refs from reference lists if there are no references left to them"

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

Mentioned in SAL (#wikimedia-operations) [2025-09-12T09:02:07Z] <awight@deploy1003> Started scap sync-world: Backport for [[gerrit:1187741|Revert "Remove refs from reference lists if there are no references left to them" (T356471)]]

Mentioned in SAL (#wikimedia-operations) [2025-09-12T09:08:23Z] <awight@deploy1003> awight: Backport for [[gerrit:1187741|Revert "Remove refs from reference lists if there are no references left to them" (T356471)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2025-09-12T09:15:21Z] <awight@deploy1003> Finished scap sync-world: Backport for [[gerrit:1187741|Revert "Remove refs from reference lists if there are no references left to them" (T356471)]] (duration: 13m 14s)

Change #1187849 had a related patch set uploaded (by DLynch; author: DLynch):

[mediawiki/extensions/Cite@master] Reapply "Remove refs from reference lists if there are no references left to them"

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