[MCR] Render multi-slot diffs
authorGergő Tisza <tgr.huwiki@gmail.com>
Wed, 11 Jul 2018 09:24:07 +0000 (11:24 +0200)
committerGergő Tisza <tgr.huwiki@gmail.com>
Mon, 20 Aug 2018 13:39:12 +0000 (15:39 +0200)
commitd31580eeb0e9a88f46439301e27db273b7c63a7e
tree197f3dc98ba8f60db3ec34e572ee0c35774406d1
parent47b5d95f12c9288dbeabaae46dd8a369b5797f5c
[MCR] Render multi-slot diffs

Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.

This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.

A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.

Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.

Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
15 files changed:
RELEASE-NOTES-1.32
autoload.php
docs/hooks.txt
includes/content/ContentHandler.php
includes/diff/DifferenceEngine.php
includes/diff/DifferenceEngineSlotDiffRenderer.php [new file with mode: 0644]
includes/diff/SlotDiffRenderer.php [new file with mode: 0644]
includes/diff/TextSlotDiffRenderer.php [new file with mode: 0644]
resources/src/mediawiki.diff.styles/diff.css
tests/common/TestsAutoLoader.php
tests/phpunit/includes/content/ContentHandlerTest.php
tests/phpunit/includes/diff/CustomDifferenceEngine.php [new file with mode: 0644]
tests/phpunit/includes/diff/DifferenceEngineSlotDiffRendererTest.php [new file with mode: 0644]
tests/phpunit/includes/diff/DifferenceEngineTest.php
tests/phpunit/includes/diff/TextSlotDiffRendererTest.php [new file with mode: 0644]