MediaWiki master
DifferenceEngineSlotDiffRenderer.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Diff;
11
16
25
27 private $differenceEngine;
28
29 public function __construct( DifferenceEngine $differenceEngine ) {
30 $this->differenceEngine = clone $differenceEngine;
31
32 // Set state to loaded. This should not matter to any of the methods invoked by
33 // the adapter, but just in case a load does get triggered somehow, make sure it's a no-op.
34 $fakeContent = MediaWikiServices::getInstance()
35 ->getContentHandlerFactory()
36 ->getContentHandler( CONTENT_MODEL_WIKITEXT )
37 ->makeEmptyContent();
38 $this->differenceEngine->setContent( $fakeContent, $fakeContent );
39
40 $this->differenceEngine->markAsSlotDiffRenderer();
41 }
42
44 public function getDiff( ?Content $oldContent = null, ?Content $newContent = null ) {
45 $this->normalizeContents( $oldContent, $newContent );
46 return $this->differenceEngine->generateContentDiffBody( $oldContent, $newContent );
47 }
48
50 public function addModules( OutputPage $output ) {
51 $oldContext = null;
52 if ( $output !== $this->differenceEngine->getOutput() ) {
53 $oldContext = $this->differenceEngine->getContext();
54 $newContext = new DerivativeContext( $oldContext );
55 $newContext->setOutput( $output );
56 $this->differenceEngine->setContext( $newContext );
57 }
58 $this->differenceEngine->showDiffStyle();
59 if ( $oldContext ) {
60 $this->differenceEngine->setContext( $oldContext );
61 }
62 }
63
65 public function getExtraCacheKeys() {
66 return $this->differenceEngine->getExtraCacheKeys();
67 }
68
69}
70
72class_alias( DifferenceEngineSlotDiffRenderer::class, 'DifferenceEngineSlotDiffRenderer' );
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:235
An IContextSource implementation which will inherit context from another source but allow individual ...
B/C adapter for turning a DifferenceEngine into a SlotDiffRenderer.
getExtraCacheKeys()
Return any extra keys to split the diff cache by.to override string[]
getDiff(?Content $oldContent=null, ?Content $newContent=null)
Get a diff between two content objects.One of them might be null (meaning a slot was created or remov...
addModules(OutputPage $output)
Add modules needed for correct styling/behavior of the diff.to override
DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
setContent(Content $oldContent, Content $newContent)
Use specified text instead of loading from the database.
Renders a diff for a single slot (that is, a diff between two content objects).
normalizeContents(?Content &$oldContent=null, ?Content &$newContent=null, $allowedClasses=null)
Helper method to normalize the input of getDiff().
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
This is one of the Core classes and should be read at least once by any new developers.
Content objects represent page content, e.g.
Definition Content.php:28