Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
GlobalAbuseFilterPager | |
0.00% |
0 / 35 |
|
0.00% |
0 / 2 |
210 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
formatValue | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
182 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\AbuseFilter\Pager; |
4 | |
5 | use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager; |
6 | use MediaWiki\Extension\AbuseFilter\CentralDBManager; |
7 | use MediaWiki\Extension\AbuseFilter\FilterUtils; |
8 | use MediaWiki\Extension\AbuseFilter\SpecsFormatter; |
9 | use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewList; |
10 | use MediaWiki\Linker\LinkRenderer; |
11 | |
12 | /** |
13 | * Class to build paginated filter list for wikis using global abuse filters |
14 | */ |
15 | class GlobalAbuseFilterPager extends AbuseFilterPager { |
16 | |
17 | /** |
18 | * @param AbuseFilterViewList $page |
19 | * @param LinkRenderer $linkRenderer |
20 | * @param AbuseFilterPermissionManager $afPermManager |
21 | * @param SpecsFormatter $specsFormatter |
22 | * @param CentralDBManager $centralDBManager |
23 | * @param array $conds |
24 | */ |
25 | public function __construct( |
26 | AbuseFilterViewList $page, |
27 | LinkRenderer $linkRenderer, |
28 | AbuseFilterPermissionManager $afPermManager, |
29 | SpecsFormatter $specsFormatter, |
30 | CentralDBManager $centralDBManager, |
31 | array $conds |
32 | ) { |
33 | // Set database before parent constructor to avoid setting it there |
34 | $this->mDb = $centralDBManager->getConnection( DB_REPLICA ); |
35 | parent::__construct( $page, $linkRenderer, null, $afPermManager, $specsFormatter, $conds, null, null ); |
36 | } |
37 | |
38 | /** |
39 | * @param string $name |
40 | * @param string|null $value |
41 | * @return string |
42 | */ |
43 | public function formatValue( $name, $value ) { |
44 | $lang = $this->getLanguage(); |
45 | $row = $this->mCurrentRow; |
46 | |
47 | switch ( $name ) { |
48 | case 'af_id': |
49 | return $lang->formatNum( intval( $value ) ); |
50 | case 'af_public_comments': |
51 | return $this->getOutput()->parseInlineAsInterface( $value ); |
52 | case 'af_enabled': |
53 | $statuses = []; |
54 | if ( $row->af_deleted ) { |
55 | $statuses[] = $this->msg( 'abusefilter-deleted' )->parse(); |
56 | } elseif ( $row->af_enabled ) { |
57 | $statuses[] = $this->msg( 'abusefilter-enabled' )->parse(); |
58 | } else { |
59 | $statuses[] = $this->msg( 'abusefilter-disabled' )->parse(); |
60 | } |
61 | if ( $row->af_global ) { |
62 | $statuses[] = $this->msg( 'abusefilter-status-global' )->parse(); |
63 | } |
64 | |
65 | return $lang->commaList( $statuses ); |
66 | case 'af_hit_count': |
67 | // If the rule is hidden or protected, don't show it, even to privileged local admins |
68 | if ( FilterUtils::isHidden( $row->af_hidden ) || FilterUtils::isProtected( $row->af_hidden ) ) { |
69 | return ''; |
70 | } |
71 | return $this->msg( 'abusefilter-hitcount' )->numParams( $value )->parse(); |
72 | case 'af_timestamp': |
73 | $user = $this->getUser(); |
74 | return $this->msg( |
75 | 'abusefilter-edit-lastmod-text', |
76 | $lang->userTimeAndDate( $value, $user ), |
77 | $row->af_user_text, |
78 | $lang->userDate( $value, $user ), |
79 | $lang->userTime( $value, $user ), |
80 | $row->af_user_text |
81 | )->parse(); |
82 | case 'af_group': |
83 | // If this is global, local name probably doesn't exist, but try |
84 | return $this->specsFormatter->nameGroup( $value ); |
85 | default: |
86 | return parent::formatValue( $name, $value ); |
87 | } |
88 | } |
89 | } |