diff options
author | Gergő Tisza <tgr.huwiki@gmail.com> | 2018-07-11 11:24:07 +0200 |
---|---|---|
committer | Gergő Tisza <tgr.huwiki@gmail.com> | 2018-08-20 15:39:12 +0200 |
commit | d31580eeb0e9a88f46439301e27db273b7c63a7e (patch) | |
tree | 197f3dc98ba8f60db3ec34e572ee0c35774406d1 /includes/diff/SlotDiffRenderer.php | |
parent | 47b5d95f12c9288dbeabaae46dd8a369b5797f5c (diff) | |
download | mediawikicore-d31580eeb0e9a88f46439301e27db273b7c63a7e.tar.gz mediawikicore-d31580eeb0e9a88f46439301e27db273b7c63a7e.zip |
[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
Diffstat (limited to 'includes/diff/SlotDiffRenderer.php')
-rw-r--r-- | includes/diff/SlotDiffRenderer.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/includes/diff/SlotDiffRenderer.php b/includes/diff/SlotDiffRenderer.php new file mode 100644 index 000000000000..f20b4169db64 --- /dev/null +++ b/includes/diff/SlotDiffRenderer.php @@ -0,0 +1,65 @@ +<?php +/** + * Renders a diff for a single slot. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup DifferenceEngine + */ + +/** + * Renders a diff for a single slot (that is, a diff between two content objects). + * + * Callers should obtain this class by invoking ContentHandler::getSlotDiffRendererClass + * on the content handler of the new content object (ie. the one shown on the right side + * of the diff), or of the old one if the new one does not exist. + * + * The default implementation just does a text diff on the native text representation. + * Content handler extensions can subclass this to provide a more appropriate diff method by + * overriding ContentHandler::getSlotDiffRendererClass. Other extensions that want to interfere + * with diff generation in some way can use the GetSlotDiffRenderer hook. + * + * @ingroup DifferenceEngine + */ +abstract class SlotDiffRenderer { + + /** + * Get a diff between two content objects. One of them might be null (meaning a slot was + * created or removed), but both cannot be. $newContent (or if it's null then $oldContent) + * must have the same content model that was used to obtain this diff renderer. + * @param Content|null $oldContent + * @param Content|null $newContent + * @return string + */ + abstract public function getDiff( Content $oldContent = null, Content $newContent = null ); + + /** + * Add modules needed for correct styling/behavior of the diff. + * @param OutputPage $output + */ + public function addModules( OutputPage $output ) { + } + + /** + * Return any extra keys to split the diff cache by. + * @return array + */ + public function getExtraCacheKeys() { + return []; + } + +} |