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\Config\ServiceOptions
;
23 use MediaWiki\Linker\LinkRendererFactory
;
24 use MediaWiki\MediaWikiServices
;
25 use MediaWiki\Special\SpecialPageFactory
;
31 /** @var ServiceOptions */
34 /** @var MagicWordFactory */
35 private $magicWordFactory;
41 private $urlProtocols;
43 /** @var SpecialPageFactory */
44 private $specialPageFactory;
46 /** @var LinkRendererFactory */
47 private $linkRendererFactory;
49 /** @var NamespaceInfo */
53 * Old parameter list, which we support for backwards compatibility, were:
54 * array $parserConf See $wgParserConf documentation
55 * MagicWordFactory $magicWordFactory
56 * Language $contLang Content language
57 * string $urlProtocols As returned from wfUrlProtocols()
58 * SpecialPageFactory $spFactory
60 * LinkRendererFactory $linkRendererFactory
61 * NamespaceInfo|null $nsInfo
63 * Some type declarations were intentionally omitted so that the backwards compatibility code
64 * would work. When backwards compatibility is no longer required, we should remove it, and
65 * and add the omitted type declarations.
67 * @param ServiceOptions|array $svcOptions
68 * @param MagicWordFactory $magicWordFactory
69 * @param Language $contLang Content language
70 * @param string $urlProtocols As returned from wfUrlProtocols()
71 * @param SpecialPageFactory $spFactory
72 * @param LinkRendererFactory $linkRendererFactory
73 * @param NamespaceInfo|LinkRendererFactory|null $nsInfo
76 public function __construct(
77 $svcOptions, MagicWordFactory
$magicWordFactory, Language
$contLang,
78 $urlProtocols, SpecialPageFactory
$spFactory, $linkRendererFactory,
81 // @todo Do we need to retain compat for constructing this class directly?
83 wfDeprecated( __METHOD__
. ' with no NamespaceInfo argument', '1.34' );
84 $nsInfo = MediaWikiServices
::getInstance()->getNamespaceInfo();
86 if ( $linkRendererFactory instanceof Config
) {
87 // Old calling convention had an array in the format of $wgParserConf as the first
88 // parameter, and a Config as the sixth, with LinkRendererFactory as the seventh.
89 wfDeprecated( __METHOD__
. ' with Config parameter', '1.34' );
90 $svcOptions = new ServiceOptions( Parser
::$constructorOptions,
92 [ 'class' => Parser
::class,
93 'preprocessorClass' => Parser
::getDefaultPreprocessorClass() ],
96 $linkRendererFactory = func_get_arg( 6 );
97 $nsInfo = func_num_args() > 7 ?
func_get_arg( 7 ) : null;
99 $svcOptions->assertRequiredOptions( Parser
::$constructorOptions );
101 wfDebug( __CLASS__
. ": using preprocessor: {$svcOptions->get( 'preprocessorClass' )}\n" );
103 $this->svcOptions
= $svcOptions;
104 $this->magicWordFactory
= $magicWordFactory;
105 $this->contLang
= $contLang;
106 $this->urlProtocols
= $urlProtocols;
107 $this->specialPageFactory
= $spFactory;
108 $this->linkRendererFactory
= $linkRendererFactory;
109 $this->nsInfo
= $nsInfo;
116 public function create() : Parser
{
117 return new Parser( $this->svcOptions
, $this->magicWordFactory
, $this->contLang
, $this,
118 $this->urlProtocols
, $this->specialPageFactory
, $this->linkRendererFactory
,