3 * Adapter for turning a DifferenceEngine into a SlotDiffRenderer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup DifferenceEngine
25 * B/C adapter for turning a DifferenceEngine into a SlotDiffRenderer.
26 * Before SlotDiffRenderer was introduced, getDiff() functionality was provided by DifferenceEngine
27 * subclasses. Convert such a subclass into a SlotDiffRenderer.
29 * @ingroup DifferenceEngine
31 class DifferenceEngineSlotDiffRenderer
extends SlotDiffRenderer
{
33 /** @var DifferenceEngine */
34 private $differenceEngine;
36 public function __construct( DifferenceEngine
$differenceEngine ) {
37 $this->differenceEngine
= clone $differenceEngine;
39 // Set state to loaded. This should not matter to any of the methods invoked by
40 // the adapter, but just in case a load does get triggered somehow, make sure it's a no-op.
41 $fakeContent = ContentHandler
::getForModelID( CONTENT_MODEL_WIKITEXT
)->makeEmptyContent();
42 $this->differenceEngine
->setContent( $fakeContent, $fakeContent );
44 $this->differenceEngine
->markAsSlotDiffRenderer();
48 public function getDiff( Content
$oldContent = null, Content
$newContent = null ) {
49 if ( !$oldContent && !$newContent ) {
50 throw new InvalidArgumentException( '$oldContent and $newContent cannot both be null' );
52 if ( !$oldContent ||
!$newContent ) {
53 $someContent = $newContent ?
: $oldContent;
54 $emptyContent = $someContent->getContentHandler()->makeEmptyContent();
55 $oldContent = $oldContent ?
: $emptyContent;
56 $newContent = $newContent ?
: $emptyContent;
58 return $this->differenceEngine
->generateContentDiffBody( $oldContent, $newContent );
61 public function addModules( OutputPage
$output ) {
63 if ( $output !== $this->differenceEngine
->getOutput() ) {
64 $oldContext = $this->differenceEngine
->getContext();
65 $newContext = new DerivativeContext( $oldContext );
66 $newContext->setOutput( $output );
67 $this->differenceEngine
->setContext( $newContext );
69 $this->differenceEngine
->showDiffStyle();
71 $this->differenceEngine
->setContext( $oldContext );
75 public function getExtraCacheKeys() {
76 return $this->differenceEngine
->getExtraCacheKeys();