diff --git a/src/ErrorReporter.php b/src/ErrorReporter.php
index a06f662ac..a9f45f375 100644
--- a/src/ErrorReporter.php
+++ b/src/ErrorReporter.php
@@ -2,6 +2,7 @@
namespace Cite;
+use Cite\Parsoid\ErrorUtils;
use InvalidArgumentException;
use MediaWiki\Html\Html;
use MediaWiki\Language\Language;
@@ -75,6 +76,9 @@ class ErrorReporter {
if ( $type === 'error' ) {
// Take care; this is a sideeffect that might not belong to this class.
$parser->addTrackingCategory( 'cite-tracking-category-cite-error' );
+ if ( ErrorUtils::isDiffingError( $key ) ) {
+ $parser->addTrackingCategory( 'cite-tracking-category-cite-diffing-error' );
+ }
}
// Optional wrapper messages: cite_error, cite_warning
@@ -125,5 +129,4 @@ class ErrorReporter {
}
return array_slice( $matches, 1 );
}
-
}
diff --git a/src/Parsoid/ErrorUtils.php b/src/Parsoid/ErrorUtils.php
new file mode 100644
index 000000000..a07d9fd43
--- /dev/null
+++ b/src/Parsoid/ErrorUtils.php
@@ -0,0 +1,61 @@
+ true,
+ 'cite_error_ref_no_key' => true,
+ 'cite_error_ref_too_many_keys' => true,
+ 'cite_error_references_invalid_parameters' => true,
+ 'cite_error_ref_invalid_dir' => true,
+ 'cite_error_ref_follow_conflicts' => true,
+ 'cite_error_ref_no_input' => true,
+ 'cite_error_group_refs_without_references' => true,
+ ];
+ return $diffingErrors[$catName] ?? false;
+ }
+
+ /**
+ * Creates a document fragment containing the Parsoid rendering of an error message
+ */
+ public static function renderParsoidError(
+ ParsoidExtensionAPI $extApi,
+ string $errorKey,
+ ?array $errorParams
+ ): DocumentFragment {
+ $error = new MessageValue( $errorKey, $errorParams ?? [] );
+ return self::renderParsoidErrorSpan( $extApi, $error );
+ }
+
+ /**
+ * Adds classes and lead on an existing Parsoid rendering of an error message, sets the tracking category and
+ * returns the completed fragment
+ */
+ public static function renderParsoidErrorSpan(
+ ParsoidExtensionAPI $extApi, MessageValue $error
+ ): DocumentFragment {
+ $extApi->addTrackingCategory( 'cite-tracking-category-cite-error' );
+ $fragment = $extApi->createInterfaceI18nFragment( 'cite_error', [ $error ] );
+ $fragSpan = DOMCompat::getLastElementChild( $fragment );
+ DOMUtils::addAttributes( $fragSpan, [ 'class' => 'error mw-ext-cite-error' ] );
+ return $fragment;
+ }
+}
diff --git a/src/Parsoid/RefGroup.php b/src/Parsoid/RefGroup.php
index eeb5e2a32..328ae7cd4 100644
--- a/src/Parsoid/RefGroup.php
+++ b/src/Parsoid/RefGroup.php
@@ -5,6 +5,7 @@ namespace Cite\Parsoid;
use Wikimedia\Parsoid\DOM\Document;
use Wikimedia\Parsoid\DOM\Element;
+use Wikimedia\Parsoid\Ext\DOMDataUtils;
use Wikimedia\Parsoid\Ext\DOMUtils;
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
use Wikimedia\Parsoid\Utils\DOMCompat;
@@ -83,6 +84,16 @@ class RefGroup {
}
$li->appendChild( $reftextSpan );
+ foreach ( $ref->nodes as $node ) {
+ foreach ( DOMDataUtils::getDataMw( $node )->errors ?? [] as $error ) {
+ $errorFragment = ErrorUtils::renderParsoidError( $extApi, $error->key, $error->params );
+ $li->appendChild( $errorFragment );
+ if ( ErrorUtils::isDiffingError( $error->key ) ) {
+ $extApi->addTrackingCategory( 'cite-tracking-category-cite-diffing-error' );
+ }
+ }
+ }
+
// mw:referencedBy is added to the for the named refs case
// and to the tag to the unnamed refs case. This difference
// is used by CSS to style backlinks in MediaWiki:Common.css
diff --git a/src/Parsoid/References.php b/src/Parsoid/References.php
index 4fafffc00..3560cd454 100644
--- a/src/Parsoid/References.php
+++ b/src/Parsoid/References.php
@@ -6,11 +6,13 @@ declare( strict_types = 1 );
namespace Cite\Parsoid;
+use Cite\Cite;
use Cite\MarkSymbolRenderer;
use Closure;
use MediaWiki\Config\Config;
use MediaWiki\MediaWikiServices;
use stdClass;
+use Wikimedia\Message\MessageValue;
use Wikimedia\Parsoid\Core\DomSourceRange;
use Wikimedia\Parsoid\DOM\DocumentFragment;
use Wikimedia\Parsoid\DOM\Element;
@@ -158,6 +160,18 @@ class References extends ExtensionTagHandler {
);
}
+ static $validAttributes = [
+ 'group' => true,
+ 'name' => true,
+ Cite::SUBREF_ATTRIBUTE => true,
+ 'follow' => true,
+ 'dir' => true
+ ];
+
+ if ( array_diff_key( (array)$refDmw->attrs, $validAttributes ) !== [] ) {
+ $errs[] = new DataMwError( 'cite_error_ref_too_many_keys' );
+ }
+
// NOTE: This will have been trimmed in Utils::getExtArgInfo()'s call
// to TokenUtils::kvToHash() and ExtensionHandler::normalizeExtOptions()
$refName = $refDmw->attrs->name ?? '';
@@ -764,6 +778,7 @@ class References extends ExtensionTagHandler {
foreach ( $refsOpts as $key => $value ) {
if ( !in_array( strtolower( (string)$key ), $knownAttributes, true ) ) {
$extApi->pushError( 'cite_error_references_invalid_parameters' );
+ $error = new MessageValue( 'cite_error_references_invalid_parameters' );
break;
}
}
@@ -782,6 +797,14 @@ class References extends ExtensionTagHandler {
}
);
$domFragment->appendChild( $frag );
+
+ if ( isset( $error ) ) {
+ $errorFragment = ErrorUtils::renderParsoidErrorSpan( $extApi, $error );
+ // we're pushing it after the reference block while it tends to be before in legacy (error + rerender)
+ $extApi->addTrackingCategory( 'cite-tracking-category-cite-diffing-error' );
+ $frag->appendChild( $errorFragment );
+ }
+
return $domFragment;
}
diff --git a/tests/parser/citeParserTests-knownFailures.json b/tests/parser/citeParserTests-knownFailures.json
index cdd6ed754..7ecd8a7b7 100644
--- a/tests/parser/citeParserTests-knownFailures.json
+++ b/tests/parser/citeParserTests-knownFailures.json
@@ -73,7 +73,7 @@
},
"Erroneous refs": {
"wt2wt": "Zero\n\nAlso zero, but differently! (Normal ref)\n\n\n\n\n\n\n\n A [1] B [inexistent 1] A [1] B [inexistent 1]
tag\n"
- },
"Simple , with
Cite error: Invalid parameter in <ref>
tag
Cite error: Invalid parameter in <ref>
tag
ONE[1]
- + - + !! html/phpONE[1]
@@ -1029,7 +1041,7 @@ Error conditions on non-visible content - + !! end # This article is used in the ' with custom group link' test below @@ -1143,7 +1155,7 @@ zeroCite error: The op - + !! end !! test @@ -1156,7 +1168,7 @@ Bla. !! html/parsoidBla.[1]
- + !! end !! test @@ -1173,7 +1185,7 @@ Ho Cite error: The ope !! html/parsoid - + !! end !! test @@ -1189,7 +1201,7 @@ Bla. !! html/parsoidBla.[1]
- + !! end !! test @@ -1229,7 +1241,7 @@ Multiple definition (outsideTHREE[NOTES 1] FOUR[NOTES 2] FIVE[NOTES 2] SIX[1]
- +
Cite error: <ref>
tags exist for a group named "theGroup", but no corresponding <references group="theGroup"/>
tag was found
[1] +
+<ref>
tag; no text was provided for refs named aaa