Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| TextRevisionSnippet | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace FileImporter\Html; |
| 4 | |
| 5 | use FileImporter\Data\TextRevision; |
| 6 | use MediaWiki\MediaWikiServices; |
| 7 | use MediaWiki\Parser\ParserOptions; |
| 8 | use MediaWiki\Title\Title; |
| 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 | $text = $intendedWikitext ?? $textRevision->getContent(); |
| 27 | |
| 28 | $content = $services->getContentHandlerFactory() |
| 29 | ->getContentHandler( $textRevision->getContentModel() ) |
| 30 | ->unserializeContent( |
| 31 | $text, |
| 32 | $textRevision->getContentFormat() |
| 33 | ); |
| 34 | |
| 35 | $parserOptions = new ParserOptions( $this->getUser(), $this->getLanguage() ); |
| 36 | $parserOptions->setIsPreview( true ); |
| 37 | |
| 38 | $contentTransformer = $services->getContentTransformer(); |
| 39 | $content = $contentTransformer->preSaveTransform( |
| 40 | $content, |
| 41 | $title, |
| 42 | $this->getUser(), |
| 43 | $parserOptions |
| 44 | ); |
| 45 | |
| 46 | $contentRenderer = $services->getContentRenderer(); |
| 47 | $parseResult = $contentRenderer->getParserOutput( |
| 48 | $content, |
| 49 | $title, |
| 50 | null, |
| 51 | $parserOptions |
| 52 | ); |
| 53 | |
| 54 | return $parseResult->runOutputPipeline( $parserOptions, |
| 55 | [ 'enableSectionEditLinks' => false ] |
| 56 | )->getContentHolderText(); |
| 57 | } |
| 58 | |
| 59 | } |