aboutsummaryrefslogtreecommitdiffstats
path: root/includes/content/Renderer/ContentRenderer.php
blob: 1f3c50251f3148a1a755a9f2514918dbcc9ab89a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace MediaWiki\Content\Renderer;

use Content;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\Page\PageReference;
use ParserOptions;
use ParserOutput;

/**
 * A service to render content.
 *
 * @since 1.38
 */
class ContentRenderer {
	/** @var IContentHandlerFactory */
	private $contentHandlerFactory;

	/**
	 * @param IContentHandlerFactory $contentHandlerFactory
	 */
	public function __construct( IContentHandlerFactory $contentHandlerFactory ) {
		$this->contentHandlerFactory = $contentHandlerFactory;
	}

	/**
	 * Returns a ParserOutput object containing information derived from this content.
	 *
	 * @param Content $content
	 * @param PageReference $page
	 * @param int|null $revId
	 * @param ParserOptions|null $parserOptions
	 * @param bool $generateHtml
	 *
	 * @return ParserOutput
	 */
	public function getParserOutput(
		Content $content,
		PageReference $page,
		?int $revId = null,
		?ParserOptions $parserOptions = null,
		bool $generateHtml = true
	): ParserOutput {
		$contentHandler = $this->contentHandlerFactory->getContentHandler( $content->getModel() );
		$cpoParams = new ContentParseParams( $page, $revId, $parserOptions, $generateHtml );

		return $contentHandler->getParserOutput( $content, $cpoParams );
	}
}