Give a different error from too_many_keys when 'follow' attribute conflicts

Add message "cite_error_ref_follow_conflicts" for tags with
conflicting parameters.

Bug: T299280
Change-Id: Ie64f4ab4831966f66f812ea67cc244718f818afb
This commit is contained in:
xiplus 2022-05-27 14:27:10 +08:00 committed by thiemowmde
parent 4377f0923d
commit f7a181ed42
7 changed files with 9 additions and 8 deletions

View file

@ -21,6 +21,7 @@
"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",
"cite_error_ref_follow_conflicts": "A <code>&lt;ref follow=\"…\"&gt;</code> tag that is the continuation of a previous one can neither be named individually nor extended",
"cite_error_ref_nested_extends": "Extending <code>&lt;ref&gt;</code> tags more than one level deep is not allowed",
"cite_error_ref_no_input": "Invalid <code>&lt;ref&gt;</code> tag; refs with no name must have content",
"cite_error_references_duplicate_key": "Invalid <code>&lt;ref&gt;</code> tag; name \"$1\" defined multiple times with different content",

View file

@ -25,6 +25,7 @@
"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.",
"cite_error_ref_follow_conflicts": "Error message shown when a ref tag with the Wikisource-specific <code>follow=\"…\"</code> feature also tries to use a <code>name=\"…\"</code> and/or <code>extends=\"…\"</code> parameter.",
"cite_error_ref_nested_extends": "Error message shown when a ref tag tries to extend another ref tag that's already extended, i.e. nesting sub-refs is not allowed.\n\nParameters:\n* $1 - Name of the invalid ref\n* $2 - Name of the previous, conflicting ref",
"cite_error_ref_no_input": "Error message shown when ref tags without names have no content. An example that cause this error is <code>&lt;ref></ref&gt;</code>",
"cite_error_references_duplicate_key": "Error message shown when multiple refs with same name exist but with different content",

View file

@ -64,8 +64,7 @@ class Validator {
}
if ( $follow && ( $name || $extends ) ) {
// TODO: Introduce a specific error for this case.
return StatusValue::newFatal( 'cite_error_ref_too_many_keys' );
return StatusValue::newFatal( 'cite_error_ref_follow_conflicts' );
}
if ( $dir !== null && !in_array( strtolower( $dir ), [ 'ltr', 'rtl' ], true ) ) {

View file

@ -495,7 +495,7 @@ wgCiteBookReferencing=true
<references />
!! html/php
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">&#91;1&#93;</a></sup>
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid parameter in <code>&lt;ref&gt;</code> tag</span>
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: A <code>&lt;ref follow="…"&gt;</code> tag that is the continuation of a previous one can neither be named individually nor extended</span>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">book 1</span>
@ -515,7 +515,7 @@ wgCiteBookReferencing=true
!! 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-b_2-0" class="reference"><a href="#cite_note-b-2">&#91;2&#93;</a></sup>
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid parameter in <code>&lt;ref&gt;</code> tag</span>
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: A <code>&lt;ref follow="…"&gt;</code> tag that is the continuation of a previous one can neither be named individually nor extended</span>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">book 1</span>

View file

@ -526,7 +526,7 @@ Can't have name="…" and follow="…" the same time
<ref name="theName" follow="theFollows">theValue</ref>
<references />
!! html/php
<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid parameter in <code>&lt;ref&gt;</code> tag</span>
<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: A <code>&lt;ref follow="…"&gt;</code> tag that is the continuation of a previous one can neither be named individually nor extended</span>
</p>
!! html/parsoid
<p><sup about="#mwt2" class="mw-ref reference" id="cite_ref-theName_1-0" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"name":"theName","follow":"theFollows"},"body":{"id":"mw-reference-text-cite_note-theName-1"},"errors":[{"key":"cite_error_ref_too_many_keys"}]}'><a href="./Parser_test#cite_note-theName-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup></p>

View file

@ -118,7 +118,7 @@ It should be impossible to roll back a follow="…", because it can't have a nam
<li id="cite_note-b-2"><span class="mw-cite-backlink"><a href="#cite_ref-b_2-0">↑</a></span> <span class="reference-text">should be 2</span>
</li>
</ol></div>
<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid parameter in <code>&lt;ref&gt;</code> tag</span>
<p><span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: A <code>&lt;ref follow="…"&gt;</code> tag that is the continuation of a previous one can neither be named individually nor extended</span>
</p>
!! end

View file

@ -91,7 +91,7 @@ class ValidatorTest extends \MediaWikiIntegrationTestCase {
'extends' => null,
'follow' => 'f',
'dir' => null,
'expected' => 'cite_error_ref_too_many_keys',
'expected' => 'cite_error_ref_follow_conflicts',
],
'Follow with extends' => [
'referencesStack' => [],
@ -103,7 +103,7 @@ class ValidatorTest extends \MediaWikiIntegrationTestCase {
'extends' => 'e',
'follow' => 'f',
'dir' => null,
'expected' => 'cite_error_ref_too_many_keys',
'expected' => 'cite_error_ref_follow_conflicts',
],
// Validating <ref> outside of <references>
'text-only <ref>' => [