From 0cac84e6b2a83fe3a828cf40dc0f20f1172a30bd Mon Sep 17 00:00:00 2001 From: sbailey Date: Mon, 30 Mar 2020 17:25:07 -0700 Subject: [PATCH] Fix Cite extension no name and no content error handling * The html generated matches the spec: https://www.mediawiki.org/wiki/Specs/HTML/2.1.0#Error_handling data-mw errors format. * The html generated also matches the spec: https://phabricator.wikimedia.org/T251842 Bug: T51538 Change-Id: I7b3a3ddd72abfab22b4565f7282f7ba95b246301 --- src/Parsoid/Ref.php | 5 ++++- src/Parsoid/References.php | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Parsoid/Ref.php b/src/Parsoid/Ref.php index 3f2a140c9..8a19ee48b 100644 --- a/src/Parsoid/Ref.php +++ b/src/Parsoid/Ref.php @@ -62,7 +62,10 @@ class Ref extends ExtensionTagHandler { if ( WTUtils::fromExtensionContent( $ref, 'references' ) ) { return $ref->nextSibling; } - + // Ignore content from reference errors + if ( DOMUtils::hasTypeOf( $ref, 'mw:Error' ) ) { + return $ref->nextSibling; + } $refFirstChild = $ref->firstChild; DOMUtils::assertElt( $refFirstChild ); $linkBackId = preg_replace( '/[^#]*#/', '', $refFirstChild->getAttribute( 'href' ), 1 ); diff --git a/src/Parsoid/References.php b/src/Parsoid/References.php index bff480e15..f916b6cdf 100644 --- a/src/Parsoid/References.php +++ b/src/Parsoid/References.php @@ -144,6 +144,9 @@ class References extends ExtensionTagHandler { // Add ref-index linkback $linkBack = $doc->createElement( 'sup' ); + // Check for missing name and content and generate error code + $hasMissingNameAndContent = ( $refName === '' && !empty( $cDp->empty ) ); + // FIXME: Lot of useless work for an edge case if ( !empty( $cDp->empty ) ) { // Discard wrapper if there was no input wikitext @@ -182,6 +185,10 @@ class References extends ExtensionTagHandler { ] ); DOMUtils::addTypeOf( $linkBack, 'mw:Extension/ref' ); + if ( $hasMissingNameAndContent ) { + DOMUtils::addTypeOf( $linkBack, 'mw:Error' ); + } + $dataParsoid = new stdClass; if ( isset( $nodeDp->src ) ) { $dataParsoid->src = $nodeDp->src; @@ -193,11 +200,18 @@ class References extends ExtensionTagHandler { $dataParsoid->pi = $nodeDp->pi; } DOMDataUtils::setDataParsoid( $linkBack, $dataParsoid ); - if ( $isTplWrapper ) { - DOMDataUtils::setDataMw( $linkBack, $tplDmw ); - } else { - DOMDataUtils::setDataMw( $linkBack, $refDmw ); + + $dmw = $isTplWrapper ? $tplDmw : $refDmw; + if ( $hasMissingNameAndContent ) { + $errs = [ + [ 'key' => 'cite_error_ref_no_input' ], + ]; + if ( is_array( $dmw->errors ?? null ) ) { + $errs = array_merge( $dmw->errors, $errs ); + } + $dmw->errors = $errs; } + DOMDataUtils::setDataMw( $linkBack, $dmw ); // refLink is the link to the citation $refLink = $doc->createElement( 'a' );