Only display the first occurrence of an error

It can happen that an error is reported multiple times for a given
reference. In this case, we only display one.
We still display different errors if a reference contains multiple
different errors. This behaviour is differs from the legacy parser's
(so, in this case, we add the category
cite-tracking-category-cite-diffing-error), but not from the legacy
parser's desired behaviour, as hinted by the various comments and TODO
in this area.

Bug: T380153
Change-Id: I9b3d5cbd086fc72c66a2afbae8f92297681989ce
This commit is contained in:
Isabelle Hurbain-Palatin 2024-11-18 13:54:56 +01:00
parent 87ae1a1de0
commit d3f85b16c5
2 changed files with 16 additions and 3 deletions

View file

@ -84,11 +84,24 @@ class RefGroup {
} }
$li->appendChild( $reftextSpan ); $li->appendChild( $reftextSpan );
// It seems counter-productive to go through hoops to not display all the errors considering that rendering
// only the first one is considered deprecated in the legacy code. However, displaying the same error
// multiple times for the same reference is also useless.
// Hence, we avoid displaying the same error multiple times, and keep count of multiple errors under this
// constraint; if we still display multiple errors where the legacy parser would only display one, we add
// the page to the cite-tracking-category-cite-diffing-error category.
$reported = [];
$errorCount = 0;
foreach ( $ref->nodes as $node ) { foreach ( $ref->nodes as $node ) {
foreach ( DOMDataUtils::getDataMw( $node )->errors ?? [] as $error ) { foreach ( DOMDataUtils::getDataMw( $node )->errors ?? [] as $error ) {
if ( in_array( $error, $reported ) ) {
continue;
}
$reported[] = $error;
$errorCount++;
$errorFragment = ErrorUtils::renderParsoidError( $extApi, $error->key, $error->params ); $errorFragment = ErrorUtils::renderParsoidError( $extApi, $error->key, $error->params );
$li->appendChild( $errorFragment ); $li->appendChild( $errorFragment );
if ( ErrorUtils::isDiffingError( $error->key ) ) { if ( ErrorUtils::isDiffingError( $error->key ) || $errorCount > 1 ) {
$extApi->addTrackingCategory( 'cite-tracking-category-cite-diffing-error' ); $extApi->addTrackingCategory( 'cite-tracking-category-cite-diffing-error' );
} }
} }

View file

@ -2035,12 +2035,12 @@ BETA<sup about="#mwt6" class="mw-ref reference" id="cite_ref-foo_1-1" rel="dc:re
ONE<sup about="#mwt9" class="mw-ref reference" id="cite_ref-foo_2-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"}}'><a href="./Parser_test#cite_note-foo-2" style="counter-reset: mw-Ref 1;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 1]</span></a></sup> ONE<sup about="#mwt9" class="mw-ref reference" id="cite_ref-foo_2-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"}}'><a href="./Parser_test#cite_note-foo-2" style="counter-reset: mw-Ref 1;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 1]</span></a></sup>
TWO<sup about="#mwt12" class="mw-ref reference" id="cite_ref-foo_2-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"},"body":{"id":"mw-reference-text-cite_note-foo-2"}}'><a href="./Parser_test#cite_note-foo-2" style="counter-reset: mw-Ref 1;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 1]</span></a></sup></p> TWO<sup about="#mwt12" class="mw-ref reference" id="cite_ref-foo_2-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"},"body":{"id":"mw-reference-text-cite_note-foo-2"}}'><a href="./Parser_test#cite_note-foo-2" style="counter-reset: mw-Ref 1;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 1]</span></a></sup></p>
<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt15" data-mw='{"name":"references","attrs":{"group":"NOTES"}}'><ol class="mw-references references" data-mw-group="NOTES"><li about="#cite_note-foo-2" id="cite_note-foo-2"><span rel="mw:referencedBy" class="mw-cite-backlink"><a href="./Parser_test#cite_ref-foo_2-0" data-mw-group="NOTES"><span class="mw-linkback-text">1 </span></a><a href="./Parser_test#cite_ref-foo_2-1" data-mw-group="NOTES"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-foo-2" class="mw-reference-text reference-text">food</span></li></ol></div> <div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt15" data-mw='{"name":"references","attrs":{"group":"NOTES"}}'><ol class="mw-references references" data-mw-group="NOTES"><li about="#cite_note-foo-2" id="cite_note-foo-2"><span rel="mw:referencedBy" class="mw-cite-backlink"><a href="./Parser_test#cite_ref-foo_2-0" data-mw-group="NOTES"><span class="mw-linkback-text">1 </span></a><a href="./Parser_test#cite_ref-foo_2-1" data-mw-group="NOTES"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-foo-2" class="mw-reference-text reference-text">food</span></li></ol></div>
<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt18" data-mw='{"name":"references","attrs":{}}'><ol class="mw-references references"><li about="#cite_note-foo-1" id="cite_note-foo-1"><span rel="mw:referencedBy" class="mw-cite-backlink"><a href="./Parser_test#cite_ref-foo_1-0"><span class="mw-linkback-text">1 </span></a><a href="./Parser_test#cite_ref-foo_1-1"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-foo-1" class="mw-reference-text reference-text"></span><span typeof="mw:I18n" class="error mw-ext-cite-error" data-mw-i18n='{"/":{"lang":"x-user","key":"cite_error","params":{"0":{"key":"cite_error_references_no_text","params":{"0":{"text":"foo","_type_":"Wikimedia\\Message\\ScalarParam"},"_type_":"array"},"_type_":"Wikimedia\\Message\\MessageValue"},"_type_":"array"}}}'></span><span typeof="mw:I18n" class="error mw-ext-cite-error" data-mw-i18n='{"/":{"lang":"x-user","key":"cite_error","params":{"0":{"key":"cite_error_references_no_text","params":{"0":{"text":"foo","_type_":"Wikimedia\\Message\\ScalarParam"},"_type_":"array"},"_type_":"Wikimedia\\Message\\MessageValue"},"_type_":"array"}}}'></span></li></ol></div> <div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt18" data-mw='{"name":"references","attrs":{}}'><ol class="mw-references references"><li about="#cite_note-foo-1" id="cite_note-foo-1"><span rel="mw:referencedBy" class="mw-cite-backlink"><a href="./Parser_test#cite_ref-foo_1-0"><span class="mw-linkback-text">1 </span></a><a href="./Parser_test#cite_ref-foo_1-1"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-foo-1" class="mw-reference-text reference-text"></span><span typeof="mw:I18n" class="error mw-ext-cite-error" data-mw-i18n='{"/":{"lang":"x-user","key":"cite_error","params":{"0":{"key":"cite_error_references_no_text","params":{"0":{"text":"foo","_type_":"Wikimedia\\Message\\ScalarParam"},"_type_":"array"},"_type_":"Wikimedia\\Message\\MessageValue"},"_type_":"array"}}}'></span></li></ol></div>
<p>THREE<sup about="#mwt21" class="mw-ref reference" id="cite_ref-bar_3-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"bar"},"body":{"id":"mw-reference-text-cite_note-bar-3"}}'><a href="./Parser_test#cite_note-bar-3" style="counter-reset: mw-Ref 1;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 1]</span></a></sup> <p>THREE<sup about="#mwt21" class="mw-ref reference" id="cite_ref-bar_3-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"bar"},"body":{"id":"mw-reference-text-cite_note-bar-3"}}'><a href="./Parser_test#cite_note-bar-3" style="counter-reset: mw-Ref 1;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 1]</span></a></sup>
FOUR<sup about="#mwt24" class="mw-ref reference" id="cite_ref-foo_4-0" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"},"errors":[{"key":"cite_error_references_no_text","params":["foo"]}]}'><a href="./Parser_test#cite_note-foo-4" style="counter-reset: mw-Ref 2;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 2]</span></a></sup> FOUR<sup about="#mwt24" class="mw-ref reference" id="cite_ref-foo_4-0" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"},"errors":[{"key":"cite_error_references_no_text","params":["foo"]}]}'><a href="./Parser_test#cite_note-foo-4" style="counter-reset: mw-Ref 2;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 2]</span></a></sup>
FIVE<sup about="#mwt27" class="mw-ref reference" id="cite_ref-foo_4-1" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"},"errors":[{"key":"cite_error_references_no_text","params":["foo"]}]}'><a href="./Parser_test#cite_note-foo-4" style="counter-reset: mw-Ref 2;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 2]</span></a></sup> FIVE<sup about="#mwt27" class="mw-ref reference" id="cite_ref-foo_4-1" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"},"errors":[{"key":"cite_error_references_no_text","params":["foo"]}]}'><a href="./Parser_test#cite_note-foo-4" style="counter-reset: mw-Ref 2;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 2]</span></a></sup>
SIX<sup about="#mwt30" class="mw-ref reference" id="cite_ref-foo_5-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"foo"}}'><a href="./Parser_test#cite_note-foo-5" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup></p> SIX<sup about="#mwt30" class="mw-ref reference" id="cite_ref-foo_5-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"foo"}}'><a href="./Parser_test#cite_note-foo-5" 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="#mwt33" data-mw='{"name":"references","attrs":{"group":"NOTES"}}'><ol class="mw-references references" data-mw-group="NOTES"><li about="#cite_note-bar-3" id="cite_note-bar-3"><span class="mw-cite-backlink"><a href="./Parser_test#cite_ref-bar_3-0" data-mw-group="NOTES" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a></span> <span id="mw-reference-text-cite_note-bar-3" class="mw-reference-text reference-text">CONTENT</span></li><li about="#cite_note-foo-4" id="cite_note-foo-4"><span rel="mw:referencedBy" class="mw-cite-backlink"><a href="./Parser_test#cite_ref-foo_4-0" data-mw-group="NOTES"><span class="mw-linkback-text">1 </span></a><a href="./Parser_test#cite_ref-foo_4-1" data-mw-group="NOTES"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-foo-4" class="mw-reference-text reference-text"></span><span typeof="mw:I18n" class="error mw-ext-cite-error" data-mw-i18n='{"/":{"lang":"x-user","key":"cite_error","params":{"0":{"key":"cite_error_references_no_text","params":{"0":{"text":"foo","_type_":"Wikimedia\\Message\\ScalarParam"},"_type_":"array"},"_type_":"Wikimedia\\Message\\MessageValue"},"_type_":"array"}}}'></span><span typeof="mw:I18n" class="error mw-ext-cite-error" data-mw-i18n='{"/":{"lang":"x-user","key":"cite_error","params":{"0":{"key":"cite_error_references_no_text","params":{"0":{"text":"foo","_type_":"Wikimedia\\Message\\ScalarParam"},"_type_":"array"},"_type_":"Wikimedia\\Message\\MessageValue"},"_type_":"array"}}}'></span></li></ol></div> <div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt33" data-mw='{"name":"references","attrs":{"group":"NOTES"}}'><ol class="mw-references references" data-mw-group="NOTES"><li about="#cite_note-bar-3" id="cite_note-bar-3"><span class="mw-cite-backlink"><a href="./Parser_test#cite_ref-bar_3-0" data-mw-group="NOTES" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a></span> <span id="mw-reference-text-cite_note-bar-3" class="mw-reference-text reference-text">CONTENT</span></li><li about="#cite_note-foo-4" id="cite_note-foo-4"><span rel="mw:referencedBy" class="mw-cite-backlink"><a href="./Parser_test#cite_ref-foo_4-0" data-mw-group="NOTES"><span class="mw-linkback-text">1 </span></a><a href="./Parser_test#cite_ref-foo_4-1" data-mw-group="NOTES"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-foo-4" class="mw-reference-text reference-text"></span><span typeof="mw:I18n" class="error mw-ext-cite-error" data-mw-i18n='{"/":{"lang":"x-user","key":"cite_error","params":{"0":{"key":"cite_error_references_no_text","params":{"0":{"text":"foo","_type_":"Wikimedia\\Message\\ScalarParam"},"_type_":"array"},"_type_":"Wikimedia\\Message\\MessageValue"},"_type_":"array"}}}'></span></li></ol></div>
<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt39" data-mw='{"name":"references","attrs":{},"body":{"html":"\n&lt;sup about=\"#mwt37\" class=\"mw-ref reference\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid=&apos;{\"dsr\":[398,434,16,6]}&apos; data-mw=&apos;{\"name\":\"ref\",\"attrs\":{\"name\":\"foo\"},\"body\":{\"id\":\"mw-reference-text-cite_note-foo-5\"}}&apos;>&lt;a href=\"./Parser_test#cite_note-foo-5\" style=\"counter-reset: mw-Ref 1;\" data-parsoid=\"{}\">&lt;span class=\"mw-reflink-text\" data-parsoid=\"{}\">[1]&lt;/span>&lt;/a>&lt;/sup>\n"}}'><ol class="mw-references references"><li about="#cite_note-foo-5" id="cite_note-foo-5"><span class="mw-cite-backlink"><a href="./Parser_test#cite_ref-foo_5-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a></span> <span id="mw-reference-text-cite_note-foo-5" class="mw-reference-text reference-text">NOGROUPCONTENT</span></li></ol></div> <div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt39" data-mw='{"name":"references","attrs":{},"body":{"html":"\n&lt;sup about=\"#mwt37\" class=\"mw-ref reference\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid=&apos;{\"dsr\":[398,434,16,6]}&apos; data-mw=&apos;{\"name\":\"ref\",\"attrs\":{\"name\":\"foo\"},\"body\":{\"id\":\"mw-reference-text-cite_note-foo-5\"}}&apos;>&lt;a href=\"./Parser_test#cite_note-foo-5\" style=\"counter-reset: mw-Ref 1;\" data-parsoid=\"{}\">&lt;span class=\"mw-reflink-text\" data-parsoid=\"{}\">[1]&lt;/span>&lt;/a>&lt;/sup>\n"}}'><ol class="mw-references references"><li about="#cite_note-foo-5" id="cite_note-foo-5"><span class="mw-cite-backlink"><a href="./Parser_test#cite_ref-foo_5-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a></span> <span id="mw-reference-text-cite_note-foo-5" class="mw-reference-text reference-text">NOGROUPCONTENT</span></li></ol></div>
<p>SEVEN<sup about="#mwt42" class="mw-ref reference" id="cite_ref-bar_6-0" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"bar"},"errors":[{"key":"cite_error_references_no_text","params":["bar"]}]}'><a href="./Parser_test#cite_note-bar-6" style="counter-reset: mw-Ref 1;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 1]</span></a></sup> <p>SEVEN<sup about="#mwt42" class="mw-ref reference" id="cite_ref-bar_6-0" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"bar"},"errors":[{"key":"cite_error_references_no_text","params":["bar"]}]}'><a href="./Parser_test#cite_note-bar-6" style="counter-reset: mw-Ref 1;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 1]</span></a></sup>
EIGHT<sup about="#mwt45" class="mw-ref reference" id="cite_ref-foo_7-0" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"},"errors":[{"key":"cite_error_references_no_text","params":["foo"]}]}'><a href="./Parser_test#cite_note-foo-7" style="counter-reset: mw-Ref 2;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 2]</span></a></sup></p> EIGHT<sup about="#mwt45" class="mw-ref reference" id="cite_ref-foo_7-0" rel="dc:references" typeof="mw:Extension/ref mw:Error" data-mw='{"name":"ref","attrs":{"group":"NOTES","name":"foo"},"errors":[{"key":"cite_error_references_no_text","params":["foo"]}]}'><a href="./Parser_test#cite_note-foo-7" style="counter-reset: mw-Ref 2;" data-mw-group="NOTES"><span class="mw-reflink-text">[NOTES 2]</span></a></sup></p>