mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Implement diffHandler for Cite extension
Bug: T214651 Change-Id: I64585cd89135887e095e3ab17d10c3c7d82af1c9
This commit is contained in:
parent
0cc211d675
commit
2e4f69a492
|
@ -182,4 +182,64 @@ class Ref extends ExtensionTagHandler {
|
||||||
|
|
||||||
return $startTagSrc . $src . '</' . $dataMw->name . '>';
|
return $startTagSrc . $src . '</' . $dataMw->name . '>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @inheritDoc */
|
||||||
|
public function diffHandler(
|
||||||
|
ParsoidExtensionAPI $extApi, callable $domDiff, Element $origNode,
|
||||||
|
Element $editedNode
|
||||||
|
): bool {
|
||||||
|
$origDataMw = DOMDataUtils::getDataMw( $origNode );
|
||||||
|
$editedDataMw = DOMDataUtils::getDataMw( $editedNode );
|
||||||
|
|
||||||
|
if ( isset( $origDataMw->body->id ) && isset( $editedDataMw->body->id ) ) {
|
||||||
|
$origId = $origDataMw->body->id;
|
||||||
|
$editedId = $editedDataMw->body->id;
|
||||||
|
|
||||||
|
// So far, this is specified for Cite and relies on the "id"
|
||||||
|
// referring to an element in the top level dom, even though the
|
||||||
|
// <ref> itself may be in embedded content,
|
||||||
|
// https://www.mediawiki.org/wiki/Specs/HTML/Extensions/Cite#Ref_and_References
|
||||||
|
// FIXME: This doesn't work if the <references> section
|
||||||
|
// itself is in embedded content, since we aren't traversing
|
||||||
|
// in there.
|
||||||
|
$origHtml = DOMCompat::getElementById( $origNode->ownerDocument, $origId );
|
||||||
|
$editedHtml = DOMCompat::getElementById( $editedNode->ownerDocument, $editedId );
|
||||||
|
|
||||||
|
if ( $origHtml && $editedHtml ) {
|
||||||
|
return call_user_func( $domDiff, $origHtml, $editedHtml );
|
||||||
|
} else {
|
||||||
|
// Log error
|
||||||
|
if ( !$origHtml ) {
|
||||||
|
$extApi->log(
|
||||||
|
'error/domdiff/orig/ref',
|
||||||
|
"extension src id {$origId} points to non-existent element for:",
|
||||||
|
DOMCompat::getOuterHTML( $origNode )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( !$editedHtml ) {
|
||||||
|
$extApi->log(
|
||||||
|
'error/domdiff/edited/ref',
|
||||||
|
"extension src id {$editedId} points to non-existent element for:",
|
||||||
|
DOMCompat::getOuterHTML( $editedNode )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ( isset( $origDataMw->body->html ) && isset( $editedDataMw->body->html ) ) {
|
||||||
|
$origFragment = $extApi->htmlToDom(
|
||||||
|
$origDataMw->body->html, $origNode->ownerDocument,
|
||||||
|
[ 'markNew' => true ]
|
||||||
|
);
|
||||||
|
$editedFragment = $extApi->htmlToDom(
|
||||||
|
$editedDataMw->body->html, $editedNode->ownerDocument,
|
||||||
|
[ 'markNew' => true ]
|
||||||
|
);
|
||||||
|
return call_user_func( $domDiff, $origFragment, $editedFragment );
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Similar to DOMDiff::subtreeDiffers, maybe $editNode should
|
||||||
|
// be marked as inserted to avoid losing any edits, at the cost of
|
||||||
|
// more normalization
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -792,4 +792,31 @@ class References extends ExtensionTagHandler {
|
||||||
// Ignoring for now.
|
// Ignoring for now.
|
||||||
return $refs->nextSibling;
|
return $refs->nextSibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @inheritDoc */
|
||||||
|
public function diffHandler(
|
||||||
|
ParsoidExtensionAPI $extApi, callable $domDiff, Element $origNode,
|
||||||
|
Element $editedNode
|
||||||
|
): bool {
|
||||||
|
$origDataMw = DOMDataUtils::getDataMw( $origNode );
|
||||||
|
$editedDataMw = DOMDataUtils::getDataMw( $editedNode );
|
||||||
|
|
||||||
|
if ( isset( $origDataMw->body->html ) && isset( $editedDataMw->body->html ) ) {
|
||||||
|
$origFragment = $extApi->htmlToDom(
|
||||||
|
$origDataMw->body->html, $origNode->ownerDocument,
|
||||||
|
[ 'markNew' => true ]
|
||||||
|
);
|
||||||
|
$editedFragment = $extApi->htmlToDom(
|
||||||
|
$editedDataMw->body->html, $editedNode->ownerDocument,
|
||||||
|
[ 'markNew' => true ]
|
||||||
|
);
|
||||||
|
return call_user_func( $domDiff, $origFragment, $editedFragment );
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Similar to DOMDiff::subtreeDiffers, maybe $editNode should
|
||||||
|
// be marked as inserted to avoid losing any edits, at the cost of
|
||||||
|
// more normalization
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue