Cite: Eliminate knowledge of DOM state from a few more call sites

* Cite (or other extensions) don't need to explicitly load/store
  data attributes from html attributes to/from the data bag held
  separately from the DOM.

Bug: T242746
Change-Id: I4a52be2b06ccfe53d0cf81987af12a1d139fef4c
This commit is contained in:
Subramanya Sastry 2020-02-10 17:34:56 -05:00 committed by jenkins-bot
parent 5397598842
commit 25bd654ce1
3 changed files with 14 additions and 24 deletions

View file

@ -8,7 +8,6 @@ use DOMNode;
use Exception;
use Wikimedia\Parsoid\Config\ParsoidExtensionAPI;
use Wikimedia\Parsoid\Ext\ExtensionTag;
use Wikimedia\Parsoid\Utils\ContentUtils;
use Wikimedia\Parsoid\Utils\DOMCompat;
use Wikimedia\Parsoid\Utils\DOMDataUtils;
use Wikimedia\Parsoid\Utils\DOMUtils;
@ -102,12 +101,7 @@ class Ref extends ExtensionTag {
$bodyElt = DOMCompat::getElementById( $editedDoc, $dataMw->body->id );
}
if ( $bodyElt ) {
// n.b. this is going to drop any diff markers but since
// the dom differ doesn't traverse into extension content
// none should exist anyways.
DOMDataUtils::visitAndStoreDataAttribs( $bodyElt );
$html = ContentUtils::toXML( $bodyElt, [ 'innerXML' => true ] );
DOMDataUtils::visitAndLoadDataAttribs( $bodyElt );
$html = ParsoidExtensionAPI::innerHTML( $bodyElt );
} else {
// Some extra debugging for VisualEditor
$extraDebug = '';

View file

@ -8,7 +8,6 @@ use DOMElement;
use stdClass;
use Wikimedia\Parsoid\Config\ParsoidExtensionAPI;
use Wikimedia\Parsoid\Utils\DOMDataUtils;
use Wikimedia\Parsoid\Utils\DOMUtils;
/**
* Helper class used by `<references>` implementation.
@ -99,9 +98,10 @@ class RefGroup {
);
if ( $refContentId ) {
$content = $extApi->getContentDOM( $refContentId );
DOMDataUtils::visitAndStoreDataAttribs( $content );
DOMUtils::migrateChildrenBetweenDocs( $content, $reftextSpan );
DOMDataUtils::visitAndLoadDataAttribs( $reftextSpan );
// The data-mw and data-parsoid attributes aren't needed on the ref content
// in the references section. The content wrapper will remain in the original
// site where the <ref> tag showed up and will retain data-parsoid & data-mw.
ParsoidExtensionAPI::migrateChildrenBetweenDocs( $content, $reftextSpan, false );
}
$li->appendChild( $reftextSpan );

View file

@ -11,7 +11,6 @@ use Wikimedia\Assert\Assert;
use Wikimedia\Parsoid\Config\ParsoidExtensionAPI;
use Wikimedia\Parsoid\Ext\ExtensionTag;
use Wikimedia\Parsoid\Tokens\DomSourceRange;
use Wikimedia\Parsoid\Utils\ContentUtils;
use Wikimedia\Parsoid\Utils\DOMCompat;
use Wikimedia\Parsoid\Utils\DOMDataUtils;
use Wikimedia\Parsoid\Utils\DOMUtils;
@ -117,9 +116,7 @@ class References extends ExtensionTag {
$tplDmw = $isTplWrapper ? DOMDataUtils::getDataMw( $node ) : null;
// This is the <sup> that's the meat of the sealed fragment
/** @var DOMElement $c */
$c = $extApi->getContentDOM( $contentId );
DOMUtils::assertElt( $c );
$cDp = DOMDataUtils::getDataParsoid( $c );
$refDmw = DOMDataUtils::getDataMw( $c );
if ( empty( $cDp->empty ) && self::hasRef( $c ) ) { // nested ref-in-ref
@ -159,7 +156,10 @@ class References extends ExtensionTag {
$html = '';
$contentDiffers = false;
if ( $ref->hasMultiples ) {
$html = ContentUtils::ppToXML( $c, [ 'innerXML' => true ] );
$html = $extApi->toHTML( $c );
// ParsoidExtensionAPI says $c shouldn't used beyond the toHTML call
// So, set $c to null to explicitly prevent that usage.
$c = null;
$contentDiffers = $html !== $ref->cachedHtml;
}
if ( $contentDiffers ) {
@ -169,11 +169,6 @@ class References extends ExtensionTag {
}
}
// FIXME: This leaks internal information about how Parsoid handles the DOM.
// $c may not be in canonical form anymore
// and shouldn't be used beyond this point.
$c = null;
DOMDataUtils::addAttributes( $linkBack, [
'about' => $about,
'class' => 'mw-ref',
@ -233,7 +228,8 @@ class References extends ExtensionTag {
} else {
// We don't need to delete the node now since it'll be removed in
// `insertReferencesIntoDOM` when all the children are cleaned out.
array_push( $nestedRefsHTML, ContentUtils::ppToXML( $linkBack ), "\n" );
array_push( $nestedRefsHTML, $extApi->toHTML( $linkBack, false ), "\n" );
$linkBack = null; // should not be used beyond this point as per 'toHTML' docs
}
// Keep the first content to compare multiple <ref>s with the same name.
@ -367,9 +363,9 @@ class References extends ExtensionTag {
private static function processEmbeddedRefs(
ParsoidExtensionAPI $extApi, ReferencesData $refsData, string $str
): string {
$dom = ContentUtils::ppToDOM( $extApi->getEnv(), $str );
self::processRefs( $extApi, $refsData, $dom );
return ContentUtils::ppToXML( $dom, [ 'innerXML' => true ] );
$domBody = DOMCompat::getBody( $extApi->parseHTML( $str ) );
self::processRefs( $extApi, $refsData, $domBody );
return $extApi->toHTML( $domBody );
}
/**