Jump to content

Specs/HTML/2.8.0/Extensions/Cite

From mediawiki.org


NOTE: In the rest of this spec below, when we say Cite implementation, we are referring to the implementation that targets Parsoid.

Non-breaking change rolled out with 1.43.0-wmf.8

[edit]
  • This minor change ought to be fully backward-compatible.
  • The references output now includes an additional reference-text class wherever there was a mw-reference-text class. This change has been made to ensure Parsoid's HTML remains compatible with all tools (gadgets, user scripts, etc.) targeting the current read-views (desktop / mobile) HTML output that uses the reference-text class.
  • Link to patch and announcement with more information.

Minor breaking change to roll out with 1.43.0-wmf.9

[edit]
  • Although this is technically a breaking change, we do not expect it to break any clients in practice.
  • For named refs with multiple backlinks, the backlinks span[rel="mw:referencedBy"] tag now has a mw-cite-backlink class added to it to match its presence in current read-views HTML. This is a non-breaking change.
  • For unnamed refs (or named refs with only one backlink), the backlinks section did not have a wrapping span tag and had a bare a[rel="mw:referencedBy"] tag. We are now adding a wrapping span tag around this a-tag and adding the mw-cite-backlink class to it. Since this changes the DOM structure, it could impact clients if they used a li > a[rel="mw:referencedBy"] selector instead of omitting the unncessary li > prefix.
  • Link to patch and announcement with more information.

Preliminaries

[edit]

An example with transcluded reference content,

<ref group='x' name='y'>{{Cite|foo|bar=baz}}</ref>

renders as follows. (Note the references section was autogenerated)

<p>
    <sup about="#mwt3" class="mw-ref" id="cite_ref-y_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-y-1"},"attrs":{"group":"x","name":"y"}}'>
        <a href="./Main_Page#cite_note-y-1" style="counter-reset: mw-Ref 1;" data-mw-group="x"><span class="mw-reflink-text">[x 1]</span></a>
    </sup>
</p>


<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt4" data-parsoid='{"group":"x","dsr":[52,52,0,0]}' data-mw='{"name":"references","attrs":{"group":"x"},"autoGenerated":true}'>
    <ol class="mw-references references" data-mw-group="x">
        <li about="#cite_note-y-1" id="cite_note-y-1">
            <span class="mw-cite-backlink"><a href="./Main_Page#cite_ref-y_1-0" data-mw-group="x" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a></span>
            <span id="mw-reference-text-cite_note-y-1" class="mw-reference-text reference-text"><cite class="citation" about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Cite","href":"./Template:Cite"},"params":{"1":{"wt":"foo"},"bar":{"wt":"baz"}},"i":0}}]}'>...</cite></span>
        <li>
    </ol>
</div>

Ref and References

[edit]
First one <ref>One</ref>
Second one <ref>Two <p>p1</p> <p>p2</p> </ref>
Named one <ref name='three'>Three</ref>
Reused <ref name='three' />
Reused again <ref name='three' />

<references />

The HTML output for this wikitext is shown below. Cite provides the element id of the HTML via the data-mw.body.id property rather than copying the HTML dom in the data-mw.body.html property. But, both formats are considered valid and Cite accepts both formats when serializing HTML to wikitext.

If data-mw.body.id is specified, it is the client's responsibility to make sure that the element id is present in the DOM. If both data-mw.body.html and data-mw.body.id are specified, Cite uses the html property and ignores the id property.

<p>
    First one
    <sup about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref"
            data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'>
        <a href="./Main_Page#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a>
    </sup>
    Second one
    <sup about="#mwt4" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref"
            data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{}}'>
        <a href="./Main_Page#cite_note-2" style="counter-reset: mw-Ref 2;"><span class="mw-reflink-text">[2]</span></a>
    </sup>
    Named one
    <sup about="#mwt6" class="mw-ref" id="cite_ref-three_3-0" rel="dc:references" typeof="mw:Extension/ref"
            data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-three-3"},"attrs":{"name":"three"}}'>
        <a href="./Main_Page#cite_note-three-3" style="counter-reset: mw-Ref 3;"><span class="mw-reflink-text">[3]</span></a>
    </sup>
    Reused
    <sup about="#mwt8" class="mw-ref" id="cite_ref-three_3-1" rel="dc:references" typeof="mw:Extension/ref"
            data-mw='{"name":"ref","attrs":{"name":"three"}}'>
        <a href="./Main_Page#cite_note-three-3" style="counter-reset: mw-Ref 3;"><span class="mw-reflink-text">[3]</span></a>
    </sup>
    Reused again
    <sup about="#mwt10" class="mw-ref" id="cite_ref-three_3-2" rel="dc:references" typeof="mw:Extension/ref"
            data-mw='{"name":"ref","attrs":{"name":"three"}}'>
        <a href="./Main_Page#cite_note-three-3" style="counter-reset: mw-Ref 3;"><span class="mw-reflink-text">[3]</span></a>
    </sup>
