Page MenuHomePhabricator

Nested refs fail inside references block
Open, MediumPublicBUG REPORT


By design, Cite does not allow a <ref> to appear within another <ref>. (This is probably a result of parser design and concerns over maintaining the integrity of Cite's internal data stack.)

However, clever Wikipedians realized that one can use #tag to avoid Cite's design limitations and create functional nested references such as:

AAA {{#tag:ref| BBB <ref> CCC </ref> }}

(See also: T18330)

Recently, Cite was expanded to allow reference content to be defined within a references block, i.e.

Foo <ref name="bar"/>

<ref name="bar">blah blah</ref>

While most references work fine in this context, the #tag based nested ref constructions universally fail when moved inside <references>. Depending on the number and order of #tag calls used and the depth of the stack the result will either be an uninformative error message or a misnumbered reference list.

The solution to this is probably to create an implementation that generically supports nested refs. (Part of the problem is that Cite was not intended to allow for nested refs at all and though the #tag based hack worked previously because of quirks in parser behavior, the same call structure doesn't work when moved inside the references block.)

The "right" way to do this is probably to restructure Cite's internal data stack and change the way the evaluation of references are hooked into the parser. I will probably implement this myself eventually, though probably not for some months.

Version: unspecified
Severity: major
See Also: T24635: Multiple problems with refs inside <references>...</references> blocks



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:54 PM
bzimport added a project: Cite.
bzimport set Reference to bz20707.
bzimport added a subscriber: Unknown Object (MLST).

Ruslik00 wrote:

An obvious solution to this problem is to use {{#tag:references|...}} construct.

(In reply to comment #1)

An obvious solution to this problem is to use {{#tag:references|...}}

Apparently one can define a nested ref inside a #tag:references as long as both the portions of the nest are also defined by #tag.

Based on an example by Ruslik_Zero:

AAAA<ref name="note1" group="note" />


{{#tag:ref|foo{{#tag:ref|inside ref}}bar|group="note"|name="note1"}}



<references />

Frankly, I'm surprised that even that works, but it will fail if any of those three #tag calls is replaced by a normal invocation. Hence I would say this is a rather fragile work around.

I suspect this is the same issue that causes problems with #tag:ref in list defined references. A single use works, but more than one results in Cite error: <ref> tag defined in <references> has no name attribute.


<ref group=Note name=a />
<ref group=Note name=b />
<ref group=Note name=c />



Nesting #tag:ref does not work either:


*** Bug 22300 has been marked as a duplicate of this bug. ***

athenurlauber wrote:

A reflist containing both a plain ref tag and a "#tag:" ref tag with a nested ref tag in it works if the ref-in-a-ref is listed before the plain ref, and doesn't work if the ref-in-a-ref is listed after the plain ref (demo here

This works:

text<ref name=n1 group=nested_first/>
text<ref name=n2 group=nested_first/>.

;Reflist, nested ref listed first:{{reflist|group=nested_first|refs=

{{#tag:ref|With nested reference<ref>content
of nested reference</ref>|name=n1|group=nested_first}}

<ref name=n2 group=nested_first>With no nested reference</ref>

;Nested refs:

This not:

text<ref name=n3 group=nested_second/>
text<ref name=n4 group=nested_second/>.

;Reflist, nested ref listed second:{{reflist|group=nested_second|refs=

<ref name=n3 group=nested_second>With no nested reference</ref>

{{#tag:ref|With nested reference<ref>content
of nested reference</ref>|name=n4|group=nested_second}}

;Nested refs:

Here is the working sample from above without templates.

Placing <ref name=n2> first throws a "Cite error references no text" and a "Cite error references no key".

Using #tag:ref more than once in the list throws the errors.

text<ref name=n1 group=nested_first/>
text<ref name=n2 group=nested_first/>.



{{#tag:ref|With nested reference<ref>content
of nested reference</ref>|name=n1}}

<ref name=n2>With no nested reference</ref>



<references />

I consider this the most egregious issue with cite.php. The inability to easily add a reference to an explanatory note using cite.php has caused the creation and retention of multiple templates for this purpose. In use, most of these templates create duplicate ids, thus rendering invalid HTML and bad in-page linking.

The simplest fix from the user standpoint would be to allow <ref> tags to nest, while allowing the #tag:ref hack to still work. Note that many uses of #tag:ref have multiple embedded <refs>s. If we have to add new syntax, then we can deal with it.

There is no expectation of multiple nesting, i.e. stuffing a #tag:ref inside a #tag:ref.

This has been fixed by 944b24542827f827cdfb8646f1c2e87aeb929b65 / The change will be deployed to all wikis on May 19/20, with MW 1.26wmf6, according to You can test the new behavior on already.

(I verified the examples given in T22707#258934 and T22707#258959.)

T100477 might be related to this fix (started happening around the same time)

Anomie added a subscriber: Anomie.

Reopening because the patch was reverted.

Aklapper edited subscribers, added: Jackmcbarn, Aklapper; removed: wikibugs-l-list.

This task has been assigned to the same task owner for more than two years. Resetting task assignee due to inactivity, to decrease task cookie-licking and to get a slightly more realistic overview of plans. Please feel free to assign this task to yourself again if you still realistically work or plan to work on this task - it would be welcome!

For tips how to manage individual work in Phabricator (noisy notifications, lists of task, etc.), see for available options.
(For the records, two emails were sent to assignee addresses before resetting assignees. See T228575 for more info and for potential feedback. Thanks!)

Aklapper changed the subtype of this task from "Task" to "Bug Report".Feb 6 2022, 7:18 PM