MediaWiki  master
DifferenceEngineSlotDiffRenderer.php
Go to the documentation of this file.
1 <?php
24 
33 
36 
41  $this->differenceEngine = clone $differenceEngine;
42 
43  // Set state to loaded. This should not matter to any of the methods invoked by
44  // the adapter, but just in case a load does get triggered somehow, make sure it's a no-op.
45  $fakeContent = MediaWikiServices::getInstance()
46  ->getContentHandlerFactory()
47  ->getContentHandler( CONTENT_MODEL_WIKITEXT )
48  ->makeEmptyContent();
49  $this->differenceEngine->setContent( $fakeContent, $fakeContent );
50 
51  $this->differenceEngine->markAsSlotDiffRenderer();
52  }
53 
55  public function getDiff( Content $oldContent = null, Content $newContent = null ) {
56  $this->normalizeContents( $oldContent, $newContent );
57  // @phan-suppress-next-line PhanTypeMismatchArgumentNullable Null handled by normalizeContents
58  return $this->differenceEngine->generateContentDiffBody( $oldContent, $newContent );
59  }
60 
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 
77  public function getExtraCacheKeys() {
78  return $this->differenceEngine->getExtraCacheKeys();
79  }
80 
81 }
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:210
An IContextSource implementation which will inherit context from another source but allow individual ...
B/C adapter for turning a DifferenceEngine into a SlotDiffRenderer.
addModules(OutputPage $output)
Add modules needed for correct styling/behavior of the diff.Stability: stableto override
__construct(DifferenceEngine $differenceEngine)
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...
getExtraCacheKeys()
Return any extra keys to split the diff cache by.Stability: stableto override string[]
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.
MediaWikiServices is the service locator for the application scope of MediaWiki.
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:52
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().
Base interface for content objects.
Definition: Content.php:35