Show warning when dir="…" don't match

This classifies as a "warning" because we still show everything,
just with an error message appended.

Disabling the Parsoid tests right away hopefully makes it easier to
do the same change in Parsoid.

Bug: T202593
Depends-On: If14acd1070617ca8c4d15be6b1759bd47ead4926
Change-Id: I294b59f989f553932b40d08308906dd72d92d2cd
This commit is contained in:
thiemowmde 2023-12-14 09:13:14 +01:00
parent e64d944194
commit b181614ba1
4 changed files with 57 additions and 2 deletions

View file

@ -18,6 +18,7 @@
"cite-desc": "Adds <code>&lt;ref&gt;</code> and <code>&lt;references&gt;</code> tags for citations",
"cite_error": "Cite error: $1",
"cite_error_ref_invalid_dir": "Invalid <code>dir=\"$1\"</code>, must be <code>ltr</code> or <code>rtl</code>",
"cite_error_ref_conflicting_dir": "One of the <code>&lt;ref&gt;</code> tags with the name \"$1\" does have a conflicting dir attribute.",
"cite_error_ref_numeric_key": "Invalid <code>&lt;ref&gt;</code> tag; name cannot be a simple integer. Use a descriptive title",
"cite_error_ref_no_key": "The opening <code>&lt;ref&gt;</code> tag is malformed or has a bad name",
"cite_error_ref_too_many_keys": "Invalid parameter in <code>&lt;ref&gt;</code> tag",

View file

@ -22,6 +22,7 @@
"cite-desc": "{{desc|name=Cite|url=https://www.mediawiki.org/wiki/Extension:Cite}}",
"cite_error": "Used when there are errors in ref or references tags.\n\nParameters:\n* $1 - an error message",
"cite_error_ref_invalid_dir": "Error message shown when ref tag contain dir attribute with invalid value.\n\nParameters:\n* $1 - invalid dir value",
"cite_error_ref_conflicting_dir": "Error message shown when ref tags with the same name contain conflicting dir attributes.\n\nParameters:\n* $1 - name of the reference",
"cite_error_ref_numeric_key": "Error message shown if the name of a ref tag only contains digits. Examples that cause this error are <code>&lt;ref name=\"123\"/&gt;</code> or <code>&lt;ref name=\"456\">input</ref&gt;</code>",
"cite_error_ref_no_key": "Error message shown when ref tags without any content (that is <code>&lt;ref/&gt;</code>) are used without a name.",
"cite_error_ref_too_many_keys": "Generic error message shown when unknown, unsupported parameters are used in a <code>&lt;ref&gt;</code> tag. This can happen when there is a mistake in a parameter name, or a parameter exclusive to the <code>&lt;references&gt;</code> tag is used in a <code>&lt;ref&gt;</code> tag. This and [[MediaWiki:Cite error references invalid parameters]] form a pair and should be worded similarly.",

View file

