Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
TextRevisionSnippet | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
getHtml | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace FileImporter\Html; |
4 | |
5 | use FileImporter\Data\TextRevision; |
6 | use MediaWiki\MediaWikiServices; |
7 | use MediaWiki\Title\Title; |
8 | use ParserOptions; |
9 | |
10 | /** |
11 | * Html of parsed wikitext |
12 | * |
13 | * @license GPL-2.0-or-later |
14 | * @author Addshore |
15 | */ |
16 | class TextRevisionSnippet extends SpecialPageHtmlFragment { |
17 | |
18 | /** |
19 | * @param TextRevision $textRevision Latest test revision |
20 | * @param string|null $intendedWikitext This will override the text provided in the TextRevision |
21 | */ |
22 | public function getHtml( TextRevision $textRevision, ?string $intendedWikitext ): string { |
23 | $services = MediaWikiServices::getInstance(); |
24 | $title = Title::newFromText( $textRevision->getField( 'title' ), NS_FILE ); |
25 | |
26 | if ( $intendedWikitext === null ) { |
27 | $text = $textRevision->getContent(); |
28 | } else { |
29 | $text = $intendedWikitext; |
30 | } |
31 | |
32 | $content = $services->getContentHandlerFactory() |
33 | ->getContentHandler( $textRevision->getContentModel() ) |
34 | ->unserializeContent( |
35 | $text, |
36 | $textRevision->getContentFormat() |
37 | ); |
38 | |
39 | $parserOptions = new ParserOptions( $this->getUser(), $this->getLanguage() ); |
40 | $parserOptions->setIsPreview( true ); |
41 | |
42 | $contentTransformer = $services->getContentTransformer(); |
43 | $content = $contentTransformer->preSaveTransform( |
44 | $content, |
45 | $title, |
46 | $this->getUser(), |
47 | $parserOptions |
48 | ); |
49 | |
50 | $contentRenderer = $services->getContentRenderer(); |
51 | $parseResult = $contentRenderer->getParserOutput( |
52 | $content, |
53 | $title, |
54 | null, |
55 | $parserOptions |
56 | ); |
57 | |
58 | return $parseResult->getText( |
59 | [ 'enableSectionEditLinks' => false ] |
60 | ); |
61 | } |
62 | |
63 | } |