MediaWiki  master
ParserFactory.php
Go to the documentation of this file.
1 <?php
36 use Psr\Log\LoggerInterface;
37 
43  private $svcOptions;
44 
46  private $magicWordFactory;
47 
49  private $contLang;
50 
52  private $urlUtils;
53 
55  private $specialPageFactory;
56 
58  private $linkRendererFactory;
59 
61  private $nsInfo;
62 
64  private $logger;
65 
67  private $badFileLookup;
68 
70  private $languageConverterFactory;
71 
73  private $userOptionsLookup;
74 
76  private $userFactory;
77 
79  private $titleFormatter;
80 
82  private $httpRequestFactory;
83 
85  private $trackingCategories;
86 
88  private $signatureValidatorFactory;
89 
91  private $userNameUtils;
92 
101  public static $inParserFactory = 0;
102 
104  private $hookContainer;
105 
107  private $tidy;
108 
110  private $wanCache;
111 
113  private $mainInstance;
114 
139  public function __construct(
140  ServiceOptions $svcOptions,
141  MagicWordFactory $magicWordFactory,
142  Language $contLang,
143  UrlUtils $urlUtils,
144  SpecialPageFactory $spFactory,
145  LinkRendererFactory $linkRendererFactory,
146  NamespaceInfo $nsInfo,
147  LoggerInterface $logger,
148  BadFileLookup $badFileLookup,
149  LanguageConverterFactory $languageConverterFactory,
150  HookContainer $hookContainer,
151  TidyDriverBase $tidy,
152  WANObjectCache $wanCache,
153  UserOptionsLookup $userOptionsLookup,
154  UserFactory $userFactory,
155  TitleFormatter $titleFormatter,
156  HttpRequestFactory $httpRequestFactory,
157  TrackingCategories $trackingCategories,
158  SignatureValidatorFactory $signatureValidatorFactory,
159  UserNameUtils $userNameUtils
160  ) {
162 
163  wfDebug( __CLASS__ . ": using default preprocessor" );
164 
165  $this->svcOptions = $svcOptions;
166  $this->magicWordFactory = $magicWordFactory;
167  $this->contLang = $contLang;
168  $this->urlUtils = $urlUtils;
169  $this->specialPageFactory = $spFactory;
170  $this->linkRendererFactory = $linkRendererFactory;
171  $this->nsInfo = $nsInfo;
172  $this->logger = $logger;
173  $this->badFileLookup = $badFileLookup;
174  $this->languageConverterFactory = $languageConverterFactory;
175  $this->hookContainer = $hookContainer;
176  $this->tidy = $tidy;
177  $this->wanCache = $wanCache;
178  $this->userOptionsLookup = $userOptionsLookup;
179  $this->userFactory = $userFactory;
180  $this->titleFormatter = $titleFormatter;
181  $this->httpRequestFactory = $httpRequestFactory;
182  $this->trackingCategories = $trackingCategories;
183  $this->signatureValidatorFactory = $signatureValidatorFactory;
184  $this->userNameUtils = $userNameUtils;
185  }
186 
193  public function create(): Parser {
194  self::$inParserFactory++;
195  try {
196  return new Parser(
197  $this->svcOptions,
198  $this->magicWordFactory,
199  $this->contLang,
200  $this,
201  $this->urlUtils,
202  $this->specialPageFactory,
203  $this->linkRendererFactory,
204  $this->nsInfo,
205  $this->logger,
206  $this->badFileLookup,
207  $this->languageConverterFactory,
208  $this->hookContainer,
209  $this->tidy,
210  $this->wanCache,
211  $this->userOptionsLookup,
212  $this->userFactory,
213  $this->titleFormatter,
214  $this->httpRequestFactory,
215  $this->trackingCategories,
216  $this->signatureValidatorFactory,
217  $this->userNameUtils
218  );
219  } finally {
220  self::$inParserFactory--;
221  }
222  }
223 
232  public function getMainInstance() {
233  if ( $this->mainInstance === null ) {
234  $this->mainInstance = $this->create();
235  }
236  return $this->mainInstance;
237  }
238 
245  public function getInstance() {
246  $instance = $this->getMainInstance();
247  if ( $instance->isLocked() ) {
248  $instance = $this->create();
249  }
250  return $instance;
251  }
252 
253 }
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:56
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:38
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:104
const CONSTRUCTOR_OPTIONS
Definition: Parser.php:424
This class performs some operations related to tracking categories, such as creating a list of all su...
Multi-datacenter aware caching interface.
A title formatter service for MediaWiki.