Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
88.89% |
8 / 9 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
CampaignTopic | |
88.89% |
8 / 9 |
|
80.00% |
4 / 5 |
5.03 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getSearchExpression | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toJsonArray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
newFromJsonArray | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\Topic; |
4 | |
5 | use MediaWiki\Json\JsonUnserializer; |
6 | use MediaWiki\Message\Message; |
7 | use MessageLocalizer; |
8 | |
9 | /** |
10 | * A topic used for a specific editing campaign. Uses a separate namespace for ID and message keys, |
11 | * and an arbitrary search expression (which could be manually configured by e.g. event organizers). |
12 | */ |
13 | class CampaignTopic extends Topic { |
14 | |
15 | /** @var string */ |
16 | private $searchExpression; |
17 | |
18 | /** |
19 | * @param string $id Topic ID, a string consisting of lowercase alphanumeric characters |
20 | * and dashes. E.g. 'biology'. Will be prefixed by 'campaign-' to avoid conflicts with |
21 | * regular topics. |
22 | * @param string $searchExpression The search expression which selects articles belonging |
23 | * to this topic. E.g. 'biology' or 'hastemplate:Taxobox'. |
24 | */ |
25 | public function __construct( string $id, string $searchExpression ) { |
26 | parent::__construct( $id, 'campaign' ); |
27 | $this->searchExpression = $searchExpression; |
28 | } |
29 | |
30 | /** |
31 | * The search expression which selects articles belonging to this topic. |
32 | * @return string |
33 | */ |
34 | public function getSearchExpression(): string { |
35 | return $this->searchExpression; |
36 | } |
37 | |
38 | /** @inheritDoc */ |
39 | public function getName( MessageLocalizer $messageLocalizer ): Message { |
40 | // These topic names are defined on-wiki, not in the software. |
41 | return $messageLocalizer->msg( 'growth-campaign-topic-name-' . $this->getId() ); |
42 | } |
43 | |
44 | /** @inheritDoc */ |
45 | protected function toJsonArray(): array { |
46 | return [ |
47 | 'id' => $this->getId(), |
48 | 'searchExpression' => $this->getSearchExpression(), |
49 | ]; |
50 | } |
51 | |
52 | /** @inheritDoc */ |
53 | public static function newFromJsonArray( JsonUnserializer $unserializer, array $json ) { |
54 | return new self( $json['id'], $json['searchExpression'] ); |
55 | } |
56 | |
57 | } |