Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ZObjectContentDifferenceEngine | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
generateContentDiffBody | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * WikiLambda ZObjectContentDifferenceEngine |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
8 | * @license MIT |
9 | */ |
10 | |
11 | namespace MediaWiki\Extension\WikiLambda\Diff; |
12 | |
13 | use DifferenceEngine; |
14 | use MediaWiki\Content\Content; |
15 | use MediaWiki\Context\RequestContext; |
16 | use MediaWiki\Extension\WikiLambda\ZObjectContent; |
17 | use MediaWiki\MediaWikiServices; |
18 | use TextSlotDiffRenderer; |
19 | |
20 | class ZObjectContentDifferenceEngine extends DifferenceEngine { |
21 | |
22 | /** |
23 | * @inheritDoc |
24 | */ |
25 | public function generateContentDiffBody( Content $oldContent, Content $newContent ) { |
26 | if ( !( $oldContent instanceof ZObjectContent && $newContent instanceof ZObjectContent ) ) { |
27 | $this->getOutput()->showErrorPage( 'errorpagetitle', 'wikilambda-diff-incompatible' ); |
28 | return ''; |
29 | } |
30 | |
31 | // TODO (T284473): Instead of this text diff, generate and return html body of the diff page |
32 | // $slotRenderer = new ZObjectSlotDiffRenderer(); |
33 | // $diffObject = $slotRenderer->getDiff( $oldContent, $newContent ); |
34 | |
35 | // HACK (T339348): For now, provide users with the raw JSON diff |
36 | $oldText = $oldContent->getText(); |
37 | $newText = $newContent->getText(); |
38 | /** @var TextSlotDiffRenderer $slotDiffRenderer */ |
39 | |
40 | // TODO (T362246): Dependency-inject (if we haven't replaced this by then) |
41 | $slotDiffRenderer = MediaWikiServices::getInstance() |
42 | ->getContentHandlerFactory() |
43 | ->getContentHandler( CONTENT_MODEL_TEXT ) |
44 | ->getSlotDiffRenderer( RequestContext::getMain() ); |
45 | '@phan-var TextSlotDiffRenderer $slotDiffRenderer'; |
46 | return $slotDiffRenderer->getTextDiff( $oldText, $newText ); |
47 | } |
48 | } |