mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Move setting data-mw on autogenerated references to createReferences
Change-Id: I2fb41ac5eb298d7388543b98cf81c683ded585ed
This commit is contained in:
parent
8cb34b6a4c
commit
936da16c3b
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in a new issue