Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ContentTransformer | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
preSaveTransform | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
preloadTransform | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
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\User\UserIdentity; |
8 | use ParserOptions; |
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 | } |