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
;
11 * A service to transform content.
15 class ContentTransformer
{
16 /** @var IContentHandlerFactory */
17 private $contentHandlerFactory;
19 public function __construct( IContentHandlerFactory
$contentHandlerFactory ) {
20 $this->contentHandlerFactory
= $contentHandlerFactory;
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
34 public function preSaveTransform(
38 ParserOptions
$parserOptions
40 $contentHandler = $this->contentHandlerFactory
->getContentHandler( $content->getModel() );
41 $pstParams = new PreSaveTransformParamsValue( $page, $user, $parserOptions );
43 return $contentHandler->preSaveTransform( $content, $pstParams );
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
57 public function preloadTransform(
60 ParserOptions
$parserOptions,
63 $contentHandler = $this->contentHandlerFactory
->getContentHandler( $content->getModel() );
64 $pltParams = new PreloadTransformParamsValue( $page, $parserOptions, $params );
66 return $contentHandler->preloadTransform( $content, $pltParams );