Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
28.57% |
8 / 28 |
|
44.44% |
4 / 9 |
CRAP | |
0.00% |
0 / 1 |
LinkRecommendationTaskTypeHandler | |
28.57% |
8 / 28 |
|
44.44% |
4 / 9 |
55.10 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRecommendationProvider | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSubmissionHandler | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createTaskType | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
getSearchTerm | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getChangeTags | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTaskTypeIdByChangeTagName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getSubmitDataFormatMessage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\TaskType; |
4 | |
5 | use GrowthExperiments\NewcomerTasks\AddLink\AddLinkSubmissionHandler; |
6 | use GrowthExperiments\NewcomerTasks\AddLink\LinkRecommendationProvider; |
7 | use GrowthExperiments\NewcomerTasks\ConfigurationLoader\ConfigurationValidator; |
8 | use GrowthExperiments\NewcomerTasks\RecommendationProvider; |
9 | use GrowthExperiments\NewcomerTasks\SubmissionHandler; |
10 | use InvalidArgumentException; |
11 | use LogicException; |
12 | use MediaWiki\Title\TitleParser; |
13 | use MessageLocalizer; |
14 | use Wikimedia\Message\MessageSpecifier; |
15 | |
16 | class LinkRecommendationTaskTypeHandler extends StructuredTaskTypeHandler { |
17 | |
18 | public const ID = 'link-recommendation'; |
19 | |
20 | public const TASK_TYPE_ID = 'link-recommendation'; |
21 | |
22 | public const CHANGE_TAG = 'newcomer task add link'; |
23 | |
24 | /** The tag prefix used for CirrusSearch\Wikimedia\WeightedTags. */ |
25 | public const WEIGHTED_TAG_PREFIX = 'recommendation.link'; |
26 | |
27 | private LinkRecommendationProvider $recommendationProvider; |
28 | private AddLinkSubmissionHandler $submissionHandler; |
29 | |
30 | /** |
31 | * @param ConfigurationValidator $configurationValidator |
32 | * @param TitleParser $titleParser |
33 | * @param LinkRecommendationProvider $recommendationProvider |
34 | * @param AddLinkSubmissionHandler $submissionHandler |
35 | */ |
36 | public function __construct( |
37 | ConfigurationValidator $configurationValidator, |
38 | TitleParser $titleParser, |
39 | LinkRecommendationProvider $recommendationProvider, |
40 | AddLinkSubmissionHandler $submissionHandler |
41 | ) { |
42 | parent::__construct( $configurationValidator, $titleParser ); |
43 | $this->recommendationProvider = $recommendationProvider; |
44 | $this->submissionHandler = $submissionHandler; |
45 | } |
46 | |
47 | /** @inheritDoc */ |
48 | public function getId(): string { |
49 | return self::ID; |
50 | } |
51 | |
52 | /** |
53 | * @inheritDoc |
54 | * @return LinkRecommendationProvider |
55 | */ |
56 | public function getRecommendationProvider(): RecommendationProvider { |
57 | return $this->recommendationProvider; |
58 | } |
59 | |
60 | /** |
61 | * @inheritDoc |
62 | * @return AddLinkSubmissionHandler |
63 | */ |
64 | public function getSubmissionHandler(): SubmissionHandler { |
65 | return $this->submissionHandler; |
66 | } |
67 | |
68 | /** @inheritDoc */ |
69 | public function createTaskType( string $taskTypeId, array $config ): TaskType { |
70 | $extraData = [ 'learnMoreLink' => $config['learnmore'] ?? null ]; |
71 | // FIXME add settings validation |
72 | $settings = array_intersect_key( $config, LinkRecommendationTaskType::DEFAULT_SETTINGS ); |
73 | |
74 | $taskType = new LinkRecommendationTaskType( |
75 | $taskTypeId, |
76 | $config['group'], |
77 | $settings, |
78 | $extraData, |
79 | $this->parseExcludedTemplates( $config ), |
80 | $this->parseExcludedCategories( $config ) |
81 | ); |
82 | $taskType->setHandlerId( $this->getId() ); |
83 | return $taskType; |
84 | } |
85 | |
86 | /** @inheritDoc */ |
87 | public function getSearchTerm( TaskType $taskType ): string { |
88 | if ( $taskType->getHandlerId() !== self::ID ) { |
89 | throw new InvalidArgumentException( '$taskType must be a link recommendation task type' ); |
90 | } |
91 | return parent::getSearchTerm( $taskType ) . 'hasrecommendation:link'; |
92 | } |
93 | |
94 | /** @inheritDoc */ |
95 | public function getChangeTags( ?string $taskType = null ): array { |
96 | return [ TaskTypeHandler::NEWCOMER_TASK_TAG, self::CHANGE_TAG ]; |
97 | } |
98 | |
99 | /** @inheritDoc */ |
100 | public function getTaskTypeIdByChangeTagName( string $changeTagName ): ?string { |
101 | if ( $changeTagName !== self::CHANGE_TAG ) { |
102 | throw new LogicException( "\"$changeTagName\" is not a valid change tag name for " . self::class ); |
103 | } |
104 | return self::TASK_TYPE_ID; |
105 | } |
106 | |
107 | /** @inheritDoc */ |
108 | public function getSubmitDataFormatMessage( |
109 | TaskType $taskType, |
110 | MessageLocalizer $localizer |
111 | ): MessageSpecifier { |
112 | return $localizer->msg( |
113 | 'apihelp-growthexperiments-structured-task-submit-data-format-link-recommendation' |
114 | ); |
115 | } |
116 | |
117 | } |