mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Fix Cite extension <ref> 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
This commit is contained in:
parent
46f749b92f
commit
0cac84e6b2
|
@ -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 );
|
||||
|
|
|
@ -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' );
|
||||
|
|
Loading…
Reference in a new issue