mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Move content differ check up higher
This will be helpful in a subsequent patch where we make use of that data while processing refs in refs. Content differing implies that we'll be embedding it for roundtripping, rather than putting in the dom. Change-Id: I7bd1d4c503fc58f862960bec82ca514fc29d7eff
This commit is contained in:
parent
50dfe518cc
commit
d0e1637d22
|
@ -197,6 +197,9 @@ class References extends ExtensionTagHandler {
|
|||
$c->appendChild( $span );
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$contentDiffers = false;
|
||||
|
||||
if ( $hasRefName ) {
|
||||
if ( $hasFollow ) {
|
||||
// Presumably, "name" has higher precedence
|
||||
|
@ -204,10 +207,19 @@ class References extends ExtensionTagHandler {
|
|||
}
|
||||
if ( isset( $group->indexByName[$refName] ) ) {
|
||||
$ref = $group->indexByName[$refName];
|
||||
if ( $ref->contentId && !$ref->hasMultiples ) {
|
||||
$ref->hasMultiples = true;
|
||||
$firstC = $extApi->getContentDOM( $ref->contentId )->firstChild;
|
||||
$ref->cachedHtml = $extApi->domToHtml( $firstC, true, false );
|
||||
// If there are multiple <ref>s with the same name, but different content,
|
||||
// the content of the first <ref> shows up in the <references> section.
|
||||
// in order to ensure lossless RT-ing for later <refs>, we have to record
|
||||
// HTML inline for all of them.
|
||||
if ( $ref->contentId ) {
|
||||
if ( $ref->cachedHtml === null ) {
|
||||
$firstC = $extApi->getContentDOM( $ref->contentId )->firstChild;
|
||||
$ref->cachedHtml = $extApi->domToHtml( $firstC, true, false );
|
||||
}
|
||||
// FIXME: Strip the mw:Cite/Follow wrappers
|
||||
// See the test, "Forward-referenced ref with magical follow edge case"
|
||||
$html = $extApi->domToHtml( $c, true, false );
|
||||
$contentDiffers = ( $html !== $ref->cachedHtml );
|
||||
}
|
||||
} else {
|
||||
if ( $refsData->inReferencesContent() ) {
|
||||
|
@ -304,28 +316,18 @@ class References extends ExtensionTagHandler {
|
|||
$refDmw->body = (object)[ 'html' => $refDmw->body->extsrc ?? '' ];
|
||||
}
|
||||
} else {
|
||||
// If there are multiple <ref>s with the same name, but different content,
|
||||
// the content of the first <ref> shows up in the <references> section.
|
||||
// in order to ensure lossless RT-ing for later <refs>, we have to record
|
||||
// HTML inline for all of them.
|
||||
$html = '';
|
||||
$contentDiffers = false;
|
||||
if ( $ref->hasMultiples && !$validFollow ) {
|
||||
// FIXME: Strip the mw:Cite/Follow wrappers
|
||||
// See the test, "Forward-referenced ref with magical follow edge case"
|
||||
$html = $extApi->domToHtml( $c, true, true );
|
||||
if ( $ref->contentId && !$validFollow ) {
|
||||
// Empty the <sup> since we've serialized its children and
|
||||
// removing it below asserts everything has been migrated out
|
||||
DOMCompat::replaceChildren( $c );
|
||||
$contentDiffers = $html !== $ref->cachedHtml;
|
||||
if ( $contentDiffers ) {
|
||||
// TODO: Since this error is being placed on the ref, the
|
||||
// key should arguably be "cite_error_ref_duplicate_key"
|
||||
$errs[] = [ 'key' => 'cite_error_references_duplicate_key',
|
||||
'params' => [ $refDmw->attrs->name ] ];
|
||||
}
|
||||
}
|
||||
if ( $contentDiffers ) {
|
||||
// TODO: Since this error is being placed on the ref, the
|
||||
// key should arguably be "cite_error_ref_duplicate_key"
|
||||
$errs[] = [
|
||||
'key' => 'cite_error_references_duplicate_key',
|
||||
'params' => [ $refDmw->attrs->name ]
|
||||
];
|
||||
$refDmw->body = (object)[ 'html' => $html ];
|
||||
} else {
|
||||
$refDmw->body = (object)[ 'id' => 'mw-reference-text-' . $ref->target ];
|
||||
|
|
|
@ -125,7 +125,15 @@ class ReferencesData {
|
|||
$this->index += 1;
|
||||
|
||||
$ref = (object)[
|
||||
// Pointer to the contents of the ref, accessible with the
|
||||
// $extApi->getContentDOM(), to be used when serializing the
|
||||
// references group. It gets set when extracting the ref from a
|
||||
// node and not $missingContent. Note that that might not
|
||||
// be the first one for named refs. Also, for named refs, it's
|
||||
// used to detect multiple conflicting definitions.
|
||||
'contentId' => null,
|
||||
// Just used for comparison when we have multiples
|
||||
'cachedHtml' => null,
|
||||
'dir' => '',
|
||||
'group' => $group->name,
|
||||
'groupIndex' => count( $group->refs ) + 1,
|
||||
|
@ -135,9 +143,6 @@ class ReferencesData {
|
|||
'linkbacks' => [],
|
||||
'name' => $refName,
|
||||
'target' => $noteId,
|
||||
'hasMultiples' => false,
|
||||
// Just used for comparison when we have multiples
|
||||
'cachedHtml' => '',
|
||||
'nodes' => [],
|
||||
'embeddedNodes' => [],
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue