Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
16.67% |
3 / 18 |
|
16.67% |
1 / 6 |
CRAP | |
0.00% |
0 / 1 |
PageConfigurationLoader | |
16.67% |
3 / 18 |
|
16.67% |
1 / 6 |
81.02 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
makeTitle | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
loadTaskTypesConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadTopicsConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadTopics | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
loadInfoboxTemplates | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\ConfigurationLoader; |
4 | |
5 | use GrowthExperiments\Config\WikiPageConfigLoader; |
6 | use GrowthExperiments\NewcomerTasks\TaskType\TaskTypeHandlerRegistry; |
7 | use GrowthExperiments\Util; |
8 | use LogicException; |
9 | use MediaWiki\Config\Config; |
10 | use MediaWiki\Linker\LinkTarget; |
11 | use MediaWiki\Title\TitleFactory; |
12 | |
13 | class PageConfigurationLoader extends AbstractDataConfigurationLoader { |
14 | |
15 | private TitleFactory $titleFactory; |
16 | private WikiPageConfigLoader $configLoader; |
17 | |
18 | /** @var LinkTarget|string */ |
19 | private $taskConfigurationPage; |
20 | |
21 | /** @var LinkTarget|string|null */ |
22 | private $topicConfigurationPage; |
23 | |
24 | /** @var Config */ |
25 | private Config $growthConfig; |
26 | |
27 | /** |
28 | * @param ConfigurationValidator $configurationValidator |
29 | * @param TaskTypeHandlerRegistry $taskTypeHandlerRegistry |
30 | * @param string $topicType |
31 | * @param TitleFactory $titleFactory |
32 | * @param WikiPageConfigLoader $configLoader |
33 | * @param string|LinkTarget $taskConfigurationPage Wiki page to load task configuration from |
34 | * (local or interwiki). |
35 | * @param string|LinkTarget|null $topicConfigurationPage Wiki page to load task configuration from |
36 | * (local or interwiki). Can be omitted, in which case topic matching will be disabled. |
37 | * @param Config $growthConfig |
38 | */ |
39 | public function __construct( |
40 | ConfigurationValidator $configurationValidator, |
41 | TaskTypeHandlerRegistry $taskTypeHandlerRegistry, |
42 | string $topicType, |
43 | TitleFactory $titleFactory, |
44 | WikiPageConfigLoader $configLoader, |
45 | $taskConfigurationPage, |
46 | $topicConfigurationPage, |
47 | Config $growthConfig |
48 | ) { |
49 | parent::__construct( $configurationValidator, $taskTypeHandlerRegistry, $topicType ); |
50 | |
51 | $this->titleFactory = $titleFactory; |
52 | $this->configLoader = $configLoader; |
53 | $this->taskConfigurationPage = $taskConfigurationPage; |
54 | $this->topicConfigurationPage = $topicConfigurationPage; |
55 | $this->growthConfig = $growthConfig; |
56 | } |
57 | |
58 | /** |
59 | * @param string|LinkTarget|null $target |
60 | * @return LinkTarget|null |
61 | */ |
62 | private function makeTitle( $target ) { |
63 | if ( is_string( $target ) ) { |
64 | $target = $this->titleFactory->newFromText( $target ); |
65 | } |
66 | if ( $target && !$target->isExternal() && !$target->inNamespace( NS_MEDIAWIKI ) ) { |
67 | Util::logException( new LogicException( 'Configuration page not in NS_MEDIAWIKI' ), |
68 | [ 'title' => $target->__toString() ] ); |
69 | } |
70 | return $target; |
71 | } |
72 | |
73 | /** |
74 | * @inheritDoc |
75 | */ |
76 | protected function loadTaskTypesConfig() { |
77 | return $this->configLoader->load( $this->makeTitle( $this->taskConfigurationPage ) ); |
78 | } |
79 | |
80 | /** |
81 | * @inheritDoc |
82 | */ |
83 | protected function loadTopicsConfig() { |
84 | return $this->configLoader->load( $this->makeTitle( $this->topicConfigurationPage ) ); |
85 | } |
86 | |
87 | /** |
88 | * @inheritDoc |
89 | */ |
90 | public function loadTopics() { |
91 | if ( $this->topicConfigurationPage === null ) { |
92 | // NOTE: This has to be here, rather than loadTopicsConfig(), as empty data does not |
93 | // pass validation tests in the parent. |
94 | return []; |
95 | } |
96 | |
97 | return parent::loadTopics(); |
98 | } |
99 | |
100 | /** |
101 | * @inheritDoc |
102 | */ |
103 | public function loadInfoboxTemplates() { |
104 | return $this->growthConfig->get( 'GEInfoboxTemplates' ); |
105 | } |
106 | } |