Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ListContentSpamlistLookup
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fetchTargets
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace MediaWiki\MassMessage\Lookup;
4
5use MediaWiki\MainConfigNames;
6use MediaWiki\MassMessage\Content\MassMessageListContent;
7use MediaWiki\MassMessage\UrlHelper;
8use MediaWiki\MediaWikiServices;
9use MediaWiki\Revision\SlotRecord;
10use MediaWiki\Title\Title;
11use MediaWiki\WikiMap\WikiMap;
12
13class ListContentSpamlistLookup extends SpamlistLookup {
14
15    /**
16     * @var Title
17     */
18    protected $spamlist;
19
20    /**
21     * @param Title $spamlist
22     */
23    public function __construct( Title $spamlist ) {
24        $this->spamlist = $spamlist;
25    }
26
27    /**
28     * Get an array of targets from a page with the MassMessageListContent model.
29     *
30     * @return array[]
31     */
32    public function fetchTargets() {
33        $services = MediaWikiServices::getInstance();
34
35        $content = $services
36            ->getRevisionLookup()
37            ->getRevisionByTitle( $this->spamlist )
38            ->getContent( SlotRecord::MAIN );
39        '@phan-var MassMessageListContent $content';
40        $targets = $content->getValidTargets();
41        $currentWikiId = WikiMap::getCurrentWikiId();
42        foreach ( $targets as &$target ) {
43            if ( array_key_exists( 'site', $target ) ) {
44                $target['wiki'] = DatabaseLookup::getDBName( $target['site'] );
45            } else {
46                $target['site'] = UrlHelper::getBaseUrl(
47                    $services->getMainConfig()->get( MainConfigNames::CanonicalServer )
48                );
49                $target['wiki'] = $currentWikiId;
50            }
51        }
52        return $targets;
53    }
54}