Update git submodules
[mediawiki.git] / includes / preferences / SignatureValidatorFactory.php
blob176eda78a4867515f0d4c4ee92e8f3158c4ba76b
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.
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
18 * @file
19 * @author Derick Alangi
22 namespace MediaWiki\Preferences;
24 use MediaWiki\Config\ServiceOptions;
25 use MediaWiki\Parser\Parsoid\Config\PageConfigFactory;
26 use MediaWiki\SpecialPage\SpecialPageFactory;
27 use MediaWiki\Title\TitleFactory;
28 use MediaWiki\User\UserIdentity;
29 use MessageLocalizer;
30 use ParserOptions;
32 /**
33 * @since 1.38
35 class SignatureValidatorFactory {
36 /** @var ServiceOptions */
37 private $serviceOptions;
39 /** @var callable */
40 private $parserFactoryClosure;
42 /** @var callable */
43 private $parsoidClosure;
45 private PageConfigFactory $pageConfigFactory;
47 /** @var SpecialPageFactory */
48 private $specialPageFactory;
50 /** @var TitleFactory */
51 private $titleFactory;
53 /**
54 * @param ServiceOptions $options
55 * @param callable $parserFactoryClosure A function which returns a ParserFactory.
56 * We use this instead of an actual ParserFactory to avoid a circular dependency,
57 * since Parser also needs a SignatureValidatorFactory for signature formatting.
58 * @param callable $parsoidClosure A function which returns a Parsoid, same as above.
59 * @param PageConfigFactory $pageConfigFactory
60 * @param SpecialPageFactory $specialPageFactory
61 * @param TitleFactory $titleFactory
63 public function __construct(
64 ServiceOptions $options,
65 callable $parserFactoryClosure,
66 callable $parsoidClosure,
67 PageConfigFactory $pageConfigFactory,
68 SpecialPageFactory $specialPageFactory,
69 TitleFactory $titleFactory
70 ) {
71 // Configuration
72 $this->serviceOptions = $options;
73 $this->serviceOptions->assertRequiredOptions( SignatureValidator::CONSTRUCTOR_OPTIONS );
74 $this->parserFactoryClosure = $parserFactoryClosure;
75 $this->parsoidClosure = $parsoidClosure;
76 $this->pageConfigFactory = $pageConfigFactory;
77 $this->specialPageFactory = $specialPageFactory;
78 $this->titleFactory = $titleFactory;
81 /**
82 * @param UserIdentity $user
83 * @param MessageLocalizer|null $localizer
84 * @param ParserOptions $popts
85 * @return SignatureValidator
87 public function newSignatureValidator(
88 UserIdentity $user,
89 ?MessageLocalizer $localizer,
90 ParserOptions $popts
91 ): SignatureValidator {
92 return new SignatureValidator(
93 $this->serviceOptions,
94 $user,
95 $localizer,
96 $popts,
97 ( $this->parserFactoryClosure )(),
98 ( $this->parsoidClosure )(),
99 $this->pageConfigFactory,
100 $this->specialPageFactory,
101 $this->titleFactory