Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
62.22% |
56 / 90 |
|
14.29% |
1 / 7 |
CRAP | |
0.00% |
0 / 1 |
PageRestHelperFactory | |
62.22% |
56 / 90 |
|
14.29% |
1 / 7 |
22.11 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
newRevisionContentHelper | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
newPageContentHelper | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
newHtmlOutputRendererHelper | |
80.77% |
21 / 26 |
|
0.00% |
0 / 1 |
4.11 | |||
newHtmlMessageOutputHelper | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
newHtmlInputTransformHelper | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
3.00 | |||
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\ChangeTags\ChangeTagsStore; |
7 | use MediaWiki\Config\ServiceOptions; |
8 | use MediaWiki\Content\IContentHandlerFactory; |
9 | use MediaWiki\Edit\ParsoidOutputStash; |
10 | use MediaWiki\Languages\LanguageConverterFactory; |
11 | use MediaWiki\Languages\LanguageFactory; |
12 | use MediaWiki\Page\PageIdentity; |
13 | use MediaWiki\Page\PageLookup; |
14 | use MediaWiki\Page\ParserOutputAccess; |
15 | use MediaWiki\Page\RedirectStore; |
16 | use MediaWiki\Parser\ParserOptions; |
17 | use MediaWiki\Parser\Parsoid\Config\SiteConfig as ParsoidSiteConfig; |
18 | use MediaWiki\Parser\Parsoid\HtmlTransformFactory; |
19 | use MediaWiki\Permissions\Authority; |
20 | use MediaWiki\Rest\RequestInterface; |
21 | use MediaWiki\Rest\ResponseFactory; |
22 | use MediaWiki\Rest\Router; |
23 | use MediaWiki\Revision\RevisionLookup; |
24 | use MediaWiki\Revision\RevisionRecord; |
25 | use MediaWiki\Revision\RevisionRenderer; |
26 | use MediaWiki\Title\TitleFactory; |
27 | use MediaWiki\Title\TitleFormatter; |
28 | use Wikimedia\Bcp47Code\Bcp47Code; |
29 | use Wikimedia\Rdbms\IConnectionProvider; |
30 | use Wikimedia\Stats\StatsFactory; |
31 | |
32 | /** |
33 | * @since 1.40 Factory for helper objects designed for sharing logic between REST handlers that deal with page content. |
34 | * @unstable during Parsoid migration |
35 | */ |
36 | class PageRestHelperFactory { |
37 | |
38 | /** |
39 | * @internal |
40 | */ |
41 | public const CONSTRUCTOR_OPTIONS = PageContentHelper::CONSTRUCTOR_OPTIONS; |
42 | |
43 | private ServiceOptions $options; |
44 | private RevisionLookup $revisionLookup; |
45 | private RevisionRenderer $revisionRenderer; |
46 | private TitleFormatter $titleFormatter; |
47 | private PageLookup $pageLookup; |
48 | private ParsoidOutputStash $parsoidOutputStash; |
49 | private StatsdDataFactoryInterface $stats; |
50 | private ParserOutputAccess $parserOutputAccess; |
51 | private ParsoidSiteConfig $parsoidSiteConfig; |
52 | private HtmlTransformFactory $htmlTransformFactory; |
53 | private IContentHandlerFactory $contentHandlerFactory; |
54 | private LanguageFactory $languageFactory; |
55 | private RedirectStore $redirectStore; |
56 | private LanguageConverterFactory $languageConverterFactory; |
57 | private TitleFactory $titleFactory; |
58 | private IConnectionProvider $dbProvider; |
59 | private ChangeTagsStore $changeTagStore; |
60 | private StatsFactory $statsFactory; |
61 | |
62 | public function __construct( |
63 | ServiceOptions $options, |
64 | RevisionLookup $revisionLookup, |
65 | RevisionRenderer $revisionRenderer, |
66 | TitleFormatter $titleFormatter, |
67 | PageLookup $pageLookup, |
68 | ParsoidOutputStash $parsoidOutputStash, |
69 | StatsdDataFactoryInterface $statsDataFactory, |
70 | ParserOutputAccess $parserOutputAccess, |
71 | ParsoidSiteConfig $parsoidSiteConfig, |
72 | HtmlTransformFactory $htmlTransformFactory, |
73 | IContentHandlerFactory $contentHandlerFactory, |
74 | LanguageFactory $languageFactory, |
75 | RedirectStore $redirectStore, |
76 | LanguageConverterFactory $languageConverterFactory, |
77 | TitleFactory $titleFactory, |
78 | IConnectionProvider $dbProvider, |
79 | ChangeTagsStore $changeTagStore, |
80 | StatsFactory $statsFactory |
81 | ) { |
82 | $this->options = $options; |
83 | $this->revisionLookup = $revisionLookup; |
84 | $this->revisionRenderer = $revisionRenderer; |
85 | $this->titleFormatter = $titleFormatter; |
86 | $this->pageLookup = $pageLookup; |
87 | $this->parsoidOutputStash = $parsoidOutputStash; |
88 | $this->stats = $statsDataFactory; |
89 | $this->parserOutputAccess = $parserOutputAccess; |
90 | $this->parsoidSiteConfig = $parsoidSiteConfig; |
91 | $this->htmlTransformFactory = $htmlTransformFactory; |
92 | $this->contentHandlerFactory = $contentHandlerFactory; |
93 | $this->languageFactory = $languageFactory; |
94 | $this->redirectStore = $redirectStore; |
95 | $this->languageConverterFactory = $languageConverterFactory; |
96 | $this->statsFactory = $statsFactory; |
97 | $this->titleFactory = $titleFactory; |
98 | $this->dbProvider = $dbProvider; |
99 | $this->changeTagStore = $changeTagStore; |
100 | } |
101 | |
102 | public function newRevisionContentHelper(): RevisionContentHelper { |
103 | return new RevisionContentHelper( |
104 | $this->options, |
105 | $this->revisionLookup, |
106 | $this->titleFormatter, |
107 | $this->pageLookup, |
108 | $this->titleFactory, |
109 | $this->dbProvider, |
110 | $this->changeTagStore |
111 | ); |
112 | } |
113 | |
114 | public function newPageContentHelper(): PageContentHelper { |
115 | return new PageContentHelper( |
116 | $this->options, |
117 | $this->revisionLookup, |
118 | $this->titleFormatter, |
119 | $this->pageLookup, |
120 | $this->titleFactory, |
121 | $this->dbProvider, |
122 | $this->changeTagStore |
123 | ); |
124 | } |
125 | |
126 | /** |
127 | * Should we ignore page id mismatches between page and revision objects |
128 | * in HTML/pagebundle requests? Mismatches arise because of page moves. |
129 | * This is recommended only for handling calls to internal APIs. |
130 | * @note Since 1.43, passing 'null' for $page has been deprecated. |
131 | * @note Since 1.43, passing 'null' for $authority has been deprecated. |
132 | * @note Since 1.43, passing $lenientRevHandling as the first parameter |
133 | * has been deprecated. |
134 | * @param bool|PageIdentity|null $page |
135 | * If `false`, this argument is used as the value for $lenientRevHandling, |
136 | * for backward-compatibility. |
137 | * @param array $parameters |
138 | * @param ?Authority $authority |
139 | * @param int|RevisionRecord|null $revision |
140 | * @param bool $lenientRevHandling |
141 | * @param ParserOptions|null $parserOptions |
142 | * @return HtmlOutputRendererHelper |
143 | */ |
144 | public function newHtmlOutputRendererHelper( |
145 | $page = null, |
146 | array $parameters = [], |
147 | ?Authority $authority = null, |
148 | $revision = null, |
149 | bool $lenientRevHandling = false, |
150 | ?ParserOptions $parserOptions = null |
151 | ): HtmlOutputRendererHelper { |
152 | if ( is_bool( $page ) ) { |
153 | // Backward compatibility w/ pre-1.43 (deprecated) |
154 | $lenientRevHandling = $page; |
155 | $page = null; |
156 | wfDeprecated( __METHOD__ . ' with boolean first parameter', '1.43' ); |
157 | } |
158 | if ( $page === null ) { |
159 | wfDeprecated( __METHOD__ . ' with null $page', '1.43' ); |
160 | } |
161 | if ( $authority === null ) { |
162 | wfDeprecated( __METHOD__ . ' with null $authority', '1.43' ); |
163 | } |
164 | return new HtmlOutputRendererHelper( |
165 | $this->parsoidOutputStash, |
166 | $this->statsFactory, |
167 | $this->parserOutputAccess, |
168 | $this->pageLookup, |
169 | $this->revisionLookup, |
170 | $this->revisionRenderer, |
171 | $this->parsoidSiteConfig, |
172 | $this->htmlTransformFactory, |
173 | $this->contentHandlerFactory, |
174 | $this->languageFactory, |
175 | $page, |
176 | $parameters, |
177 | $authority, |
178 | $revision, |
179 | $lenientRevHandling, |
180 | $parserOptions |
181 | ); |
182 | } |
183 | |
184 | /** |
185 | * @note Since 1.43, passing a null $page is deprecated. |
186 | */ |
187 | public function newHtmlMessageOutputHelper( ?PageIdentity $page = null ): HtmlMessageOutputHelper { |
188 | if ( $page === null ) { |
189 | wfDeprecated( __METHOD__ . ' with null $page', '1.43' ); |
190 | } |
191 | return new HtmlMessageOutputHelper( $page ); |
192 | } |
193 | |
194 | public function newHtmlInputTransformHelper( |
195 | $envOptions = [], |
196 | ?PageIdentity $page = null, |
197 | $body = null, |
198 | array $parameters = [], |
199 | ?RevisionRecord $originalRevision = null, |
200 | ?Bcp47Code $pageLanguage = null |
201 | ): HtmlInputTransformHelper { |
202 | if ( $page === null || $body === null ) { |
203 | wfDeprecated( __METHOD__ . ' without $page or $body' ); |
204 | } |
205 | return new HtmlInputTransformHelper( |
206 | $this->statsFactory, |
207 | $this->htmlTransformFactory, |
208 | $this->parsoidOutputStash, |
209 | $this->parserOutputAccess, |
210 | $this->pageLookup, |
211 | $this->revisionLookup, |
212 | $envOptions, |
213 | $page, |
214 | $body ?? '', |
215 | $parameters, |
216 | $originalRevision, |
217 | $pageLanguage |
218 | ); |
219 | } |
220 | |
221 | /** |
222 | * @since 1.41 |
223 | */ |
224 | public function newPageRedirectHelper( |
225 | ResponseFactory $responseFactory, |
226 | Router $router, |
227 | string $route, |
228 | RequestInterface $request |
229 | ): PageRedirectHelper { |
230 | return new PageRedirectHelper( |
231 | $this->redirectStore, |
232 | $this->titleFormatter, |
233 | $responseFactory, |
234 | $router, |
235 | $route, |
236 | $request, |
237 | $this->languageConverterFactory |
238 | ); |
239 | } |
240 | |
241 | } |