Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
9 / 10
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GrowthArticleTopicFeature
90.00% covered (success)
90.00%
9 / 10
50.00% covered (danger)
50.00%
1 / 2
3.01
0.00% covered (danger)
0.00%
0 / 1
 parseValue
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
 getKeywords
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\NewcomerTasks;
4
5use CirrusSearch\Query\ArticleTopicFeature;
6use CirrusSearch\WarningCollector;
7use MediaWiki\Message\Message;
8
9/**
10 * Implementation of growtharticletopic: keyword which is similar to articletopic: but
11 * uses custom tags which are managed manually.
12 * FIXME This is a hack that will be removed once the feature is not needed; see T301030.
13 */
14class GrowthArticleTopicFeature extends ArticleTopicFeature {
15
16    public const KEYWORD = 'growtharticletopic';
17
18    public const TAG_PREFIX = 'classification.oneoff.T301028';
19
20    /** @inheritDoc */
21    public function parseValue(
22        $key, $value, $quotedValue, $valueDelimiter, $suffix, WarningCollector $warningCollector
23    ) {
24        $topics = explode( '|', $value );
25        $validTopics = array_filter( $topics, static function ( string $topic ) {
26            return preg_match( '/^[a-zA-Z0-9-_]+$/', $topic );
27        } );
28        $invalidTopics = array_diff( $topics, $validTopics );
29
30        if ( $invalidTopics ) {
31            $warningCollector->addWarning( 'growthexperiments-homepage-suggestededits-articletopic-invalid-topic',
32                Message::listParam( $invalidTopics, 'comma' ), count( $invalidTopics ) );
33        }
34        return [ 'topics' => $validTopics, 'tag_prefix' => self::TAG_PREFIX ];
35    }
36
37    /** @inheritDoc */
38    public function getKeywords() {
39        return [ self::KEYWORD ];
40    }
41
42}