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
;
26 use Psr\Log\LoggerInterface
;
27 use Psr\Log\NullLogger
;
33 /** @var ServiceOptions */
36 /** @var MagicWordFactory */
37 private $magicWordFactory;
43 private $urlProtocols;
45 /** @var SpecialPageFactory */
46 private $specialPageFactory;
48 /** @var LinkRendererFactory */
49 private $linkRendererFactory;
51 /** @var NamespaceInfo */
54 /** @var LoggerInterface */
58 * Old parameter list, which we support for backwards compatibility, were:
59 * array $parserConf See $wgParserConf documentation
60 * MagicWordFactory $magicWordFactory
61 * Language $contLang Content language
62 * string $urlProtocols As returned from wfUrlProtocols()
63 * SpecialPageFactory $spFactory
65 * LinkRendererFactory $linkRendererFactory
66 * NamespaceInfo|null $nsInfo
68 * Some type declarations were intentionally omitted so that the backwards compatibility code
69 * would work. When backwards compatibility is no longer required, we should remove it, and
70 * and add the omitted type declarations.
72 * @param ServiceOptions|array $svcOptions
73 * @param MagicWordFactory $magicWordFactory
74 * @param Language $contLang Content language
75 * @param string $urlProtocols As returned from wfUrlProtocols()
76 * @param SpecialPageFactory $spFactory
77 * @param LinkRendererFactory $linkRendererFactory
78 * @param NamespaceInfo|LinkRendererFactory|null $nsInfo
79 * @param LoggerInterface|null $logger
82 public function __construct(
84 MagicWordFactory
$magicWordFactory,
87 SpecialPageFactory
$spFactory,
92 // @todo Do we need to retain compat for constructing this class directly?
94 wfDeprecated( __METHOD__
. ' with no NamespaceInfo argument', '1.34' );
95 $nsInfo = MediaWikiServices
::getInstance()->getNamespaceInfo();
97 if ( $linkRendererFactory instanceof Config
) {
98 // Old calling convention had an array in the format of $wgParserConf as the first
99 // parameter, and a Config as the sixth, with LinkRendererFactory as the seventh.
100 wfDeprecated( __METHOD__
. ' with Config parameter', '1.34' );
101 $svcOptions = new ServiceOptions( Parser
::$constructorOptions,
103 [ 'class' => Parser
::class,
104 'preprocessorClass' => Parser
::getDefaultPreprocessorClass() ],
107 $linkRendererFactory = func_get_arg( 6 );
108 $nsInfo = func_num_args() > 7 ?
func_get_arg( 7 ) : null;
110 $svcOptions->assertRequiredOptions( Parser
::$constructorOptions );
112 wfDebug( __CLASS__
. ": using preprocessor: {$svcOptions->get( 'preprocessorClass' )}\n" );
114 $this->svcOptions
= $svcOptions;
115 $this->magicWordFactory
= $magicWordFactory;
116 $this->contLang
= $contLang;
117 $this->urlProtocols
= $urlProtocols;
118 $this->specialPageFactory
= $spFactory;
119 $this->linkRendererFactory
= $linkRendererFactory;
120 $this->nsInfo
= $nsInfo;
121 $this->logger
= $logger ?
: new NullLogger();
128 public function create() : Parser
{
131 $this->magicWordFactory
,
135 $this->specialPageFactory
,
136 $this->linkRendererFactory
,