summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/AbuseFilter/includes/pagers/GlobalAbuseFilterPager.php
blob: 36c84a01158c78e6a10cb9dffa5ceb71aafec282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

/**
 * Class to build paginated filter list for wikis using global abuse filters
 */
class GlobalAbuseFilterPager extends AbuseFilterPager {
	function __construct( $page, $conds, $linkRenderer ) {
		parent::__construct( $page, $conds, $linkRenderer, [ '', 'LIKE' ] );
		global $wgAbuseFilterCentralDB;
		$this->mDb = wfGetDB( DB_REPLICA, [], $wgAbuseFilterCentralDB );
	}

	function formatValue( $name, $value ) {
		$lang = $this->getLanguage();
		$row = $this->mCurrentRow;

		switch ( $name ) {
			case 'af_id':
				return $lang->formatNum( intval( $value ) );
			case 'af_public_comments':
				return $this->getOutput()->parseInline( $value );
			case 'af_actions':
				$actions = explode( ',', $value );
				$displayActions = [];
				foreach ( $actions as $action ) {
					$displayActions[] = AbuseFilter::getActionDisplay( $action );
				}
				return htmlspecialchars( $lang->commaList( $displayActions ) );
			case 'af_enabled':
				$statuses = [];
				if ( $row->af_deleted ) {
					$statuses[] = $this->msg( 'abusefilter-deleted' )->parse();
				} elseif ( $row->af_enabled ) {
					$statuses[] = $this->msg( 'abusefilter-enabled' )->parse();
				} else {
					$statuses[] = $this->msg( 'abusefilter-disabled' )->parse();
				}
				if ( $row->af_global ) {
					$statuses[] = $this->msg( 'abusefilter-status-global' )->parse();
				}

				return $lang->commaList( $statuses );
			case 'af_hidden':
				$msg = $value ? 'abusefilter-hidden' : 'abusefilter-unhidden';
				return $this->msg( $msg )->parse();
			case 'af_hit_count':
				// If the rule is hidden, don't show it, even to priviledged local admins
				if ( $row->af_hidden ) {
					return '';
				}
				return $this->msg( 'abusefilter-hitcount' )->numParams( $value )->parse();
			case 'af_timestamp':
				$user = $row->af_user_text;
				return $this->msg(
					'abusefilter-edit-lastmod-text',
					$lang->timeanddate( $value, true ),
					$user,
					$lang->date( $value, true ),
					$lang->time( $value, true ),
					$user
				)->parse();
			case 'af_group':
				// If this is global, local name probably doesn't exist, but try
				return AbuseFilter::nameGroup( $value );
				break;
			default:
				throw new MWException( "Unknown row type $name!" );
		}
	}
}