From 51d55bb8de52c4dba357e0bdccca502668febf85 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 23 Jan 2020 15:00:26 +0100 Subject: [PATCH] =?UTF-8?q?Introduce=20dedicated=20error=20message=20for?= =?UTF-8?q?=20nested=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This resolves another TODO. Since this is an intentional limitation in the design of the feature, I find it pretty signigicant to give it it's own error message. Note that the text does not need to be perfect, just good enough for now. We will review all error messages later via T238188. Bug: T242141 Change-Id: Id9c863061e855350320131e81f6702c8810736f4 --- i18n/en.json | 1 + i18n/qqq.json | 1 + src/Cite.php | 4 ++-- src/ReferencesFormatter.php | 4 ++-- tests/parser/bookReferencing.txt | 3 +-- tests/phpunit/unit/ReferencesFormatterTest.php | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index e82564074..c4f70ad34 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -21,6 +21,7 @@ "cite_error_ref_numeric_key": "Invalid <ref> tag;\nname cannot be a simple integer. Use a descriptive title", "cite_error_ref_no_key": "The opening <ref> tag is malformed or has a bad name", "cite_error_ref_too_many_keys": "Invalid <ref> tag;\ninvalid names, e.g. too many", + "cite_error_ref_nested_extends": "Extending <ref> tags more than one level deep is not allowed", "cite_error_ref_no_input": "Invalid <ref> tag;\nrefs with no name must have content", "cite_error_references_duplicate_key": "Invalid <ref> tag; name \"$1\" defined multiple times with different content", "cite_error_references_invalid_parameters": "Invalid parameter in <references> tag", diff --git a/i18n/qqq.json b/i18n/qqq.json index d9f1d3725..ea728ebdb 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -22,6 +22,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 <ref name=\"123\"/> or <ref name=\"456\">input", "cite_error_ref_no_key": "Error message shown when ref tags without any content (that is <ref/>) are used without a name.", "cite_error_ref_too_many_keys": "Error message shown when ref tags has parameters other than name and group. Examples that cause this error are <ref name=\"name\" notname=\"value\"/> or <ref notname=\"value\" >input", + "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 <ref>", "cite_error_references_duplicate_key": "Error message shown when multiple refs with same name exist but with different content", "cite_error_references_invalid_parameters": "Error message shown when parameters are used in the references tag. An example that causes this error is <references someparameter=\"value\"/>.", diff --git a/src/Cite.php b/src/Cite.php index 1c2f5d3aa..e0097eb1f 100644 --- a/src/Cite.php +++ b/src/Cite.php @@ -180,8 +180,8 @@ class Cite { return StatusValue::newFatal( 'cite_error_references_duplicate_key', $name ); } elseif ( isset( $groupRefs[$extends]['extends'] ) ) { // A sub-reference can not be extended a second time (no nesting) - // TODO: Introduce a specific error for this case, reuse in formatReferences()! - return StatusValue::newFatal( 'cite_error_ref_too_many_keys' ); + return StatusValue::newFatal( 'cite_error_ref_nested_extends', $extends, + $groupRefs[$extends]['extends'] ); } } diff --git a/src/ReferencesFormatter.php b/src/ReferencesFormatter.php index 354ca6e97..0e18334fc 100644 --- a/src/ReferencesFormatter.php +++ b/src/ReferencesFormatter.php @@ -119,8 +119,8 @@ class ReferencesFormatter { isset( $groupRefs[$value['extends']]['extends'] ) ) { $value['text'] = ( $value['text'] ?? '' ) . ' ' . - // TODO: Introduce a specific error for this case; reuse in validateRef()! - $this->errorReporter->plain( $parser, 'cite_error_ref_too_many_keys' ); + $this->errorReporter->plain( $parser, 'cite_error_ref_nested_extends', + $value['extends'], $groupRefs[$value['extends']]['extends'] ); } if ( !$indented && isset( $value['extends'] ) ) { diff --git a/tests/parser/bookReferencing.txt b/tests/parser/bookReferencing.txt index daa626698..4ffaa0708 100644 --- a/tests/parser/bookReferencing.txt +++ b/tests/parser/bookReferencing.txt @@ -243,8 +243,7 @@ wgCiteBookReferencing=true !! html/php

[1] [1.1] -Cite error: Invalid <ref> tag; -invalid names, e.g. too many +Cite error: Extending <ref> tags more than one level deep is not allowed

  1. book diff --git a/tests/phpunit/unit/ReferencesFormatterTest.php b/tests/phpunit/unit/ReferencesFormatterTest.php index 3c34285ca..0efb297b2 100644 --- a/tests/phpunit/unit/ReferencesFormatterTest.php +++ b/tests/phpunit/unit/ReferencesFormatterTest.php @@ -126,7 +126,7 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase { '
      ' . "\n" . '
    1. (cite_references_link_many|||t3' . "\n" . '|)
      1. (cite_references_link_many|||' . - 't1 (cite_error_ref_too_many_keys)' . + 't1 (cite_error_ref_nested_extends|a|b)' . "\n|)
      2. \n" . '
      3. (cite_references_link_many|||t2' . "\n|)
      4. \n
    2. \n" .