Debian Codegraph @

includes/diff/DifferenceEngineSlotDiffRenderer.php

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