Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
DefaultOutputPipelineFactory | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
buildPipeline | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\OutputTransform; |
4 | |
5 | use Language; |
6 | use MediaWiki\Config\ServiceOptions; |
7 | use MediaWiki\HookContainer\HookContainer; |
8 | use MediaWiki\Languages\LanguageFactory; |
9 | use MediaWiki\MainConfigNames; |
10 | use MediaWiki\OutputTransform\Stages\AddRedirectHeader; |
11 | use MediaWiki\OutputTransform\Stages\AddWrapperDivClass; |
12 | use MediaWiki\OutputTransform\Stages\DeduplicateStyles; |
13 | use MediaWiki\OutputTransform\Stages\ExecutePostCacheTransformHooks; |
14 | use MediaWiki\OutputTransform\Stages\ExpandToAbsoluteUrls; |
15 | use MediaWiki\OutputTransform\Stages\ExtractBody; |
16 | use MediaWiki\OutputTransform\Stages\HandleParsoidSectionLinks; |
17 | use MediaWiki\OutputTransform\Stages\HandleSectionLinks; |
18 | use MediaWiki\OutputTransform\Stages\HandleTOCMarkers; |
19 | use MediaWiki\OutputTransform\Stages\HydrateHeaderPlaceholders; |
20 | use MediaWiki\OutputTransform\Stages\ParsoidLocalization; |
21 | use MediaWiki\OutputTransform\Stages\RenderDebugInfo; |
22 | use MediaWiki\Tidy\TidyDriverBase; |
23 | use MediaWiki\Title\TitleFactory; |
24 | use Psr\Log\LoggerInterface; |
25 | |
26 | /** |
27 | * This class contains the default output transformation pipeline factory for wikitext. It is a postprocessor for |
28 | * ParserOutput objects either directly resulting from a parse or fetched from ParserCache. |
29 | * @unstable |
30 | */ |
31 | class DefaultOutputPipelineFactory { |
32 | |
33 | /** @internal */ |
34 | public const CONSTRUCTOR_OPTIONS = [ |
35 | MainConfigNames::ParserEnableLegacyHeadingDOM, // For HandleSectionLinks |
36 | ]; |
37 | |
38 | private ServiceOptions $options; |
39 | private HookContainer $hookContainer; |
40 | private LoggerInterface $logger; |
41 | private TidyDriverBase $tidy; |
42 | private LanguageFactory $langFactory; |
43 | private Language $contentLang; |
44 | private TitleFactory $titleFactory; |
45 | |
46 | public function __construct( |
47 | ServiceOptions $options, |
48 | HookContainer $hookContainer, |
49 | TidyDriverBase $tidy, |
50 | LanguageFactory $langFactory, |
51 | Language $contentLang, |
52 | LoggerInterface $logger, |
53 | TitleFactory $titleFactory |
54 | ) { |
55 | $this->options = $options; |
56 | $this->hookContainer = $hookContainer; |
57 | $this->logger = $logger; |
58 | $this->langFactory = $langFactory; |
59 | $this->contentLang = $contentLang; |
60 | $this->tidy = $tidy; |
61 | $this->titleFactory = $titleFactory; |
62 | } |
63 | |
64 | /** |
65 | * Creates a pipeline of transformations to transform the content of the ParserOutput object from "parsed HTML" |
66 | * to "output HTML" and returns it. |
67 | * @internal |
68 | * @return OutputTransformPipeline |
69 | */ |
70 | public function buildPipeline(): OutputTransformPipeline { |
71 | return ( new OutputTransformPipeline() ) |
72 | ->addStage( new ExtractBody( $this->logger ) ) |
73 | ->addStage( new AddRedirectHeader() ) |
74 | ->addStage( new RenderDebugInfo( $this->hookContainer ) ) |
75 | ->addStage( new ParsoidLocalization( $this->logger ) ) |
76 | ->addStage( new ExecutePostCacheTransformHooks( $this->hookContainer ) ) |
77 | ->addStage( new AddWrapperDivClass( $this->langFactory, $this->contentLang ) ) |
78 | ->addStage( new HandleSectionLinks( $this->options, $this->titleFactory ) ) |
79 | ->addStage( new HandleParsoidSectionLinks( $this->logger, $this->titleFactory ) ) |
80 | ->addStage( new HandleTOCMarkers( $this->tidy ) ) |
81 | ->addStage( new DeduplicateStyles() ) |
82 | ->addStage( new ExpandToAbsoluteUrls() ) |
83 | ->addStage( new HydrateHeaderPlaceholders() ); |
84 | } |
85 | } |