diff options
author | Tim Starling <tstarling@wikimedia.org> | 2023-06-21 11:05:25 +1000 |
---|---|---|
committer | Tim Starling <tstarling@wikimedia.org> | 2023-06-21 14:46:19 +1000 |
commit | 512806564d5f9a5196583c85834c82c367bd8537 (patch) | |
tree | b5ca83923750c32a6d6290928ca96d887a4b3524 /includes/diff/TextSlotDiffRenderer.php | |
parent | b7ce2923f91959fbfd8b5703983fe29e89db36c5 (diff) | |
download | mediawikicore-512806564d5f9a5196583c85834c82c367bd8537.tar.gz mediawikicore-512806564d5f9a5196583c85834c82c367bd8537.zip |
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 <tr> element in this case, causing
the diff-empty message to be omitted.
* Clarify the doc comment up the stack, indicating SlotDiffRenderer may
return zero <tr> 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
Diffstat (limited to 'includes/diff/TextSlotDiffRenderer.php')
-rw-r--r-- | includes/diff/TextSlotDiffRenderer.php | 6 |
1 files changed, 5 insertions, 1 deletions
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 <tr> tags. + * @return string HTML. One or more <tr> 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 ) { |