Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
12 / 14
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CategorySpamlistLookup
85.71% covered (warning)
85.71%
12 / 14
33.33% covered (danger)
33.33%
1 / 3
4.05
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 fetchTargets
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
2
 isCachable
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\MassMessage\Lookup;
4
5use MediaWiki\Category\Category;
6use MediaWiki\MainConfigNames;
7use MediaWiki\MassMessage\UrlHelper;
8use MediaWiki\MediaWikiServices;
9use MediaWiki\Title\Title;
10use MediaWiki\WikiMap\WikiMap;
11
12class CategorySpamlistLookup extends SpamlistLookup {
13
14    /**
15     * @var Title
16     */
17    protected $spamlist;
18
19    /**
20     * @param Title $spamlist
21     */
22    public function __construct( Title $spamlist ) {
23        $this->spamlist = $spamlist;
24    }
25
26    /**
27     * Get an array of targets from a category
28     * @return array[]
29     */
30    public function fetchTargets() {
31        $members = Category::newFromTitle( $this->spamlist )->getMembers();
32        $targets = [];
33        $currentWikiId = WikiMap::getCurrentWikiId();
34
35        /** @var Title $member */
36        foreach ( $members as $member ) {
37            $targets[] = [
38                'title' => $member->getPrefixedText(),
39                'wiki' => $currentWikiId,
40                'site' => UrlHelper::getBaseUrl(
41                    MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::CanonicalServer )
42                ),
43            ];
44        }
45        return $targets;
46    }
47
48    /**
49     * @return false
50     */
51    public function isCachable() {
52        return false;
53    }
54}