Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractContentDifferenceEngine
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 generateContentDiffBody
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * WikiLambda AbstractContentDifferenceEngine
4 *
5 * @file
6 * @ingroup Extensions
7 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
8 * @license MIT
9 */
10
11namespace MediaWiki\Extension\WikiLambda\AbstractContent;
12
13use DifferenceEngine;
14use MediaWiki\Content\Content;
15use MediaWiki\Context\RequestContext;
16use TextSlotDiffRenderer;
17
18class AbstractContentDifferenceEngine extends DifferenceEngine {
19
20    /**
21     * @inheritDoc
22     */
23    public function generateContentDiffBody( Content $oldContent, Content $newContent ) {
24        if ( !( $oldContent instanceof AbstractWikiContent && $newContent instanceof AbstractWikiContent ) ) {
25            $this->getOutput()->showErrorPage( 'errorpagetitle', 'wikilambda-diff-incompatible' );
26            return '';
27        }
28        // For now, provide users with the raw JSON diff
29        $oldText = $oldContent->getText();
30        $newText = $newContent->getText();
31
32        $abstractContentHandler = $newContent->getContentHandler();
33        '@phan-var AbstractWikiContentHandler $abstractContentHandler';
34
35        $slotDiffRenderer = $abstractContentHandler
36            ->getSlotDiffRendererWithOptions( RequestContext::getMain() );
37        '@phan-var TextSlotDiffRenderer $slotDiffRenderer';
38
39        return $slotDiffRenderer->getTextDiff( $oldText, $newText );
40    }
41}