Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
DifferenceEngineSlotDiffRenderer
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getDiff
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addModules
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 getExtraCacheKeys
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Adapter for turning a DifferenceEngine into a SlotDiffRenderer.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup DifferenceEngine
22 */
23use MediaWiki\MediaWikiServices;
24use MediaWiki\Output\OutputPage;
25
26/**
27 * B/C adapter for turning a DifferenceEngine into a SlotDiffRenderer.
28 * Before SlotDiffRenderer was introduced, getDiff() functionality was provided by DifferenceEngine
29 * subclasses. Convert such a subclass into a SlotDiffRenderer.
30 * @deprecated
31 * @ingroup DifferenceEngine
32 */
33class DifferenceEngineSlotDiffRenderer extends SlotDiffRenderer {
34
35    /** @var DifferenceEngine */
36    private $differenceEngine;
37
38    /**
39     * @param DifferenceEngine $differenceEngine
40     */
41    public function __construct( DifferenceEngine $differenceEngine ) {
42        $this->differenceEngine = clone $differenceEngine;
43
44        // Set state to loaded. This should not matter to any of the methods invoked by
45        // the adapter, but just in case a load does get triggered somehow, make sure it's a no-op.
46        $fakeContent = MediaWikiServices::getInstance()
47                ->getContentHandlerFactory()
48                ->getContentHandler( CONTENT_MODEL_WIKITEXT )
49                ->makeEmptyContent();
50        $this->differenceEngine->setContent( $fakeContent, $fakeContent );
51
52        $this->differenceEngine->markAsSlotDiffRenderer();
53    }
54
55    /** @inheritDoc */
56    public function getDiff( Content $oldContent = null, Content $newContent = null ) {
57        $this->normalizeContents( $oldContent, $newContent );
58        return $this->differenceEngine->generateContentDiffBody( $oldContent, $newContent );
59    }
60
61    /** @inheritDoc */
62    public function addModules( OutputPage $output ) {
63        $oldContext = null;
64        if ( $output !== $this->differenceEngine->getOutput() ) {
65            $oldContext = $this->differenceEngine->getContext();
66            $newContext = new DerivativeContext( $oldContext );
67            $newContext->setOutput( $output );
68            $this->differenceEngine->setContext( $newContext );
69        }
70        $this->differenceEngine->showDiffStyle();
71        if ( $oldContext ) {
72            $this->differenceEngine->setContext( $oldContext );
73        }
74    }
75
76    /** @inheritDoc */
77    public function getExtraCacheKeys() {
78        return $this->differenceEngine->getExtraCacheKeys();
79    }
80
81}