Nested refs fail inside references block
Closed, ResolvedPublic

Description

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: Bug 16330)

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

Foo <ref name="bar"/>

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

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:
https://bugzilla.wikimedia.org/show_bug.cgi?id=22635

bzimport added a project: Cite.Via ConduitNov 21 2014, 10:54 PM
bzimport added a subscriber: wikibugs-l.
bzimport set Reference to bz20707.
Dragons_flight created this task.Via LegacySep 18 2009, 1:41 AM
bzimport added a comment.Via ConduitSep 20 2009, 6:18 PM

Ruslik00 wrote:

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

Dragons_flight added a comment.Via ConduitSep 20 2009, 7:16 PM

(In reply to comment #1)

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

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" />

notes

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

group="note"}}

references

<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.

Gadget850 added a comment.Via ConduitMay 11 2010, 2:27 PM

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.

Example:

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

;Notes
{{reflist|group=Note|refs=
{{#tag:ref|Note1<ref>ref1</ref>|name=a|group=Note}}
{{#tag:ref|Note2<ref>ref2</ref>|name=b|group=Note}}
{{#tag:ref|Note3<ref>ref3</ref>|name=c|group=Note}}
}}

;References
{{reflist}}

Nesting #tag:ref does not work either:

{{#tag:ref|Note1{{#tag:ref|ref1}}|name=a|group=Note}}

Platonides added a comment.Via ConduitMay 22 2010, 3:07 PM

Also see bug 22635

Platonides added a comment.Via ConduitMay 22 2010, 3:08 PM

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

bzimport added a comment.Via ConduitAug 13 2010, 12:48 PM

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 http://en.wikipedia.org/wiki/User:Dan_Pelleg/Sandbox/Nested_refs):

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:
{{reflist}}

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:
{{reflist}}

Gadget850 added a comment.Via ConduitOct 6 2011, 1:24 PM

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/>.

'''Notes'''

{{#tag:references|

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

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

group=nested_first}}

'''References'''

<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.

mxn added a subscriber: mxn.Via WebNov 24 2014, 8:55 PM
matmarex assigned this task to Jackmcbarn.Via WebTue, May 19, 3:49 PM

This has been fixed by 944b24542827f827cdfb8646f1c2e87aeb929b65 / https://gerrit.wikimedia.org/r/#/c/181112/. The change will be deployed to all wikis on May 19/20, with MW 1.26wmf6, according to https://www.mediawiki.org/wiki/MediaWiki_1.26/Roadmap. You can test the new behavior on http://en.wikipedia.beta.wmflabs.org/ already.

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

matmarex closed this task as "Resolved".Via WebTue, May 19, 3:49 PM
czar added a subscriber: czar.Via WebWed, May 27, 11:37 PM

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

Add Comment