Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
70.59% |
36 / 51 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
ConfigFactory | |
70.59% |
36 / 51 |
|
75.00% |
3 / 4 |
6.92 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
newRequestConfig | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
newGlobalConfig | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
newCampaignConfig | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\MediaUploader\Config; |
4 | |
5 | use JobQueueGroup; |
6 | use Language; |
7 | use MediaWiki\Cache\LinkBatchFactory; |
8 | use MediaWiki\Config\ServiceOptions; |
9 | use MediaWiki\Extension\MediaUploader\Campaign\CampaignRecord; |
10 | use MediaWiki\Extension\MediaUploader\Campaign\CampaignStore; |
11 | use MediaWiki\Extension\MediaUploader\Campaign\Exception\BaseCampaignException; |
12 | use MediaWiki\Languages\LanguageNameUtils; |
13 | use MediaWiki\Page\PageReference; |
14 | use MediaWiki\User\UserOptionsLookup; |
15 | use ParserOptions; |
16 | use WANObjectCache; |
17 | |
18 | /** |
19 | * Constructs GlobalParsedConfig and CampaignParsedConfig objects. |
20 | */ |
21 | class ConfigFactory { |
22 | |
23 | /** @var WANObjectCache */ |
24 | private $cache; |
25 | |
26 | /** @var UserOptionsLookup */ |
27 | private $userOptionsLookup; |
28 | |
29 | /** @var LanguageNameUtils */ |
30 | private $languageNameUtils; |
31 | |
32 | /** @var Language */ |
33 | private $contentLanguage; |
34 | |
35 | /** @var LinkBatchFactory */ |
36 | private $linkBatchFactory; |
37 | |
38 | /** @var JobQueueGroup */ |
39 | private $jobQueueGroup; |
40 | |
41 | /** @var RawConfig */ |
42 | private $rawGlobalConfig; |
43 | |
44 | /** @var ConfigParserFactory */ |
45 | private $configParserFactory; |
46 | |
47 | /** @var ConfigCacheInvalidator */ |
48 | private $configCacheInvalidator; |
49 | |
50 | /** |
51 | * @param WANObjectCache $cache |
52 | * @param UserOptionsLookup $userOptionsLookup |
53 | * @param LanguageNameUtils $languageNameUtils |
54 | * @param Language $contentLanguage |
55 | * @param LinkBatchFactory $linkBatchFactory |
56 | * @param JobQueueGroup $jobQueueGroup |
57 | * @param RawConfig $rawGlobalConfig |
58 | * @param ConfigParserFactory $configParserFactory |
59 | * @param ConfigCacheInvalidator $cacheInvalidator |
60 | * |
61 | * @internal Only for use by ServiceWiring |
62 | */ |
63 | public function __construct( |
64 | WANObjectCache $cache, |
65 | UserOptionsLookup $userOptionsLookup, |
66 | LanguageNameUtils $languageNameUtils, |
67 | Language $contentLanguage, |
68 | LinkBatchFactory $linkBatchFactory, |
69 | JobQueueGroup $jobQueueGroup, |
70 | RawConfig $rawGlobalConfig, |
71 | ConfigParserFactory $configParserFactory, |
72 | ConfigCacheInvalidator $cacheInvalidator |
73 | ) { |
74 | $this->cache = $cache; |
75 | $this->userOptionsLookup = $userOptionsLookup; |
76 | $this->languageNameUtils = $languageNameUtils; |
77 | $this->contentLanguage = $contentLanguage; |
78 | $this->linkBatchFactory = $linkBatchFactory; |
79 | $this->jobQueueGroup = $jobQueueGroup; |
80 | $this->rawGlobalConfig = $rawGlobalConfig; |
81 | $this->configParserFactory = $configParserFactory; |
82 | $this->configCacheInvalidator = $cacheInvalidator; |
83 | } |
84 | |
85 | /** |
86 | * @param Language $language |
87 | * |
88 | * @return RequestConfig |
89 | */ |
90 | private function newRequestConfig( Language $language ): RequestConfig { |
91 | return new RequestConfig( |
92 | $this->cache, |
93 | $this->languageNameUtils, |
94 | $this->linkBatchFactory, |
95 | $language, |
96 | $this->rawGlobalConfig |
97 | ); |
98 | } |
99 | |
100 | /** |
101 | * Returns the global parsed config. |
102 | * |
103 | * @param ParserOptions $parserOptions |
104 | * @param array $urlOverrides URL parameter overrides in the form of an |
105 | * associative array. Use with caution and do not pass unvalidated user |
106 | * input. |
107 | * @param bool $noCache Whether to ignore config cache |
108 | * |
109 | * @return GlobalParsedConfig |
110 | */ |
111 | public function newGlobalConfig( |
112 | ParserOptions $parserOptions, |
113 | array $urlOverrides = [], |
114 | bool $noCache = false |
115 | ): GlobalParsedConfig { |
116 | $language = $parserOptions->getTargetLanguage() ?: $this->contentLanguage; |
117 | return new GlobalParsedConfig( |
118 | $this->cache, |
119 | $this->userOptionsLookup, |
120 | $this->configCacheInvalidator, |
121 | $parserOptions, |
122 | $this->configParserFactory, |
123 | $this->newRequestConfig( $language ), |
124 | $this->jobQueueGroup, |
125 | $urlOverrides, |
126 | new ServiceOptions( |
127 | ParsedConfig::CONSTRUCTOR_OPTIONS, |
128 | [ ParsedConfig::NO_CACHE => $noCache ] |
129 | ) |
130 | ); |
131 | } |
132 | |
133 | /** |
134 | * Returns the parsed config of a campaign. |
135 | * |
136 | * @param ParserOptions $parserOptions |
137 | * @param CampaignRecord $campaignRecord |
138 | * @param PageReference $campaignPage |
139 | * @param array $urlOverrides URL parameter overrides in the form of an |
140 | * associative array. Use with caution and do not pass unvalidated user |
141 | * input. |
142 | * @param bool $noCache Whether to ignore config cache |
143 | * |
144 | * @return CampaignParsedConfig |
145 | * @throws BaseCampaignException |
146 | */ |
147 | public function newCampaignConfig( |
148 | ParserOptions $parserOptions, |
149 | CampaignRecord $campaignRecord, |
150 | PageReference $campaignPage, |
151 | array $urlOverrides = [], |
152 | bool $noCache = false |
153 | ): CampaignParsedConfig { |
154 | $campaignRecord->assertValid( |
155 | $campaignPage->getDBkey(), |
156 | CampaignStore::SELECT_CONTENT |
157 | ); |
158 | |
159 | $language = $parserOptions->getTargetLanguage() ?: $this->contentLanguage; |
160 | return new CampaignParsedConfig( |
161 | $this->cache, |
162 | $this->userOptionsLookup, |
163 | $this->configCacheInvalidator, |
164 | $parserOptions, |
165 | $this->configParserFactory, |
166 | $this->newRequestConfig( $language ), |
167 | $urlOverrides, |
168 | $campaignRecord, |
169 | $campaignPage, |
170 | new ServiceOptions( |
171 | ParsedConfig::CONSTRUCTOR_OPTIONS, |
172 | [ ParsedConfig::NO_CACHE => $noCache ] |
173 | ) |
174 | ); |
175 | } |
176 | } |