Merge "jquery.tablesorter: Silence an expected "sort-rowspan-error" warning"
[mediawiki.git] / includes / content / Transform / ContentTransformer.php
blobf18344e171ab77596bf39ce2f34c0da58e784351
1 <?php
2 namespace MediaWiki\Content\Transform;
4 use MediaWiki\Content\Content;
5 use MediaWiki\Content\IContentHandlerFactory;
6 use MediaWiki\Page\PageReference;
7 use MediaWiki\Parser\ParserOptions;
8 use MediaWiki\User\UserIdentity;
10 /**
11 * A service to transform content.
13 * @since 1.37
15 class ContentTransformer {
16 /** @var IContentHandlerFactory */
17 private $contentHandlerFactory;
19 public function __construct( IContentHandlerFactory $contentHandlerFactory ) {
20 $this->contentHandlerFactory = $contentHandlerFactory;
23 /**
24 * Returns a Content object with pre-save transformations applied (or $content
25 * if no transformations apply).
27 * @param Content $content
28 * @param PageReference $page
29 * @param UserIdentity $user
30 * @param ParserOptions $parserOptions
32 * @return Content
34 public function preSaveTransform(
35 Content $content,
36 PageReference $page,
37 UserIdentity $user,
38 ParserOptions $parserOptions
39 ): Content {
40 $contentHandler = $this->contentHandlerFactory->getContentHandler( $content->getModel() );
41 $pstParams = new PreSaveTransformParamsValue( $page, $user, $parserOptions );
43 return $contentHandler->preSaveTransform( $content, $pstParams );
46 /**
47 * Returns a Content object with preload transformations applied (or $content
48 * if no transformations apply).
50 * @param Content $content
51 * @param PageReference $page
52 * @param ParserOptions $parserOptions
53 * @param array $params
55 * @return Content
57 public function preloadTransform(
58 Content $content,
59 PageReference $page,
60 ParserOptions $parserOptions,
61 array $params = []
62 ): Content {
63 $contentHandler = $this->contentHandlerFactory->getContentHandler( $content->getModel() );
64 $pltParams = new PreloadTransformParamsValue( $page, $parserOptions, $params );
66 return $contentHandler->preloadTransform( $content, $pltParams );