Page MenuHomePhabricator

Can't reuse an extended reference by name before it is defined
Open, Needs TriagePublicBUG REPORT

Description

Trying to reuse an extended ref before it is defined currently triggers a chain of 2 or more error messages. First "name … defined multiple times with different content", then "no text was provided for refs named …" as a subsequent error, and possible more that get triggered from all that. Minimal code that demonstrates the issue:

<ref name=p20 />
<ref extends=book name=p20>p. 20</ref>

<references>
<ref name=book>All information about the book</ref>
</references>

The problem disappears when …

  • When we move the re-used <ref name=p20 /> down below the original ref, everything works.
  • When we change the re-use on top to <ref extends=book name=p20 /> with a technically redundant extends= attribute, it also works.

Expected behavior:

  • Re-use needs to be possible no matter what the order is. The same is possible with normal ref w/o extends.
  • Re-using an extended ref should be possible just with the name, without repeating the extends= attribute.
  • Old and new parser need to behave the same (long-term goal, possibly not part of this ticket).

Dev notes:

  • The root cause is effectively the rollback stack not supporting rollbacks across multiple dimensions. I.e. it's not only the content that is missing, but the parser has no idea that the ref is going to be an extended one, with very different footnote numbering. See T242141 where we already dug into this edge case. A rollback would need to roll back the already rendered footnote number as well (which was already send to the ParserOutput at this point) – or we need to change the entire approach to assign these numbers only once at the very end.
  • In T242141 we decided to (possibly temporarily) block this use-case with an error message, but intentionally re-used an existing error message. The least we need to do is to add a new, much more helpful error message.
  • Test cases are already in place. Search for "T240424" in the code.
  • This also affects VE, which can be split into a separate task. If a subref reuse occurs first, several bits of logic go wrong because they depend on firstNode having the correct attributes. As an extreme corner case, a reuse of a subref defined before the subref will look like a top-level ref when checking for orphans, and will then fail to detect the orphaning when a subref illegally extends the non-defined subref.

Event Timeline

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

[mediawiki/extensions/Cite@master] [POC] Delay rendering of footnote marker numbers via StripState

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

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

[mediawiki/extensions/Cite@master] Additional parser test cases for delayed extends usage

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

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

[mediawiki/extensions/Cite@master] Split FootnoteMarkFormatter code into logical pieces

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

Change #1048036 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Additional parser test cases for delayed extends usage

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

Change #1048546 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Split FootnoteMarkFormatter code into logical pieces

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

This issue was also reported on dewiki: The person who reported this would like to be able to define not only main references, but also sub-references in the references section. This currently leads to an error, which you can see here: https://de.wikipedia.beta.wmflabs.org/wiki/Explosion_des_Oppauer_Stickstoffwerkes#cite_note-FFI2016_16-6