| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
use MediaWiki\Content\Content; |
| 24 |
use MediaWiki\Context\DerivativeContext; |
| 25 |
use MediaWiki\MediaWikiServices; |
| 26 |
use MediaWiki\Output\OutputPage; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class DifferenceEngineSlotDiffRenderer extends SlotDiffRenderer { |
| 36 |
|
| 37 |
|
| 38 |
private $differenceEngine; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function __construct( DifferenceEngine $differenceEngine ) { |
| 44 |
$this->differenceEngine = clone $differenceEngine; |
| 45 |
|
| 46 |
|
| 47 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 79 |
public function getExtraCacheKeys() { |
| 80 |
return $this->differenceEngine->getExtraCacheKeys(); |
| 81 |
} |
| 82 |
|
| 83 |
} |