MediaWiki  master
ParserFactory.php
Go to the documentation of this file.
1 <?php
37 use Psr\Log\LoggerInterface;
38 
44  private $svcOptions;
45 
47  private $magicWordFactory;
48 
50  private $contLang;
51 
53  private $urlUtils;
54 
56  private $specialPageFactory;
57 
59  private $linkRendererFactory;
60 
62  private $nsInfo;
63 
65  private $logger;
66 
68  private $badFileLookup;
69 
71  private $languageConverterFactory;
72 
74  private $userOptionsLookup;
75 
77  private $userFactory;
78 
80  private $titleFormatter;
81 
83  private $httpRequestFactory;
84 
86  private $trackingCategories;
87 
89  private $signatureValidatorFactory;
90 
92  private $userNameUtils;
93 
102  public static $inParserFactory = 0;
103 
105  private $hookContainer;
106 
108  private $tidy;
109 
111  private $wanCache;
112 
114  private $mainInstance;
115 
140  public function __construct(
141  ServiceOptions $svcOptions,
142  MagicWordFactory $magicWordFactory,
143  Language $contLang,
144  UrlUtils $urlUtils,
145  SpecialPageFactory $spFactory,
146  LinkRendererFactory $linkRendererFactory,
147  NamespaceInfo $nsInfo,
148  LoggerInterface $logger,
149  BadFileLookup $badFileLookup,
150  LanguageConverterFactory $languageConverterFactory,
151  HookContainer $hookContainer,
152  TidyDriverBase $tidy,
153  WANObjectCache $wanCache,
154  UserOptionsLookup $userOptionsLookup,
155  UserFactory $userFactory,
156  TitleFormatter $titleFormatter,
157  HttpRequestFactory $httpRequestFactory,
158  TrackingCategories $trackingCategories,
159  SignatureValidatorFactory $signatureValidatorFactory,
160  UserNameUtils $userNameUtils
161  ) {
163 
164  wfDebug( __CLASS__ . ": using default preprocessor" );
165 
166  $this->svcOptions = $svcOptions;
167  $this->magicWordFactory = $magicWordFactory;
168  $this->contLang = $contLang;
169  $this->urlUtils = $urlUtils;
170  $this->specialPageFactory = $spFactory;
171  $this->linkRendererFactory = $linkRendererFactory;
172  $this->nsInfo = $nsInfo;
173  $this->logger = $logger;
174  $this->badFileLookup = $badFileLookup;
175  $this->languageConverterFactory = $languageConverterFactory;
176  $this->hookContainer = $hookContainer;
177  $this->tidy = $tidy;
178  $this->wanCache = $wanCache;
179  $this->userOptionsLookup = $userOptionsLookup;
180  $this->userFactory = $userFactory;
181  $this->titleFormatter = $titleFormatter;
182  $this->httpRequestFactory = $httpRequestFactory;
183  $this->trackingCategories = $trackingCategories;
184  $this->signatureValidatorFactory = $signatureValidatorFactory;
185  $this->userNameUtils = $userNameUtils;
186  }
187 
194  public function create(): Parser {
195  self::$inParserFactory++;
196  try {
197  return new Parser(
198  $this->svcOptions,
199  $this->magicWordFactory,
200  $this->contLang,
201  $this,
202  $this->urlUtils,
203  $this->specialPageFactory,
204  $this->linkRendererFactory,
205  $this->nsInfo,
206  $this->logger,
207  $this->badFileLookup,
208  $this->languageConverterFactory,
209  $this->hookContainer,
210  $this->tidy,
211  $this->wanCache,
212  $this->userOptionsLookup,
213  $this->userFactory,
214  $this->titleFormatter,
215  $this->httpRequestFactory,
216  $this->trackingCategories,
217  $this->signatureValidatorFactory,
218  $this->userNameUtils
219  );
220  } finally {
221  self::$inParserFactory--;
222  }
223  }
224 
233  public function getMainInstance() {
234  if ( $this->mainInstance === null ) {
235  $this->mainInstance = $this->create();
236  }
237  return $this->mainInstance;
238  }
239 
246  public function getInstance() {
247  $instance = $this->getMainInstance();
248  if ( $instance->isLocked() ) {
249  $instance = $this->create();
250  }
251  return $instance;
252  }
253 
254 }
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:57
This class performs some operations related to tracking categories, such as creating a list of all su...
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.
A factory that stores information about MagicWords, and creates them on demand with caching.
Factory for handling the special page list and generating SpecialPage objects.
Base class for HTML cleanup utilities.
Creates User objects.
Definition: UserFactory.php:42
UserNameUtils service.
Provides access to user options.
A service to expand, parse, and otherwise manipulate URLs.
Definition: UrlUtils.php:17
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
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:107
const CONSTRUCTOR_OPTIONS
Definition: Parser.php:403
Multi-datacenter aware caching interface.
A title formatter service for MediaWiki.