MediaWiki master
ParserFactory.php
Go to the documentation of this file.
1<?php
39use Psr\Log\LoggerInterface;
40
46 private $svcOptions;
47
49 private $magicWordFactory;
50
52 private $contLang;
53
55 private $urlUtils;
56
58 private $specialPageFactory;
59
61 private $linkRendererFactory;
62
64 private $nsInfo;
65
67 private $logger;
68
70 private $badFileLookup;
71
73 private $languageConverterFactory;
74
76 private $userOptionsLookup;
77
79 private $userFactory;
80
82 private $titleFormatter;
83
85 private $httpRequestFactory;
86
88 private $trackingCategories;
89
91 private $signatureValidatorFactory;
92
94 private $userNameUtils;
95
104 public static $inParserFactory = 0;
105
107 private $hookContainer;
108
110 private $tidy;
111
113 private $wanCache;
114
116 private $mainInstance;
117
142 public function __construct(
143 ServiceOptions $svcOptions,
144 MagicWordFactory $magicWordFactory,
145 Language $contLang,
146 UrlUtils $urlUtils,
147 SpecialPageFactory $spFactory,
148 LinkRendererFactory $linkRendererFactory,
149 NamespaceInfo $nsInfo,
150 LoggerInterface $logger,
151 BadFileLookup $badFileLookup,
152 LanguageConverterFactory $languageConverterFactory,
153 HookContainer $hookContainer,
154 TidyDriverBase $tidy,
155 WANObjectCache $wanCache,
156 UserOptionsLookup $userOptionsLookup,
157 UserFactory $userFactory,
158 TitleFormatter $titleFormatter,
159 HttpRequestFactory $httpRequestFactory,
160 TrackingCategories $trackingCategories,
161 SignatureValidatorFactory $signatureValidatorFactory,
162 UserNameUtils $userNameUtils
163 ) {
164 $svcOptions->assertRequiredOptions( Parser::CONSTRUCTOR_OPTIONS );
165
166 wfDebug( __CLASS__ . ": using default preprocessor" );
167
168 $this->svcOptions = $svcOptions;
169 $this->magicWordFactory = $magicWordFactory;
170 $this->contLang = $contLang;
171 $this->urlUtils = $urlUtils;
172 $this->specialPageFactory = $spFactory;
173 $this->linkRendererFactory = $linkRendererFactory;
174 $this->nsInfo = $nsInfo;
175 $this->logger = $logger;
176 $this->badFileLookup = $badFileLookup;
177 $this->languageConverterFactory = $languageConverterFactory;
178 $this->hookContainer = $hookContainer;
179 $this->tidy = $tidy;
180 $this->wanCache = $wanCache;
181 $this->userOptionsLookup = $userOptionsLookup;
182 $this->userFactory = $userFactory;
183 $this->titleFormatter = $titleFormatter;
184 $this->httpRequestFactory = $httpRequestFactory;
185 $this->trackingCategories = $trackingCategories;
186 $this->signatureValidatorFactory = $signatureValidatorFactory;
187 $this->userNameUtils = $userNameUtils;
188 }
189
200 public function create(): Parser {
201 self::$inParserFactory++;
202 try {
203 return new Parser(
204 $this->svcOptions,
205 $this->magicWordFactory,
206 $this->contLang,
207 $this,
208 $this->urlUtils,
209 $this->specialPageFactory,
210 $this->linkRendererFactory,
211 $this->nsInfo,
212 $this->logger,
213 $this->badFileLookup,
214 $this->languageConverterFactory,
215 $this->hookContainer,
216 $this->tidy,
217 $this->wanCache,
218 $this->userOptionsLookup,
219 $this->userFactory,
220 $this->titleFormatter,
221 $this->httpRequestFactory,
222 $this->trackingCategories,
223 $this->signatureValidatorFactory,
224 $this->userNameUtils
225 );
226 } finally {
227 self::$inParserFactory--;
228 }
229 }
230
243 public function getMainInstance() {
244 if ( $this->mainInstance === null ) {
245 $this->mainInstance = $this->create();
246 }
247 return $this->mainInstance;
248 }
249
261 public function getInstance() {
262 $instance = $this->getMainInstance();
263 if ( $instance->isLocked() ) {
264 $instance = $this->create();
265 }
266 return $instance;
267 }
268
269}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Base class for language-specific code.
Definition Language.php:63
This class performs some operations related to tracking categories, such as adding a tracking categor...
A class for passing options to services.
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Factory creating MWHttpRequest objects.
An interface for creating language converters.
Factory to create LinkRender objects.
Store information about magic words, and create/cache MagicWord objects.
Factory for handling the special page list and generating SpecialPage objects.
Base class for HTML cleanup utilities.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Creates User objects.
UserNameUtils service.
Provides access to user options.
A service to expand, parse, and otherwise manipulate URLs.
Definition UrlUtils.php:17
getInstance()
Get the main shared instance, or if it is locked, get a new instance.
static int $inParserFactory
Track calls to Parser constructor to aid in deprecation of direct Parser invocation.
__construct(ServiceOptions $svcOptions, MagicWordFactory $magicWordFactory, Language $contLang, UrlUtils $urlUtils, SpecialPageFactory $spFactory, LinkRendererFactory $linkRendererFactory, NamespaceInfo $nsInfo, LoggerInterface $logger, BadFileLookup $badFileLookup, LanguageConverterFactory $languageConverterFactory, HookContainer $hookContainer, TidyDriverBase $tidy, WANObjectCache $wanCache, UserOptionsLookup $userOptionsLookup, UserFactory $userFactory, TitleFormatter $titleFormatter, HttpRequestFactory $httpRequestFactory, TrackingCategories $trackingCategories, SignatureValidatorFactory $signatureValidatorFactory, UserNameUtils $userNameUtils)
getMainInstance()
Get the main shared instance.
create()
Creates a new parser.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition Parser.php:118
Multi-datacenter aware caching interface.
A title formatter service for MediaWiki.