diff --git a/src/Parsoid/References.php b/src/Parsoid/References.php index 8ccd98eac..b9b96c847 100644 --- a/src/Parsoid/References.php +++ b/src/Parsoid/References.php @@ -7,7 +7,6 @@ use DOMDocument; use DOMElement; use DOMNode; use stdClass; -use Wikimedia\Assert\Assert; use Wikimedia\Parsoid\Core\DomSourceRange; use Wikimedia\Parsoid\Ext\DOMDataUtils; use Wikimedia\Parsoid\Ext\DOMUtils; @@ -48,8 +47,8 @@ class References extends ExtensionTagHandler { * @return DOMElement */ private static function createReferences( - ParsoidExtensionAPI $extApi, DOMDocument $doc, ?DOMNode $body, array $refsOpts, - ?callable $modifyDp, bool $autoGenerated = false + ParsoidExtensionAPI $extApi, DOMDocument $doc, ?DOMNode $body, + array $refsOpts, ?callable $modifyDp, bool $autoGenerated = false ): DOMElement { $ol = $doc->createElement( 'ol' ); DOMCompat::getClassList( $ol )->add( 'mw-references' ); @@ -76,14 +75,24 @@ class References extends ExtensionTagHandler { } if ( $autoGenerated ) { + // FIXME: This is very much trying to copy ExtensionHandler::onDocument DOMUtils::addAttributes( $frag, [ 'typeof' => 'mw:Extension/references', 'about' => $extApi->newAboutId() ] ); + $dataMw = (object)[ + 'name' => 'references', + 'attrs' => new stdClass, + ]; + // Dont emit empty keys + if ( $refsOpts['group'] ) { + $dataMw->attrs->group = $refsOpts['group']; + } + DOMDataUtils::setDataMw( $frag, $dataMw ); } $dp = DOMDataUtils::getDataParsoid( $frag ); - if ( $refsOpts['group'] ) { // No group for the empty string either + if ( $refsOpts['group'] ) { // No group for the empty string either $dp->group = $refsOpts['group']; $ol->setAttribute( 'data-mw-group', $refsOpts['group'] ); } @@ -270,20 +279,6 @@ class References extends ExtensionTagHandler { $group = $dp->group ?? ''; if ( !$isTplWrapper ) { $dataMw = DOMDataUtils::getDataMw( $refsNode ); - if ( !count( (array)$dataMw ) ) { - // FIXME: This can be moved to `insertMissingReferencesIntoDOM` - Assert::invariant( $autoGenerated, 'Expected non empty $dataMw or $autoGenerated is true' ); - $dataMw = (object)[ - 'name' => 'references', - 'attrs' => new stdClass, - ]; - // Dont emit empty keys - if ( $group ) { - $dataMw->attrs->group = $group; - } - DOMDataUtils::setDataMw( $refsNode, $dataMw ); - } - // Mark this auto-generated so that we can skip this during // html -> wt and so that clients can strip it if necessary. if ( $autoGenerated ) {