Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
44.00% |
22 / 50 |
|
42.86% |
3 / 7 |
CRAP | |
0.00% |
0 / 1 |
PageRestHelperFactory | |
44.00% |
22 / 50 |
|
42.86% |
3 / 7 |
15.61 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
newRevisionContentHelper | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
newPageContentHelper | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
newHtmlOutputRendererHelper | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
newHtmlMessageOutputHelper | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
newHtmlInputTransformHelper | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
newPageRedirectHelper | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Rest\Handler\Helper; |
4 | |
5 | use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; |
6 | use MediaWiki\Config\ServiceOptions; |
7 | use MediaWiki\Content\IContentHandlerFactory; |
8 | use MediaWiki\Edit\ParsoidOutputStash; |
9 | use MediaWiki\Languages\LanguageConverterFactory; |
10 | use MediaWiki\Languages\LanguageFactory; |
11 | use MediaWiki\Page\PageLookup; |
12 | use MediaWiki\Page\RedirectStore; |
13 | use MediaWiki\Parser\Parsoid\HtmlTransformFactory; |
14 | use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; |
15 | use MediaWiki\Rest\RequestInterface; |
16 | use MediaWiki\Rest\ResponseFactory; |
17 | use MediaWiki\Rest\Router; |
18 | use MediaWiki\Revision\RevisionLookup; |
19 | use MediaWiki\Title\TitleFormatter; |
20 | |
21 | /** |
22 | * @since 1.40 Factory for helper objects designed for sharing logic between REST handlers that deal with page content. |
23 | */ |
24 | class PageRestHelperFactory { |
25 | |
26 | /** |
27 | * @internal |
28 | */ |
29 | public const CONSTRUCTOR_OPTIONS = PageContentHelper::CONSTRUCTOR_OPTIONS; |
30 | |
31 | private ServiceOptions $options; |
32 | private RevisionLookup $revisionLookup; |
33 | private TitleFormatter $titleFormatter; |
34 | private PageLookup $pageLookup; |
35 | private ParsoidOutputStash $parsoidOutputStash; |
36 | private StatsdDataFactoryInterface $stats; |
37 | private ParsoidOutputAccess $parsoidOutputAccess; |
38 | private HtmlTransformFactory $htmlTransformFactory; |
39 | private IContentHandlerFactory $contentHandlerFactory; |
40 | private LanguageFactory $languageFactory; |
41 | private RedirectStore $redirectStore; |
42 | private LanguageConverterFactory $languageConverterFactory; |
43 | |
44 | /** |
45 | * @param ServiceOptions $options |
46 | * @param RevisionLookup $revisionLookup |
47 | * @param TitleFormatter $titleFormatter |
48 | * @param PageLookup $pageLookup |
49 | * @param ParsoidOutputStash $parsoidOutputStash |
50 | * @param StatsdDataFactoryInterface $statsDataFactory |
51 | * @param ParsoidOutputAccess $parsoidOutputAccess |
52 | * @param HtmlTransformFactory $htmlTransformFactory |
53 | * @param IContentHandlerFactory $contentHandlerFactory |
54 | * @param LanguageFactory $languageFactory |
55 | * @param RedirectStore $redirectStore |
56 | * @param LanguageConverterFactory $languageConverterFactory |
57 | */ |
58 | public function __construct( |
59 | ServiceOptions $options, |
60 | RevisionLookup $revisionLookup, |
61 | TitleFormatter $titleFormatter, |
62 | PageLookup $pageLookup, |
63 | ParsoidOutputStash $parsoidOutputStash, |
64 | StatsdDataFactoryInterface $statsDataFactory, |
65 | ParsoidOutputAccess $parsoidOutputAccess, |
66 | HtmlTransformFactory $htmlTransformFactory, |
67 | IContentHandlerFactory $contentHandlerFactory, |
68 | LanguageFactory $languageFactory, |
69 | RedirectStore $redirectStore, |
70 | LanguageConverterFactory $languageConverterFactory |
71 | ) { |
72 | $this->options = $options; |
73 | $this->revisionLookup = $revisionLookup; |
74 | $this->titleFormatter = $titleFormatter; |
75 | $this->pageLookup = $pageLookup; |
76 | $this->parsoidOutputStash = $parsoidOutputStash; |
77 | $this->stats = $statsDataFactory; |
78 | $this->parsoidOutputAccess = $parsoidOutputAccess; |
79 | $this->htmlTransformFactory = $htmlTransformFactory; |
80 | $this->contentHandlerFactory = $contentHandlerFactory; |
81 | $this->languageFactory = $languageFactory; |
82 | $this->redirectStore = $redirectStore; |
83 | $this->languageConverterFactory = $languageConverterFactory; |
84 | } |
85 | |
86 | public function newRevisionContentHelper(): RevisionContentHelper { |
87 | return new RevisionContentHelper( |
88 | $this->options, |
89 | $this->revisionLookup, |
90 | $this->titleFormatter, |
91 | $this->pageLookup |
92 | ); |
93 | } |
94 | |
95 | public function newPageContentHelper(): PageContentHelper { |
96 | return new PageContentHelper( |
97 | $this->options, |
98 | $this->revisionLookup, |
99 | $this->titleFormatter, |
100 | $this->pageLookup |
101 | ); |
102 | } |
103 | |
104 | /** |
105 | * Should we ignore page id mismatches between page and revision objects |
106 | * in HTML/pagebundle requests? Mismatches arise because of page moves. |
107 | * This is recommended only for handling calls to internal APIs. |
108 | */ |
109 | public function newHtmlOutputRendererHelper( |
110 | bool $lenientRevHandling = false |
111 | ): HtmlOutputRendererHelper { |
112 | return new HtmlOutputRendererHelper( |
113 | $this->parsoidOutputStash, |
114 | $this->stats, |
115 | $this->parsoidOutputAccess, |
116 | $this->htmlTransformFactory, |
117 | $this->contentHandlerFactory, |
118 | $this->languageFactory, |
119 | $lenientRevHandling |
120 | ); |
121 | } |
122 | |
123 | public function newHtmlMessageOutputHelper(): HtmlMessageOutputHelper { |
124 | return new HtmlMessageOutputHelper(); |
125 | } |
126 | |
127 | public function newHtmlInputTransformHelper( $envOptions = [] ): HtmlInputTransformHelper { |
128 | return new HtmlInputTransformHelper( |
129 | $this->stats, |
130 | $this->htmlTransformFactory, |
131 | $this->parsoidOutputStash, |
132 | $this->parsoidOutputAccess, |
133 | $envOptions |
134 | ); |
135 | } |
136 | |
137 | /** |
138 | * @since 1.41 |
139 | */ |
140 | public function newPageRedirectHelper( |
141 | ResponseFactory $responseFactory, |
142 | Router $router, |
143 | string $route, |
144 | RequestInterface $request |
145 | ): PageRedirectHelper { |
146 | return new PageRedirectHelper( |
147 | $this->redirectStore, |
148 | $this->titleFormatter, |
149 | $responseFactory, |
150 | $router, |
151 | $route, |
152 | $request, |
153 | $this->languageConverterFactory |
154 | ); |
155 | } |
156 | |
157 | } |