MediaWiki  1.34.0
ParserFactory.php
Go to the documentation of this file.
1 <?php
27 use Psr\Log\LoggerInterface;
28 use Psr\Log\NullLogger;
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::$constructorOptions,
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::$constructorOptions );
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 }
ParserFactory\$contLang
Language $contLang
Definition: ParserFactory.php:41
ParserFactory\create
create()
Definition: ParserFactory.php:136
ParserFactory\$magicWordFactory
MagicWordFactory $magicWordFactory
Definition: ParserFactory.php:38
MagicWordFactory
A factory that stores information about MagicWords, and creates them on demand with caching.
Definition: MagicWordFactory.php:34
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
MediaWiki\BadFileLookup
Definition: BadFileLookup.php:12
MediaWiki\Linker\LinkRendererFactory
Factory to create LinkRender objects.
Definition: LinkRendererFactory.php:32
ParserFactory\$badFileLookup
BadFileLookup $badFileLookup
Definition: ParserFactory.php:59
ParserFactory\$logger
LoggerInterface $logger
Definition: ParserFactory.php:56
Config
Interface for configuration instances.
Definition: Config.php:28
ParserFactory\$svcOptions
ServiceOptions $svcOptions
Definition: ParserFactory.php:35
ParserFactory\$urlProtocols
string $urlProtocols
Definition: ParserFactory.php:44
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition: ServiceOptions.php:25
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1044
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:913
ParserFactory\$specialPageFactory
SpecialPageFactory $specialPageFactory
Definition: ParserFactory.php:47
MediaWiki\Special\SpecialPageFactory
Factory for handling the special page list and generating SpecialPage objects.
Definition: SpecialPageFactory.php:64
ParserFactory
Definition: ParserFactory.php:33
ParserFactory\__construct
__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...
Definition: ParserFactory.php:87
ParserFactory\$linkRendererFactory
LinkRendererFactory $linkRendererFactory
Definition: ParserFactory.php:50
ParserFactory\$nsInfo
NamespaceInfo $nsInfo
Definition: ParserFactory.php:53
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:33
Language
Internationalisation code.
Definition: Language.php:37
MediaWiki\Config\ServiceOptions\assertRequiredOptions
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Definition: ServiceOptions.php:62