</p>

<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt12" data-mw='{"name":"references","attrs":{}}'>
    <ol class="mw-references references">
        <li about="#cite_note-1" id="cite_note-1">
            <span class="mw-cite-backlink"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a></span>
            <span id="mw-reference-text-cite_note-1" class="mw-reference-text reference-text">One</span>
        </li>
        <li about="#cite_note-2" id="cite_note-2">
            <span class="mw-cite-backlink"><a href="./Main_Page#cite_ref-2" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a></span>
            <span id="mw-reference-text-cite_note-2" class="mw-reference-text reference-text">Two <p data-parsoid='{"stx":"html"}'>p1</p> <p data-parsoid='{"stx":"html"}'>p2</p> </span>
        </li>
        <li about="#cite_note-three-3" id="cite_note-three-3">
            <span rel="mw:referencedBy" class="mw-cite-backlink">
                <a href="./Main_Page#cite_ref-three_3-0"><span class="mw-linkback-text">1 </span></a>
                <a href="./Main_Page#cite_ref-three_3-1"><span class="mw-linkback-text">2 </span></a>
                <a href="./Main_Page#cite_ref-three_3-2"><span class="mw-linkback-text">3 </span></a>
            </span>
            <span id="mw-reference-text-cite_note-three-3" class="mw-reference-text reference-text">Three</span>
        </li>
    </ol>
</div>

Auto-generated references blocks

[edit]

If the source wikitext had <ref> tags but no corresponding <references> tag to generate references, Cite auto-generates references blocks for every set of refs that need it. As of HTML version 1.2.1, for all such auto-generated reference block, the data-mw will have the autoGenerated property set to true.

Responsive wrappers

[edit]

In T159894, support was added for the cite extension's responsive parameter, which presents the references section as multiple columns based on the browser window size. This is achieved by wrapping the ordered list with a div. Of note, since this is part of the extension content, the transclusion annotations are placed on the wrapper.

Directionality

[edit]

A mw-cite-dir-XXX class is added to the reference list item based on the dir attribute specified on the reference definition. For example,

First one <ref dir="ltr">One</ref>

<references />

renders as,

<p>
    First one
    <sup about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref"
            data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{"dir":"ltr"}}'>
        <a href="./Main_Page#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a>
    </sup>
</p>

<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt12" data-mw='{"name":"references","attrs":{}}'>
    <ol class="mw-references references">
        <li about="#cite_note-1" id="cite_note-1" class="mw-cite-dir-ltr">
            <span class="mw-cite-backlink"<a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a></span>
            <span id="mw-reference-text-cite_note-1" class="mw-reference-text reference-text">One</span>
        </li>
    </ol>
</div>

Error representation

[edit]

Cite does not inline the i18n error text in the HTML. It instead annotates the erroneous <ref> with a mw:Error value in the typeof attribute and the i18n error key in the data-mw.errors property as shown in the following excerpt:

typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"name":"example"},"errors":[{"key":"cite_error_ref_no_text"}]}'

Clients like VisualEditor will need to recognize these new attributes and display the actual error message in the correct language with parameters such as the name expanded in the error message text.

As part of T51538 the full suite of error conditions provided by Core Cite extension are being added to Parsoid's Cite implementation. Parsoid's Cite implementation will use the same mechanism for annotating the other error types.

CSS based configuration

[edit]

The display of footnotes, etc. are configured via CSS. This differs from the design of the legacy extension. See the announcement and task. FIXME: Say more ...