Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
31 / 31 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
BeforePageDisplayHookHandler | |
100.00% |
31 / 31 |
|
100.00% |
2 / 2 |
11 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
onBeforePageDisplay | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
10 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\SurfacingStructuredTasks; |
4 | |
5 | use GrowthExperiments\NewcomerTasks\ConfigurationLoader\ConfigurationLoader; |
6 | use GrowthExperiments\NewcomerTasks\TaskType\LinkRecommendationTaskTypeHandler; |
7 | use GrowthExperiments\Util; |
8 | use MediaWiki\Config\Config; |
9 | use MediaWiki\Output\Hook\BeforePageDisplayHook; |
10 | |
11 | class BeforePageDisplayHookHandler implements BeforePageDisplayHook { |
12 | |
13 | private Config $config; |
14 | private ConfigurationLoader $configurationLoader; |
15 | |
16 | public function __construct( |
17 | Config $config, |
18 | ConfigurationLoader $configurationLoader |
19 | ) { |
20 | $this->config = $config; |
21 | $this->configurationLoader = $configurationLoader; |
22 | } |
23 | |
24 | /** |
25 | * @inheritDoc |
26 | */ |
27 | public function onBeforePageDisplay( $out, $skin ): void { |
28 | if ( !$this->config->get( 'GESurfacingStructuredTasksEnabled' ) ) { |
29 | return; |
30 | } |
31 | |
32 | $user = $out->getUser(); |
33 | if ( !$user->isNamed() ) { |
34 | return; |
35 | } |
36 | |
37 | $page = $out->getTitle(); |
38 | if ( !$page || $page->getNamespace() !== NS_MAIN ) { |
39 | return; |
40 | } |
41 | |
42 | $action = $out->getRequest()->getVal( 'action', 'view' ); |
43 | if ( $action !== 'view' ) { |
44 | return; |
45 | } |
46 | |
47 | $veaction = $out->getRequest()->getVal( 'veaction', null ); |
48 | if ( $veaction !== null ) { |
49 | return; |
50 | } |
51 | |
52 | if ( !Util::isMobile( $skin ) ) { |
53 | return; |
54 | } |
55 | |
56 | if ( $user->getEditCount() !== 0 ) { |
57 | return; |
58 | } |
59 | |
60 | $taskTypes = $this->configurationLoader->getTaskTypes(); |
61 | if ( !isset( $taskTypes[LinkRecommendationTaskTypeHandler::TASK_TYPE_ID] ) ) { |
62 | return; |
63 | } |
64 | |
65 | $linkRecommendationTaskType = $taskTypes[LinkRecommendationTaskTypeHandler::TASK_TYPE_ID]; |
66 | '@phan-var \GrowthExperiments\NewcomerTasks\TaskType\LinkRecommendationTaskType $linkRecommendationTaskType'; |
67 | |
68 | $maxLinks = $linkRecommendationTaskType->getMaximumLinksToShowPerTask(); |
69 | $minScore = $linkRecommendationTaskType->getMinimumLinkScore(); |
70 | $out->addJsConfigVars( 'wgGrowthExperimentsLinkRecommendationTask', [ |
71 | 'maxLinks' => $maxLinks, |
72 | 'minScore' => $minScore, |
73 | ] ); |
74 | $out->addModules( 'ext.growthExperiments.StructuredTask.Surfacing' ); |
75 | } |
76 | } |