Split parser related files to have one class in one file
[lhc/web/wiklou.git] / includes / parser / ParserFactory.php
1 <?php
2 /**
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @ingroup Parser
20 */
21 use MediaWiki\Linker\LinkRendererFactory;
22 use MediaWiki\MediaWikiServices;
23 use MediaWiki\Special\SpecialPageFactory;
24
25 /**
26 * @since 1.32
27 */
28 class ParserFactory {
29 /** @var array */
30 private $parserConf;
31
32 /** @var MagicWordFactory */
33 private $magicWordFactory;
34
35 /** @var Language */
36 private $contLang;
37
38 /** @var string */
39 private $urlProtocols;
40
41 /** @var SpecialPageFactory */
42 private $specialPageFactory;
43
44 /** @var Config */
45 private $siteConfig;
46
47 /** @var LinkRendererFactory */
48 private $linkRendererFactory;
49
50 /** @var NamespaceInfo */
51 private $nsInfo;
52
53 /**
54 * @param array $parserConf See $wgParserConf documentation
55 * @param MagicWordFactory $magicWordFactory
56 * @param Language $contLang Content language
57 * @param string $urlProtocols As returned from wfUrlProtocols()
58 * @param SpecialPageFactory $spFactory
59 * @param Config $siteConfig
60 * @param LinkRendererFactory $linkRendererFactory
61 * @param NamespaceInfo|null $nsInfo
62 * @since 1.32
63 */
64 public function __construct(
65 array $parserConf, MagicWordFactory $magicWordFactory, Language $contLang, $urlProtocols,
66 SpecialPageFactory $spFactory, Config $siteConfig,
67 LinkRendererFactory $linkRendererFactory, NamespaceInfo $nsInfo = null
68 ) {
69 if ( !$nsInfo ) {
70 wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' );
71 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
72 }
73 $this->parserConf = $parserConf;
74 $this->magicWordFactory = $magicWordFactory;
75 $this->contLang = $contLang;
76 $this->urlProtocols = $urlProtocols;
77 $this->specialPageFactory = $spFactory;
78 $this->siteConfig = $siteConfig;
79 $this->linkRendererFactory = $linkRendererFactory;
80 $this->nsInfo = $nsInfo;
81 }
82
83 /**
84 * @return Parser
85 * @since 1.32
86 */
87 public function create() : Parser {
88 return new Parser( $this->parserConf, $this->magicWordFactory, $this->contLang, $this,
89 $this->urlProtocols, $this->specialPageFactory, $this->siteConfig,
90 $this->linkRendererFactory, $this->nsInfo );
91 }
92 }