Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ImageRecommendationTaskTypeHandler | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
createTaskType | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
getSearchTerm | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getSubmitDataFormatMessage | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\TaskType; |
4 | |
5 | use GrowthExperiments\NewcomerTasks\AddImage\AddImageSubmissionHandler; |
6 | use InvalidArgumentException; |
7 | use LogicException; |
8 | use Message; |
9 | use MessageLocalizer; |
10 | use MessageSpecifier; |
11 | |
12 | class ImageRecommendationTaskTypeHandler extends ImageRecommendationBaseTaskTypeHandler { |
13 | |
14 | public const ID = 'image-recommendation'; |
15 | |
16 | public const TASK_TYPE_ID = 'image-recommendation'; |
17 | |
18 | public const CHANGE_TAG = 'newcomer task image suggestion'; |
19 | |
20 | /** The tag prefix used for CirrusSearch\Wikimedia\WeightedTags. */ |
21 | public const WEIGHTED_TAG_PREFIX = 'recommendation.image'; |
22 | |
23 | /** @inheritDoc */ |
24 | public function createTaskType( string $taskTypeId, array $config ): ImageRecommendationTaskType { |
25 | $extraData = [ 'learnMoreLink' => $config['learnmore'] ?? null ]; |
26 | $settings = array_intersect_key( $config, ImageRecommendationTaskType::DEFAULT_SETTINGS ); |
27 | $taskType = new ImageRecommendationTaskType( |
28 | $taskTypeId, |
29 | $config['group'], |
30 | $settings, |
31 | $extraData, |
32 | $this->parseExcludedTemplates( $config ), |
33 | $this->parseExcludedCategories( $config ) |
34 | ); |
35 | $taskType->setHandlerId( $this->getId() ); |
36 | return $taskType; |
37 | } |
38 | |
39 | /** @inheritDoc */ |
40 | public function getSearchTerm( TaskType $taskType ): string { |
41 | if ( $taskType->getHandlerId() !== self::ID ) { |
42 | throw new InvalidArgumentException( '$taskType must be an image recommendation task type' ); |
43 | } |
44 | return parent::getSearchTerm( $taskType ) . 'hasrecommendation:image -hastemplatecollection:infobox'; |
45 | } |
46 | |
47 | /** @inheritDoc */ |
48 | public function getSubmitDataFormatMessage( |
49 | TaskType $taskType, |
50 | MessageLocalizer $localizer |
51 | ): MessageSpecifier { |
52 | if ( !( $taskType instanceof ImageRecommendationTaskType ) ) { |
53 | throw new LogicException( 'impossible' ); |
54 | } |
55 | $wrappedReasons = array_map( |
56 | fn ( $reason ) => "<kbd>$reason</kbd>", |
57 | AddImageSubmissionHandler::REJECTION_REASONS |
58 | ); |
59 | return $localizer->msg( |
60 | 'apihelp-growthexperiments-structured-task-submit-data-format-image-recommendation', |
61 | Message::listParam( $wrappedReasons, 'comma' ), |
62 | Message::numParam( $taskType->getMinimumCaptionCharacterLength() ) |
63 | ); |
64 | } |
65 | |
66 | } |