From 512806564d5f9a5196583c85834c82c367bd8537 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 21 Jun 2023 11:05:25 +1000 Subject: Do not generate diffs for slots with identical content When the old and new revisions have identical content in a given slot, do not include the relevant SlotDiffRenderer in the return value of DifferenceEngine::getSlotDiffRenderers(), so that the relevant table prefixes and modules will be omitted. Also: * In TextSlotDiffRenderer::getTextDiff(), return an empty string when the inputs are equal, instead of invoking the diff engine. Previously, the inline format would produce a element in this case, causing the diff-empty message to be omitted. * Clarify the doc comment up the stack, indicating SlotDiffRenderer may return zero tags, it doesn't have to be one or more. * Fix the documented return type of getSlotContents() so that @var is not needed in the caller. * Don't convert the return value of SlotDiffRenderer::getDiff() to boolean. It's always a string so compare it to the empty string. Note that the cache key for inline empty diffs will change, because TextSlotDiffRenderer::getExtraCacheKeys() is not called anymore for empty diffs. Bug: T338670 Change-Id: I0774ba0b159ac43ec214403cf2d06740f6d067cd --- includes/diff/TextSlotDiffRenderer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'includes/diff/TextSlotDiffRenderer.php') diff --git a/includes/diff/TextSlotDiffRenderer.php b/includes/diff/TextSlotDiffRenderer.php index bc526956e5b6..5f0bfed882fa 100644 --- a/includes/diff/TextSlotDiffRenderer.php +++ b/includes/diff/TextSlotDiffRenderer.php @@ -208,7 +208,7 @@ class TextSlotDiffRenderer extends SlotDiffRenderer { * Diff the text representations of two content objects (or just two pieces of text in general). * @param string $oldText * @param string $newText - * @return string HTML, one or more tags. + * @return string HTML. One or more tags, or an empty string if the inputs are identical. */ public function getTextDiff( string $oldText, string $newText ) { $diff = function () use ( $oldText, $newText ) { @@ -269,6 +269,10 @@ class TextSlotDiffRenderer extends SlotDiffRenderer { $oldText = str_replace( "\r\n", "\n", $oldText ); $newText = str_replace( "\r\n", "\n", $newText ); + if ( $oldText === $newText ) { + return ''; + } + // Better external diff engine, the 2 may some day be dropped // This one does the escaping and segmenting itself if ( $this->engine === self::ENGINE_WIKIDIFF2 ) { -- cgit v1.2.3