3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 use MediaWiki\BadFileLookup
;
23 use MediaWiki\Config\ServiceOptions
;
24 use MediaWiki\Linker\LinkRendererFactory
;
25 use MediaWiki\MediaWikiServices
;
26 use MediaWiki\Special\SpecialPageFactory
;
27 use Psr\Log\LoggerInterface
;
28 use Psr\Log\NullLogger
;
34 /** @var ServiceOptions */
37 /** @var MagicWordFactory */
38 private $magicWordFactory;
44 private $urlProtocols;
46 /** @var SpecialPageFactory */
47 private $specialPageFactory;
49 /** @var LinkRendererFactory */
50 private $linkRendererFactory;
52 /** @var NamespaceInfo */
55 /** @var LoggerInterface */
58 /** @var BadFileLookup */
59 private $badFileLookup;
62 * Old parameter list, which we support for backwards compatibility, were:
63 * array $parserConf See $wgParserConf documentation
64 * MagicWordFactory $magicWordFactory
65 * Language $contLang Content language
66 * string $urlProtocols As returned from wfUrlProtocols()
67 * SpecialPageFactory $spFactory
69 * LinkRendererFactory $linkRendererFactory
70 * NamespaceInfo|null $nsInfo
72 * Some type declarations were intentionally omitted so that the backwards compatibility code
73 * would work. When backwards compatibility is no longer required, we should remove it, and
74 * and add the omitted type declarations.
76 * @param ServiceOptions|array $svcOptions
77 * @param MagicWordFactory $magicWordFactory
78 * @param Language $contLang Content language
79 * @param string $urlProtocols As returned from wfUrlProtocols()
80 * @param SpecialPageFactory $spFactory
81 * @param LinkRendererFactory $linkRendererFactory
82 * @param NamespaceInfo|LinkRendererFactory|null $nsInfo
83 * @param LoggerInterface|null $logger
84 * @param BadFileLookup|null $badFileLookup
87 public function __construct(
89 MagicWordFactory
$magicWordFactory,
92 SpecialPageFactory
$spFactory,
96 BadFileLookup
$badFileLookup = null
98 // @todo Do we need to retain compat for constructing this class directly?
100 wfDeprecated( __METHOD__
. ' with no NamespaceInfo argument', '1.34' );
101 $nsInfo = MediaWikiServices
::getInstance()->getNamespaceInfo();
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,
109 [ 'class' => Parser
::class,
110 'preprocessorClass' => Parser
::getDefaultPreprocessorClass() ],
113 $linkRendererFactory = func_get_arg( 6 );
114 $nsInfo = func_num_args() > 7 ?
func_get_arg( 7 ) : null;
116 $svcOptions->assertRequiredOptions( Parser
::$constructorOptions );
118 wfDebug( __CLASS__
. ": using preprocessor: {$svcOptions->get( 'preprocessorClass' )}\n" );
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();
136 public function create() : Parser
{
139 $this->magicWordFactory
,
143 $this->specialPageFactory
,
144 $this->linkRendererFactory
,