From 47b5d95f12c9288dbeabaae46dd8a369b5797f5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Mon, 13 Aug 2018 18:53:59 +0200 Subject: [PATCH] Create DifferenceEngine before calling GetDifferenceEngine This way the hook is able to consider what kind of DifferenceEngine was created by default, or even wrap/decorate it. Change-Id: Ibb6b1b087a2dda445be2b5e8c7518c7d169b5192 --- docs/hooks.txt | 6 ++---- includes/content/ContentHandler.php | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 219c51f30e..9a634ad35d 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1670,15 +1670,13 @@ $title: Title object that we need to get a sortkey for &$sortkey: Sortkey to use. 'GetDifferenceEngine': Called when getting a new difference engine interface -object Return false for valid object in $differenceEngine or true for the -default difference engine. +object. Can be used to decorate or replace the default difference engine. $context: IContextSource context to be used for diff $old: Revision ID to show and diff with $new: Either a revision ID or one of the strings 'cur', 'prev' or 'next' $refreshCache: If set, refreshes the diff cache $unhide: If set, allow viewing deleted revs -&$differenceEngine: output parameter, difference engine object to be used for - diff +&$differenceEngine: The difference engine object to be used for the diff 'GetDoubleUnderscoreIDs': Modify the list of behavior switch (double underscore) magic words. Called by MagicWord. diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index 004e38a5ef..0a451b2fa3 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -614,6 +614,14 @@ abstract class ContentHandler { /** * Factory for creating an appropriate DifferenceEngine for this content model. * + * The DifferenceEngine subclass to use is selected in getDiffEngineClass(). The + * GetDifferenceEngine hook will receive the DifferenceEngine object and can replace or + * wrap it. + * (Note that in older versions of MediaWiki the hook documentation instructed extensions + * to return false from the hook; you should not rely on always being able to decorate + * the DifferenceEngine instance from the hook. If the owner of the content type wants to + * decorare the instance, overriding this method is a safer approach.) + * * @since 1.21 * * @param IContextSource $context Context to use, anything else will be ignored. @@ -629,15 +637,11 @@ abstract class ContentHandler { $rcid = 0, // FIXME: Deprecated, no longer used $refreshCache = false, $unhide = false ) { - // hook: get difference engine - $differenceEngine = null; - if ( !Hooks::run( 'GetDifferenceEngine', - [ $context, $old, $new, $refreshCache, $unhide, &$differenceEngine ] - ) ) { - return $differenceEngine; - } $diffEngineClass = $this->getDiffEngineClass(); - return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide ); + $differenceEngine = new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide ); + Hooks::run( 'GetDifferenceEngine', [ $context, $old, $new, $refreshCache, $unhide, + &$differenceEngine ] ); + return $differenceEngine; } /** -- 2.20.1