MediaWiki 1.43.1
DefaultOutputPipelineFactory.php
Go to the documentation of this file.
1<?php
2
4
21use Psr\Log\LoggerInterface;
22use Wikimedia\ObjectFactory\ObjectFactory;
23
30
31 private ServiceOptions $options;
32 private Config $config;
33 private LoggerInterface $logger;
34 private ObjectFactory $objectFactory;
35
36 public const CONSTRUCTOR_OPTIONS = [
38 ];
39
40 private const CORE_LIST = [
41 'ExtractBody' => [
42 'class' => ExtractBody::class,
43 'services' => [
44 'UrlUtils',
45 ],
46 'optional_services' => [
47 'MobileFrontend.Context',
48 ],
49 ],
50 'AddRedirectHeader' => [
51 'class' => AddRedirectHeader::class,
52 ],
53 'RenderDebugInfo' => [
54 'class' => RenderDebugInfo::class,
55 'services' => [
56 'HookContainer',
57 ],
58 ],
59 'ParsoidLocalization' => [
60 'class' => ParsoidLocalization::class,
61 ],
62 'ExecutePostCacheTransformHooks' => [
63 'class' => ExecutePostCacheTransformHooks::class,
64 'services' => [
65 'HookContainer',
66 ],
67 ],
68 'AddWrapperDivClass' => [
69 'class' => AddWrapperDivClass::class,
70 'services' => [
71 'LanguageFactory',
72 'ContentLanguage',
73 ],
74 ],
75 'HandleSectionLinks' => [
76 'class' => HandleSectionLinks::class,
77 'services' => [
78 'TitleFactory',
79 ],
80 ],
81 'HandleParsoidSectionLinks' => [
82 'class' => HandleParsoidSectionLinks::class,
83 'services' => [
84 'TitleFactory',
85 ],
86 ],
87 'HandleTOCMarkers' => [
88 'class' => HandleTOCMarkers::class,
89 'services' => [
90 'Tidy',
91 ],
92 ],
93 'DeduplicateStyles' => [
94 'class' => DeduplicateStyles::class,
95 ],
96 'ExpandToAbsoluteUrls' => [
97 'class' => ExpandToAbsoluteUrls::class,
98 ],
99 'HydrateHeaderPlaceholders' => [
100 'class' => HydrateHeaderPlaceholders::class,
101 ],
102 # This should be last, in order to ensure final output is hardened
103 'HardenNFC' => [
104 'class' => HardenNFC::class,
105 ],
106 ];
107
108 public function __construct(
109 ServiceOptions $options,
110 Config $config,
111 LoggerInterface $logger,
112 ObjectFactory $objectFactory
113 ) {
114 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
115 $this->options = $options;
116 $this->config = $config;
117 $this->logger = $logger;
118 $this->objectFactory = $objectFactory;
119 }
120
128 // Add extension stages
129 $list = array_merge(
130 self::CORE_LIST,
131 $this->options->get( MainConfigNames::OutputPipelineStages )
132 );
133
134 $otp = new OutputTransformPipeline();
135 foreach ( $list as $spec ) {
136 $class = $spec['class'];
137 $svcOptions = new ServiceOptions(
138 $class::CONSTRUCTOR_OPTIONS, $this->config
139 );
140 $transform = $this->objectFactory->createObject(
141 $spec,
142 [
143 'assertClass' => OutputTransformStage::class,
144 'extraArgs' => [ $svcOptions, $this->logger ],
145 ]
146 );
147 $otp->addStage( $transform );
148 }
149 return $otp;
150 }
151}
A class for passing options to services.
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
A class containing constants representing the names of configuration variables.
const OutputPipelineStages
Name constant for the OutputPipelineStages setting, for use with Config::get()
This class contains the default output transformation pipeline factory for wikitext.
buildPipeline()
Creates a pipeline of transformations to transform the content of the ParserOutput object from "parse...
__construct(ServiceOptions $options, Config $config, LoggerInterface $logger, ObjectFactory $objectFactory)
Wrap the output in a div with the provided class name.
Generates a list of unique style links.
Applies base href, and strip everything but the <body>
Inject table of contents (or empty string if there's no sections)
Hardens the output against NFC normalization (T387130).
Definition HardenNFC.php:14
Hydrate slot section header placeholders generated by RevisionRenderer.
Resolves the mw:I18n and mw:LocalizedAttrs to their localised forms.
Interface for configuration instances.
Definition Config.php:32