Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[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
22 use MediaWiki\Config\ServiceOptions;
23 use MediaWiki\Linker\LinkRendererFactory;
24 use MediaWiki\MediaWikiServices;
25 use MediaWiki\Special\SpecialPageFactory;
26
27 /**
28 * @since 1.32
29 */
30 class ParserFactory {
31 /** @var ServiceOptions */
32 private $svcOptions;
33
34 /** @var MagicWordFactory */
35 private $magicWordFactory;
36
37 /** @var Language */
38 private $contLang;
39
40 /** @var string */
41 private $urlProtocols;
42
43 /** @var SpecialPageFactory */
44 private $specialPageFactory;
45
46 /** @var LinkRendererFactory */
47 private $linkRendererFactory;
48
49 /** @var NamespaceInfo */
50 private $nsInfo;
51
52 /**
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
59 * Config $siteConfig
60 * LinkRendererFactory $linkRendererFactory
61 * NamespaceInfo|null $nsInfo
62 *
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.
66 *
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
74 * @since 1.32
75 */
76 public function __construct(
77 $svcOptions, MagicWordFactory $magicWordFactory, Language $contLang,
78 $urlProtocols, SpecialPageFactory $spFactory, $linkRendererFactory,
79 $nsInfo = null
80 ) {
81 // @todo Do we need to retain compat for constructing this class directly?
82 if ( !$nsInfo ) {
83 wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' );
84 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
85 }
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,
91 $svcOptions,
92 [ 'class' => Parser::class,
93 'preprocessorClass' => Parser::getDefaultPreprocessorClass() ],
94 func_get_arg( 5 )
95 );
96 $linkRendererFactory = func_get_arg( 6 );
97 $nsInfo = func_num_args() > 7 ? func_get_arg( 7 ) : null;
98 }
99 $svcOptions->assertRequiredOptions( Parser::$constructorOptions );
100
101 wfDebug( __CLASS__ . ": using preprocessor: {$svcOptions->get( 'preprocessorClass' )}\n" );
102
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;
110 }
111
112 /**
113 * @return Parser
114 * @since 1.32
115 */
116 public function create() : Parser {
117 return new Parser( $this->svcOptions, $this->magicWordFactory, $this->contLang, $this,
118 $this->urlProtocols, $this->specialPageFactory, $this->linkRendererFactory,
119 $this->nsInfo );
120 }
121 }