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