MediaWiki master
ParserFactory.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Parser;
9
30use Psr\Log\LoggerInterface;
32
45 public static $inParserFactory = 0;
46
48 private $mainInstance;
49
54 public function __construct(
55 private readonly ServiceOptions $svcOptions,
56 private readonly ParserCoreTagHooks $parserCoreTagHooks,
57 private readonly MagicWordFactory $magicWordFactory,
58 private readonly Language $contLang,
59 private readonly UrlUtils $urlUtils,
60 private readonly SpecialPageFactory $specialPageFactory,
61 private readonly LinkRendererFactory $linkRendererFactory,
62 private readonly NamespaceInfo $nsInfo,
63 private readonly LoggerInterface $logger,
64 private readonly BadFileLookup $badFileLookup,
65 private readonly RepoGroup $repoGroup,
66 private readonly LanguageFactory $languageFactory,
67 private readonly LanguageConverterFactory $languageConverterFactory,
68 private readonly LanguageNameUtils $languageNameUtils,
69 private readonly HookContainer $hookContainer,
70 private readonly TidyDriverBase $tidy,
71 private readonly WANObjectCache $wanCache,
72 private readonly UserOptionsLookup $userOptionsLookup,
73 private readonly UserFactory $userFactory,
74 private readonly TitleFormatter $titleFormatter,
75 private readonly HttpRequestFactory $httpRequestFactory,
76 private readonly TrackingCategories $trackingCategories,
77 private readonly SignatureValidatorFactory $signatureValidatorFactory,
78 private readonly UserNameUtils $userNameUtils,
79 ) {
80 $svcOptions->assertRequiredOptions( Parser::CONSTRUCTOR_OPTIONS );
81
82 wfDebug( __CLASS__ . ": using default preprocessor" );
83 }
84
95 public function create(): Parser {
96 self::$inParserFactory++;
97 try {
98 return new Parser(
99 $this->svcOptions,
100 $this->parserCoreTagHooks,
101 $this->magicWordFactory,
102 $this->contLang,
103 $this->urlUtils,
104 $this->specialPageFactory,
105 $this->linkRendererFactory,
106 $this->nsInfo,
107 $this->logger,
108 $this->badFileLookup,
109 $this->repoGroup,
110 $this->languageFactory,
111 $this->languageConverterFactory,
112 $this->languageNameUtils,
113 $this->hookContainer,
114 $this->tidy,
115 $this->wanCache,
116 $this->userOptionsLookup,
117 $this->userFactory,
118 $this->titleFormatter,
119 $this->httpRequestFactory,
120 $this->trackingCategories,
121 $this->signatureValidatorFactory,
122 $this->userNameUtils
123 );
124 } finally {
125 self::$inParserFactory--;
126 }
127 }
128
141 public function getMainInstance() {
142 if ( $this->mainInstance === null ) {
143 $this->mainInstance = $this->create();
144 }
145 return $this->mainInstance;
146 }
147
159 public function getInstance() {
160 $instance = $this->getMainInstance();
161 if ( $instance->isLocked() ) {
162 $instance = $this->create();
163 }
164 return $instance;
165 }
166
167}
168
170class_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.
Prioritized list of file repositories.
Definition RepoGroup.php:30
Factory creating MWHttpRequest objects.
An interface for creating language converters.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
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 RepoGroup $repoGroup, private readonly LanguageFactory $languageFactory, 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:138
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.