Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / includes / parser / ParserFactory.php
index eb05ace..0446d9c 100644 (file)
  * @ingroup Parser
  */
 
+use MediaWiki\Config\ServiceOptions;
+use MediaWiki\Linker\LinkRendererFactory;
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Special\SpecialPageFactory;
 
 /**
  * @since 1.32
  */
 class ParserFactory {
-       /** @var array */
-       private $parserConf;
+       /** @var ServiceOptions */
+       private $svcOptions;
 
        /** @var MagicWordFactory */
        private $magicWordFactory;
@@ -40,28 +43,70 @@ class ParserFactory {
        /** @var SpecialPageFactory */
        private $specialPageFactory;
 
-       /** @var Config */
-       private $siteConfig;
+       /** @var LinkRendererFactory */
+       private $linkRendererFactory;
+
+       /** @var NamespaceInfo */
+       private $nsInfo;
 
        /**
-        * @param array $parserConf See $wgParserConf documentation
+        * Old parameter list, which we support for backwards compatibility, were:
+        *   array $parserConf See $wgParserConf documentation
+        *   MagicWordFactory $magicWordFactory
+        *   Language $contLang Content language
+        *   string $urlProtocols As returned from wfUrlProtocols()
+        *   SpecialPageFactory $spFactory
+        *   Config $siteConfig
+        *   LinkRendererFactory $linkRendererFactory
+        *   NamespaceInfo|null $nsInfo
+        *
+        * Some type declarations were intentionally omitted so that the backwards compatibility code
+        * would work. When backwards compatibility is no longer required, we should remove it, and
+        * and add the omitted type declarations.
+        *
+        * @param ServiceOptions|array $svcOptions
         * @param MagicWordFactory $magicWordFactory
         * @param Language $contLang Content language
         * @param string $urlProtocols As returned from wfUrlProtocols()
         * @param SpecialPageFactory $spFactory
-        * @param Config $siteConfig
+        * @param LinkRendererFactory $linkRendererFactory
+        * @param NamespaceInfo|LinkRendererFactory|null $nsInfo
         * @since 1.32
         */
        public function __construct(
-               array $parserConf, MagicWordFactory $magicWordFactory, Language $contLang, $urlProtocols,
-               SpecialPageFactory $spFactory, Config $siteConfig
+               $svcOptions, MagicWordFactory $magicWordFactory, Language $contLang,
+               $urlProtocols, SpecialPageFactory $spFactory, $linkRendererFactory,
+               $nsInfo = null
        ) {
-               $this->parserConf = $parserConf;
+               // @todo Do we need to retain compat for constructing this class directly?
+               if ( !$nsInfo ) {
+                       wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' );
+                       $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+               }
+               if ( $linkRendererFactory instanceof Config ) {
+                       // Old calling convention had an array in the format of $wgParserConf as the first
+                       // parameter, and a Config as the sixth, with LinkRendererFactory as the seventh.
+                       wfDeprecated( __METHOD__ . ' with Config parameter', '1.34' );
+                       $svcOptions = new ServiceOptions( Parser::$constructorOptions,
+                               $svcOptions,
+                               [ 'class' => Parser::class,
+                                       'preprocessorClass' => Parser::getDefaultPreprocessorClass() ],
+                               func_get_arg( 5 )
+                       );
+                       $linkRendererFactory = func_get_arg( 6 );
+                       $nsInfo = func_num_args() > 7 ? func_get_arg( 7 ) : null;
+               }
+               $svcOptions->assertRequiredOptions( Parser::$constructorOptions );
+
+               wfDebug( __CLASS__ . ": using preprocessor: {$svcOptions->get( 'preprocessorClass' )}\n" );
+
+               $this->svcOptions = $svcOptions;
                $this->magicWordFactory = $magicWordFactory;
                $this->contLang = $contLang;
                $this->urlProtocols = $urlProtocols;
                $this->specialPageFactory = $spFactory;
-               $this->siteConfig = $siteConfig;
+               $this->linkRendererFactory = $linkRendererFactory;
+               $this->nsInfo = $nsInfo;
        }
 
        /**
@@ -69,7 +114,8 @@ class ParserFactory {
         * @since 1.32
         */
        public function create() : Parser {
-               return new Parser( $this->parserConf, $this->magicWordFactory, $this->contLang, $this,
-                       $this->urlProtocols, $this->specialPageFactory, $this->siteConfig );
+               return new Parser( $this->svcOptions, $this->magicWordFactory, $this->contLang, $this,
+                       $this->urlProtocols, $this->specialPageFactory, $this->linkRendererFactory,
+                       $this->nsInfo );
        }
 }