Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
GlobalBlockListPager
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 formatRow
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 1
20
 getQueryInfo
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getIndexField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\GlobalBlocking\Special;
4
5use CentralIdLookup;
6use IContextSource;
7use MediaWiki\CommentFormatter\CommentFormatter;
8use MediaWiki\Extension\GlobalBlocking\GlobalBlocking;
9use MediaWiki\Extension\GlobalBlocking\Services\GlobalBlockingLinkBuilder;
10use MediaWiki\Html\Html;
11use MediaWiki\Linker\LinkRenderer;
12use MediaWiki\Pager\ReverseChronologicalPager;
13use MediaWiki\User\User;
14use MediaWiki\WikiMap\WikiMap;
15
16class GlobalBlockListPager extends ReverseChronologicalPager {
17    private array $queryConds;
18
19    private CommentFormatter $commentFormatter;
20    private CentralIdLookup $lookup;
21    private GlobalBlockingLinkBuilder $globalBlockingLinkBuilder;
22
23    /**
24     * @param IContextSource $context
25     * @param array $conds
26     * @param LinkRenderer $linkRenderer
27     * @param CommentFormatter $commentFormatter
28     * @param CentralIdLookup $lookup
29     * @param GlobalBlockingLinkBuilder $globalBlockingLinkBuilder
30     */
31    public function __construct(
32        IContextSource $context,
33        array $conds,
34        LinkRenderer $linkRenderer,
35        CommentFormatter $commentFormatter,
36        CentralIdLookup $lookup,
37        GlobalBlockingLinkBuilder $globalBlockingLinkBuilder
38    ) {
39        // Set database before parent constructor so that the DB that has the globalblocks table is used
40        // over the local database which may not be the same database.
41        $this->mDb = GlobalBlocking::getReplicaGlobalBlockingDatabase();
42        parent::__construct( $context, $linkRenderer );
43        $this->queryConds = $conds;
44        $this->commentFormatter = $commentFormatter;
45        $this->lookup = $lookup;
46        $this->globalBlockingLinkBuilder = $globalBlockingLinkBuilder;
47    }
48
49    public function formatRow( $row ) {
50        $lang = $this->getLanguage();
51        $user = $this->getUser();
52        $options = [];
53
54        $expiry = $lang->formatExpiry( $row->gb_expiry, TS_MW );
55        if ( $expiry == 'infinity' ) {
56            $options[] = $this->msg( 'globalblocking-infiniteblock' )->parse();
57        } else {
58            $options[] = $this->msg(
59                'globalblocking-expiringblock',
60                $lang->userDate( $expiry, $user ),
61                $lang->userTime( $expiry, $user )
62            )->parse();
63        }
64
65        // Check for whitelisting.
66        $wlinfo = GlobalBlocking::getLocalWhitelistInfo( $row->gb_id );
67        if ( $wlinfo ) {
68            $options[] = $this->msg(
69                'globalblocking-list-whitelisted',
70                User::whois( $wlinfo['user'] ), $wlinfo['reason']
71            )->text();
72        }
73
74        if ( $row->gb_anon_only ) {
75            $options[] = $this->msg( 'globalblocking-list-anononly' )->text();
76        }
77
78        // Do afterthoughts (comment, links for admins)
79        $timestamp = $row->gb_timestamp;
80        $timestamp = $lang->userTimeAndDate( wfTimestamp( TS_MW, $timestamp ), $user );
81        // Userpage link / Info on originating wiki
82        $displayWiki = WikiMap::getWikiName( $row->gb_by_wiki );
83        $userDisplay = GlobalBlocking::maybeLinkUserpage(
84            $row->gb_by_wiki,
85            $this->lookup->nameFromCentralId( $row->gb_by_central_id ) ?? ''
86        );
87        $infoItems = $this->globalBlockingLinkBuilder->getActionLinks( $user, $row->gb_address );
88
89        // Put it all together.
90        return Html::rawElement( 'li', [],
91            $this->msg( 'globalblocking-list-blockitem',
92                $timestamp,
93                $userDisplay,
94                $displayWiki,
95                $row->gb_address,
96                $lang->commaList( $options )
97            )->parse() . ' ' .
98                $this->commentFormatter->formatBlock( $row->gb_reason ) . ' ' .
99                $infoItems
100        );
101    }
102
103    public function getQueryInfo() {
104        return [
105            'tables' => 'globalblocks',
106            'fields' => GlobalBlocking::selectFields(),
107            'conds' => $this->queryConds,
108        ];
109    }
110
111    public function getIndexField() {
112        return 'gb_timestamp';
113    }
114}