MediaWiki master
ParserFactory.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Parser;
9
15use MediaWiki\Languages\LanguageConverterFactory;
16use MediaWiki\Languages\LanguageNameUtils;
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 MagicWordFactory $magicWordFactory,
55 private readonly Language $contLang,
56 private readonly UrlUtils $urlUtils,
57 private readonly SpecialPageFactory $specialPageFactory,
58 private readonly LinkRendererFactory $linkRendererFactory,
59 private readonly NamespaceInfo $nsInfo,
60 private readonly LoggerInterface $logger,
61 private readonly BadFileLookup $badFileLookup,
62 private readonly LanguageConverterFactory $languageConverterFactory,
63 private readonly LanguageNameUtils $languageNameUtils,
64 private readonly HookContainer $hookContainer,
65 private readonly TidyDriverBase $tidy,
66 private readonly WANObjectCache $wanCache,
67 private readonly UserOptionsLookup $userOptionsLookup,
68 private readonly UserFactory $userFactory,
69 private readonly TitleFormatter $titleFormatter,
70 private readonly HttpRequestFactory $httpRequestFactory,
71 private readonly TrackingCategories $trackingCategories,
72 private readonly SignatureValidatorFactory $signatureValidatorFactory,
73 private readonly UserNameUtils $userNameUtils,
74 ) {
75 $svcOptions->assertRequiredOptions( Parser::CONSTRUCTOR_OPTIONS );
76
77 wfDebug( __CLASS__ . ": using default preprocessor" );
78 }
79
90 public function create(): Parser {
91 self::$inParserFactory++;
92 try {
93 return new Parser(
94 $this->svcOptions,
95 $this->magicWordFactory,
96 $this->contLang,
97 $this->urlUtils,
98 $this->specialPageFactory,
99 $this->linkRendererFactory,
100 $this->nsInfo,
101 $this->logger,
102 $this->badFileLookup,
103 $this->languageConverterFactory,
104 $this->languageNameUtils,
105 $this->hookContainer,
106 $this->tidy,
107 $this->wanCache,
108 $this->userOptionsLookup,
109 $this->userFactory,
110 $this->titleFormatter,
111 $this->httpRequestFactory,
112 $this->trackingCategories,
113 $this->signatureValidatorFactory,
114 $this->userNameUtils
115 );
116 } finally {
117 self::$inParserFactory--;
118 }
119 }
120
133 public function getMainInstance() {
134 if ( $this->mainInstance === null ) {
135 $this->mainInstance = $this->create();
136 }
137 return $this->mainInstance;
138 }
139
151 public function getInstance() {
152 $instance = $this->getMainInstance();
153 if ( $instance->isLocked() ) {
154 $instance = $this->create();
155 }
156 return $instance;
157 }
158
159}
160
162class_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.
Base class for language-specific code.
Definition Language.php:69
Factory to create LinkRender objects.
Store information about magic words, and create/cache MagicWord objects.
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.
__construct(private readonly ServiceOptions $svcOptions, 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,)
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:135
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.