mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Don't keep pointers to nodes from embedded content
Since the fragment they're subtrees of goes out of scope.
Follow up to 2f09cdb
Previous to that patch this wasn't an issue because we were creating a
whole document which is retained by the environment.
Fixes the warnings from,
"PHP Warning: DOMElement::getAttribute(): Couldn't fetch DOMElement"
https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-2020.10.02/parsoid-tests?id=AXTqaLL12lgCwKx7fVYz&_g=h@a06543d
Tested on scandium with,
node bin/roundtrip-test.js --proxyURL http://scandium.eqiad.wmnet:80 --parsoidURL http://DOMAIN/w/rest.php --domain vi.wikipedia.org "Vua_Việt_Nam"
Change-Id: I74bc7de79b18054e19b77af25e978d3ab3a505e4
This commit is contained in:
parent
f00325d6cc
commit
6bd0594f28
|
@ -473,6 +473,16 @@ class References extends ExtensionTagHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* The fragment generated is scoped to the function so we can't keep
|
||||
* pointers to subtrees of it when collecting references data.
|
||||
* See https://bugs.php.net/bug.php?id=39593
|
||||
*
|
||||
* Removing the nodes would keep them alive but updating them in
|
||||
* insertReferencesIntoDOM isn't helpful because we've already serialized
|
||||
* the fragment.
|
||||
*
|
||||
* There's already a FIXME there to say this isn't supported.
|
||||
*
|
||||
* @param ParsoidExtensionAPI $extApi
|
||||
* @param ReferencesData $refsData
|
||||
* @param string $str
|
||||
|
@ -482,7 +492,10 @@ class References extends ExtensionTagHandler {
|
|||
ParsoidExtensionAPI $extApi, ReferencesData $refsData, string $str
|
||||
): string {
|
||||
$domFragment = $extApi->htmlToDom( $str );
|
||||
$inEmbeddedContent = $refsData->inEmbeddedContent;
|
||||
$refsData->inEmbeddedContent = true;
|
||||
self::processRefs( $extApi, $refsData, $domFragment );
|
||||
$refsData->inEmbeddedContent = $inEmbeddedContent;
|
||||
return $extApi->domToHtml( $domFragment, true, true );
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,18 @@ class ReferencesData {
|
|||
*/
|
||||
private $refGroups;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $inEmbeddedContent;
|
||||
|
||||
/**
|
||||
* ReferencesData constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->index = 0;
|
||||
$this->refGroups = [];
|
||||
$this->inEmbeddedContent = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +78,9 @@ class ReferencesData {
|
|||
$c = $extApi->getContentDOM( $ref->contentId )->firstChild;
|
||||
$ref->cachedHtml = $extApi->domToHtml( $c, true, false );
|
||||
}
|
||||
if ( !$this->inEmbeddedContent ) {
|
||||
$ref->nodes[] = $linkBack;
|
||||
}
|
||||
} else {
|
||||
// The ids produced Cite.php have some particulars:
|
||||
// Simple refs get 'cite_ref-' + index
|
||||
|
@ -107,9 +115,11 @@ class ReferencesData {
|
|||
$group->refs[] = $ref;
|
||||
if ( $hasRefName ) {
|
||||
$group->indexByName[$refName] = $ref;
|
||||
if ( !$this->inEmbeddedContent ) {
|
||||
$ref->nodes[] = $linkBack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$skipLinkback ) {
|
||||
$ref->linkbacks[] = $ref->key . '-' . count( $ref->linkbacks );
|
||||
|
|
Loading…
Reference in a new issue