MediaWiki  master
ParserFactory.php
Go to the documentation of this file.
1 <?php
29 
35  private $svcOptions;
36 
39 
41  private $contLang;
42 
44  private $urlProtocols;
45 
48 
51 
53  private $nsInfo;
54 
56  private $logger;
57 
59  private $badFileLookup;
60 
87  public function __construct(
92  SpecialPageFactory $spFactory,
94  $nsInfo = null,
95  $logger = null,
97  ) {
98  // @todo Do we need to retain compat for constructing this class directly?
99  if ( !$nsInfo ) {
100  wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' );
101  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
102  }
103  if ( $linkRendererFactory instanceof Config ) {
104  // Old calling convention had an array in the format of $wgParserConf as the first
105  // parameter, and a Config as the sixth, with LinkRendererFactory as the seventh.
106  wfDeprecated( __METHOD__ . ' with Config parameter', '1.34' );
107  $svcOptions = new ServiceOptions( Parser::CONSTRUCTOR_OPTIONS,
108  $svcOptions,
109  [ 'class' => Parser::class,
110  'preprocessorClass' => Parser::getDefaultPreprocessorClass() ],
111  func_get_arg( 5 )
112  );
113  $linkRendererFactory = func_get_arg( 6 );
114  $nsInfo = func_num_args() > 7 ? func_get_arg( 7 ) : null;
115  }
116  $svcOptions->assertRequiredOptions( Parser::CONSTRUCTOR_OPTIONS );
117 
118  wfDebug( __CLASS__ . ": using preprocessor: {$svcOptions->get( 'preprocessorClass' )}\n" );
119 
120  $this->svcOptions = $svcOptions;
121  $this->magicWordFactory = $magicWordFactory;
122  $this->contLang = $contLang;
123  $this->urlProtocols = $urlProtocols;
124  $this->specialPageFactory = $spFactory;
125  $this->linkRendererFactory = $linkRendererFactory;
126  $this->nsInfo = $nsInfo;
127  $this->logger = $logger ?: new NullLogger();
128  $this->badFileLookup = $badFileLookup ??
129  MediaWikiServices::getInstance()->getBadFileLookup();
130  }
131 
136  public function create() : Parser {
137  return new Parser(
138  $this->svcOptions,
139  $this->magicWordFactory,
140  $this->contLang,
141  $this,
142  $this->urlProtocols,
143  $this->specialPageFactory,
144  $this->linkRendererFactory,
145  $this->nsInfo,
146  $this->logger,
147  $this->badFileLookup
148  );
149  }
150 }
__construct( $svcOptions, MagicWordFactory $magicWordFactory, Language $contLang, $urlProtocols, SpecialPageFactory $spFactory, $linkRendererFactory, $nsInfo=null, $logger=null, BadFileLookup $badFileLookup=null)
Old parameter list, which we support for backwards compatibility, were: array $parserConf See $wgPars...
MagicWordFactory $magicWordFactory
ServiceOptions $svcOptions
A class for passing options to services.
Factory for handling the special page list and generating SpecialPage objects.
Interface for configuration instances.
Definition: Config.php:28
SpecialPageFactory $specialPageFactory
string $urlProtocols
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Language $contLang
LinkRendererFactory $linkRendererFactory
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys, without regard for order.
NamespaceInfo $nsInfo
LoggerInterface $logger
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
static getDefaultPreprocessorClass()
Which class should we use for the preprocessor if not otherwise specified?
Definition: Parser.php:449
BadFileLookup $badFileLookup