Debian Codegraph @

includes/content/Transform/ContentTransformer.php

raw symbols SCIP
1 <?php
2 namespace MediaWiki\Content\Transform;
3
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;
9
10 /**
11 * A service to transform content.
12 *
13 * @since 1.37
14 */
15 class ContentTransformer {
16 /** @var IContentHandlerFactory */
17 private $contentHandlerFactory;
18
19 /**
20 * @param IContentHandlerFactory $contentHandlerFactory
21 */
22 public function __construct( IContentHandlerFactory $contentHandlerFactory ) {
23 $this->contentHandlerFactory = $contentHandlerFactory;
24 }
25
26 /**
27 * Returns a Content object with pre-save transformations applied (or $content
28 * if no transformations apply).
29 *
30 * @param Content $content
31 * @param PageReference $page
32 * @param UserIdentity $user
33 * @param ParserOptions $parserOptions
34 *
35 * @return Content
36 */
37 public function preSaveTransform(
38 Content $content,
39 PageReference $page,
40 UserIdentity $user,
41 ParserOptions $parserOptions
42 ): Content {
43 $contentHandler = $this->contentHandlerFactory->getContentHandler( $content->getModel() );
44 $pstParams = new PreSaveTransformParamsValue( $page, $user, $parserOptions );
45
46 return $contentHandler->preSaveTransform( $content, $pstParams );
47 }
48
49 /**
50 * Returns a Content object with preload transformations applied (or $content
51 * if no transformations apply).
52 *
53 * @param Content $content
54 * @param PageReference $page
55 * @param ParserOptions $parserOptions
56 * @param array $params
57 *
58 * @return Content
59 */
60 public function preloadTransform(
61 Content $content,
62 PageReference $page,
63 ParserOptions $parserOptions,
64 array $params = []
65 ): Content {
66 $contentHandler = $this->contentHandlerFactory->getContentHandler( $content->getModel() );
67 $pltParams = new PreloadTransformParamsValue( $page, $parserOptions, $params );
68
69 return $contentHandler->preloadTransform( $content, $pltParams );
70 }
71 }