@ -152,6 +152,11 @@ class ReferenceStack {
$ref['count']++;
// Rollback the global counter since we won't create a new ref.
$this->refSequence--;
if ( $ref['dir'] && $dir && $ref['dir'] !== $dir ) {
$ref['warnings'][] = [ 'cite_error_ref_conflicting_dir', $name ];
}
if ( $ref['text'] === null && $text !== null ) {
// If no text was set before, use this text
$ref['text'] = $text;

View file

@ -1275,7 +1275,7 @@ Multiple definition (mixed outside/inside)
!! end
!! test
T202593: Conflicting dir attributes are currently not reported as an error
T202593: Conflicting dir attributes
!! wikitext
<ref name="a" dir="ltr" />
<ref name="a" dir="rtl">abc</ref>
@ -1285,11 +1285,59 @@ T202593: Conflicting dir attributes are currently not reported as an error
<sup id="cite_ref-a_1-1" class="reference"><a href="#cite_note-a-1">&#91;1&#93;</a></sup>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-a-1" class="mw-cite-dir-rtl"><span class="mw-cite-backlink">↑ <sup><a href="#cite_ref-a_1-0">1.0</a></sup> <sup><a href="#cite_ref-a_1-1">1.1</a></sup></span> <span class="reference-text">abc <span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: One of the <code>&lt;ref&gt;</code> tags with the name "a" does have a conflicting dir attribute.</span></span>
</li>
</ol></div>
!! html/parsoid+disabled
<p><sup class="mw-ref reference" id="cite_ref-a_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a","dir":"ltr"}}'><a href="./Parser_test#cite_note-a-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup>
<sup class="mw-ref reference" id="cite_ref-a_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a","dir":"rtl"},"body":{"id":"mw-reference-text-cite_note-a-1"}}'><a href="./Parser_test#cite_note-a-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" data-mw='{"name":"references","attrs":{}}'>
<ol class="mw-references references">
<li id="cite_note-a-1" class="mw-cite-dir-rtl"><span rel="mw:referencedBy"><a href="./Parser_test#cite_ref-a_1-0"><span class="mw-linkback-text">1 </span></a><a href="./Parser_test#cite_ref-a_1-1"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-a-1" class="mw-reference-text">abc</span></li>
</ol>
</div>
!! end
!! test
T202593: Conflicting dir attributes with the full ref first
!! wikitext
<ref name="a" dir="ltr">abc</ref>
<ref name="a" dir="rtl" />
<references />
!! html/php
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">&#91;1&#93;</a></sup>
<sup id="cite_ref-a_1-1" class="reference"><a href="#cite_note-a-1">&#91;1&#93;</a></sup>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-a-1" class="mw-cite-dir-ltr"><span class="mw-cite-backlink">↑ <sup><a href="#cite_ref-a_1-0">1.0</a></sup> <sup><a href="#cite_ref-a_1-1">1.1</a></sup></span> <span class="reference-text">abc <span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: One of the <code>&lt;ref&gt;</code> tags with the name "a" does have a conflicting dir attribute.</span></span>
</li>
</ol></div>
!! html/parsoid+disabled
<p><sup class="mw-ref reference" id="cite_ref-a_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a","dir":"ltr"},"body":{"id":"mw-reference-text-cite_note-a-1"}}'><a href="./Parser_test#cite_note-a-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup>
<sup class="mw-ref reference" id="cite_ref-a_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a","dir":"rtl"}}'><a href="./Parser_test#cite_note-a-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" data-mw='{"name":"references","attrs":{}}'>
<ol class="mw-references references">
<li id="cite_note-a-1" class="mw-cite-dir-ltr"><span rel="mw:referencedBy"><a href="./Parser_test#cite_ref-a_1-0"><span class="mw-linkback-text">1 </span></a><a href="./Parser_test#cite_ref-a_1-1"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-a-1" class="mw-reference-text">abc</span></li>
</ol>
</div>
!! end
!! test
T202593: Identical dir attributes are pointless, but should not generate an error
!! wikitext
<ref name="a" dir="rtl" />
<ref name="a" dir="rtl">abc</ref>
<references />
!! html/php
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">&#91;1&#93;</a></sup>
<sup id="cite_ref-a_1-1" class="reference"><a href="#cite_note-a-1">&#91;1&#93;</a></sup>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-a-1" class="mw-cite-dir-rtl"><span class="mw-cite-backlink">↑ <sup><a href="#cite_ref-a_1-0">1.0</a></sup> <sup><a href="#cite_ref-a_1-1">1.1</a></sup></span> <span class="reference-text">abc</span>
</li>
</ol></div>
!! html/parsoid
<p><sup class="mw-ref reference" id="cite_ref-a_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a","dir":"ltr"}}'><a href="./Parser_test#cite_note-a-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup>
<p><sup class="mw-ref reference" id="cite_ref-a_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a","dir":"rtl"}}'><a href="./Parser_test#cite_note-a-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup>
<sup class="mw-ref reference" id="cite_ref-a_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a","dir":"rtl"},"body":{"id":"mw-reference-text-cite_note-a-1"}}'><a href="./Parser_test#cite_note-a-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" data-mw='{"name":"references","attrs":{}}'>
<ol class="mw-references references">