MediaWiki master
ParserFactory.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Parser;
9
28use Psr\Log\LoggerInterface;
30
43 public static $inParserFactory = 0;
44
46 private $mainInstance;
47
52 public function __construct(
53 private readonly ServiceOptions $svcOptions,
54 private readonly ParserCoreTagHooks $parserCoreTagHooks,
55 private readonly MagicWordFactory $magicWordFactory,
56 private readonly Language $contLang,
57 private readonly UrlUtils $urlUtils,
58 private readonly SpecialPageFactory $specialPageFactory,
59 private readonly LinkRendererFactory $linkRendererFactory,
60 private readonly NamespaceInfo $nsInfo,
61 private readonly LoggerInterface $logger,
62 private readonly BadFileLookup $badFileLookup,
63 private readonly LanguageConverterFactory $languageConverterFactory,
64 private readonly LanguageNameUtils $languageNameUtils,
65 private readonly HookContainer $hookContainer,
66 private readonly TidyDriverBase $tidy,
67 private readonly WANObjectCache $wanCache,
68 private readonly UserOptionsLookup $userOptionsLookup,
69 private readonly UserFactory $userFactory,
70 private readonly TitleFormatter $titleFormatter,
71 private readonly HttpRequestFactory $httpRequestFactory,
72 private readonly TrackingCategories $trackingCategories,
73 private readonly SignatureValidatorFactory $signatureValidatorFactory,
74 private readonly UserNameUtils $userNameUtils,
75 ) {
76 $svcOptions->assertRequiredOptions( Parser::CONSTRUCTOR_OPTIONS );
77
78 wfDebug( __CLASS__ . ": using default preprocessor" );
79 }
80
91 public function create(): Parser {
92 self::$inParserFactory++;
93 try {
94 return new Parser(
95 $this->svcOptions,
96 $this->parserCoreTagHooks,
97 $this->magicWordFactory,
98 $this->contLang,
99 $this->urlUtils,
100 $this->specialPageFactory,
101 $this->linkRendererFactory,
102 $this->nsInfo,
103 $this->logger,
104 $this->badFileLookup,
105 $this->languageConverterFactory,
106 $this->languageNameUtils,
107 $this->hookContainer,
108 $this->tidy,
109 $this->wanCache,
110 $this->userOptionsLookup,
111 $this->userFactory,
112 $this->titleFormatter,
113 $this->httpRequestFactory,
114 $this->trackingCategories,
115 $this->signatureValidatorFactory,
116 $this->userNameUtils
117 );
118 } finally {
119 self::$inParserFactory--;
120 }
121 }
122
135 public function getMainInstance() {
136 if ( $this->mainInstance === null ) {
137 $this->mainInstance = $this->create();
138 }
139 return $this->mainInstance;
140 }
141
153 public function getInstance() {
154 $instance = $this->getMainInstance();
155 if ( $instance->isLocked() ) {
156 $instance = $this->create();
157 }
158 return $instance;
159 }
160
161}
162
164class_alias( ParserFactory::class, 'ParserFactory' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
This class performs some operations related to tracking categories, such as adding a tracking categor...
A class for passing options to services.
Factory creating MWHttpRequest objects.
An interface for creating language converters.
A service that provides utilities to do with language names and codes.
Base class for language-specific code.
Definition Language.php:65
Factory to create LinkRender objects.
Store information about magic words, and create/cache MagicWord objects.
Various tag hooks, registered in every Parser.
static int $inParserFactory
Track calls to Parser constructor to aid in deprecation of direct Parser invocation.
getInstance()
Get the main shared instance, or if it is locked, get a new instance.
getMainInstance()
Get the main shared instance.
__construct(private readonly ServiceOptions $svcOptions, private readonly ParserCoreTagHooks $parserCoreTagHooks, private readonly MagicWordFactory $magicWordFactory, private readonly Language $contLang, private readonly UrlUtils $urlUtils, private readonly SpecialPageFactory $specialPageFactory, private readonly LinkRendererFactory $linkRendererFactory, private readonly NamespaceInfo $nsInfo, private readonly LoggerInterface $logger, private readonly BadFileLookup $badFileLookup, private readonly LanguageConverterFactory $languageConverterFactory, private readonly LanguageNameUtils $languageNameUtils, private readonly HookContainer $hookContainer, private readonly TidyDriverBase $tidy, private readonly WANObjectCache $wanCache, private readonly UserOptionsLookup $userOptionsLookup, private readonly UserFactory $userFactory, private readonly TitleFormatter $titleFormatter, private readonly HttpRequestFactory $httpRequestFactory, private readonly TrackingCategories $trackingCategories, private readonly SignatureValidatorFactory $signatureValidatorFactory, private readonly UserNameUtils $userNameUtils,)
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:134
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...
A title formatter service for MediaWiki.
Provides access to user options.
Create User objects.
UserNameUtils service.
A service to expand, parse, and otherwise manipulate URLs.
Definition UrlUtils.php:16
Multi-datacenter aware caching interface.