mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 06:03:49 +00:00
184 lines
4.5 KiB
PHP
184 lines
4.5 KiB
PHP
|
<?php
|
||
|
|
||
|
/**
|
||
|
* Class to build paginated filter list
|
||
|
*/
|
||
|
class AbuseFilterPager extends TablePager {
|
||
|
|
||
|
/**
|
||
|
* @var \MediaWiki\Linker\LinkRenderer
|
||
|
*/
|
||
|
protected $linkRenderer;
|
||
|
|
||
|
function __construct( $page, $conds, $linkRenderer ) {
|
||
|
$this->mPage = $page;
|
||
|
$this->mConds = $conds;
|
||
|
$this->linkRenderer = $linkRenderer;
|
||
|
parent::__construct( $this->mPage->getContext() );
|
||
|
}
|
||
|
|
||
|
function getQueryInfo() {
|
||
|
return [
|
||
|
'tables' => [ 'abuse_filter' ],
|
||
|
'fields' => [
|
||
|
'af_id',
|
||
|
'af_enabled',
|
||
|
'af_deleted',
|
||
|
'af_global',
|
||
|
'af_public_comments',
|
||
|
'af_hidden',
|
||
|
'af_hit_count',
|
||
|
'af_timestamp',
|
||
|
'af_user_text',
|
||
|
'af_user',
|
||
|
'af_actions',
|
||
|
'af_group',
|
||
|
],
|
||
|
'conds' => $this->mConds,
|
||
|
];
|
||
|
}
|
||
|
|
||
|
function getFieldNames() {
|
||
|
static $headers = null;
|
||
|
|
||
|
if ( !empty( $headers ) ) {
|
||
|
return $headers;
|
||
|
}
|
||
|
|
||
|
$headers = [
|
||
|
'af_id' => 'abusefilter-list-id',
|
||
|
'af_public_comments' => 'abusefilter-list-public',
|
||
|
'af_actions' => 'abusefilter-list-consequences',
|
||
|
'af_enabled' => 'abusefilter-list-status',
|
||
|
'af_timestamp' => 'abusefilter-list-lastmodified',
|
||
|
'af_hidden' => 'abusefilter-list-visibility',
|
||
|
];
|
||
|
|
||
|
if ( $this->mPage->getUser()->isAllowed( 'abusefilter-log-detail' ) ) {
|
||
|
$headers['af_hit_count'] = 'abusefilter-list-hitcount';
|
||
|
}
|
||
|
|
||
|
global $wgAbuseFilterValidGroups;
|
||
|
if ( count( $wgAbuseFilterValidGroups ) > 1 ) {
|
||
|
$headers['af_group'] = 'abusefilter-list-group';
|
||
|
}
|
||
|
|
||
|
foreach ( $headers as &$msg ) {
|
||
|
$msg = $this->msg( $msg )->text();
|
||
|
}
|
||
|
|
||
|
return $headers;
|
||
|
}
|
||
|
|
||
|
function formatValue( $name, $value ) {
|
||
|
$lang = $this->getLanguage();
|
||
|
$row = $this->mCurrentRow;
|
||
|
|
||
|
switch ( $name ) {
|
||
|
case 'af_id':
|
||
|
return $this->linkRenderer->makeLink(
|
||
|
SpecialPage::getTitleFor( 'AbuseFilter', intval( $value ) ),
|
||
|
$lang->formatNum( intval( $value ) )
|
||
|
);
|
||
|
case 'af_public_comments':
|
||
|
return $this->linkRenderer->makeLink(
|
||
|
SpecialPage::getTitleFor( 'AbuseFilter', intval( $row->af_id ) ),
|
||
|
$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();
|
||
|
}
|
||
|
|
||
|
global $wgAbuseFilterIsCentral;
|
||
|
if ( $row->af_global && $wgAbuseFilterIsCentral ) {
|
||
|
$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 ( SpecialAbuseLog::canSeeDetails( $row->af_id, $row->af_hidden ) ) {
|
||
|
$count_display = $this->msg( 'abusefilter-hitcount' )
|
||
|
->numParams( $value )->parse();
|
||
|
$link = $this->linkRenderer->makeKnownLink(
|
||
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
||
|
$count_display,
|
||
|
[],
|
||
|
[ 'wpSearchFilter' => $row->af_id ]
|
||
|
);
|
||
|
} else {
|
||
|
$link = "";
|
||
|
}
|
||
|
return $link;
|
||
|
case 'af_timestamp':
|
||
|
$userLink =
|
||
|
Linker::userLink(
|
||
|
$row->af_user,
|
||
|
$row->af_user_text
|
||
|
) .
|
||
|
Linker::userToolLinks(
|
||
|
$row->af_user,
|
||
|
$row->af_user_text
|
||
|
);
|
||
|
$user = $row->af_user_text;
|
||
|
return $this->msg( 'abusefilter-edit-lastmod-text' )
|
||
|
->rawParams( $lang->timeanddate( $value, true ),
|
||
|
$userLink,
|
||
|
$lang->date( $value, true ),
|
||
|
$lang->time( $value, true ),
|
||
|
$user
|
||
|
)->parse();
|
||
|
case 'af_group':
|
||
|
return AbuseFilter::nameGroup( $value );
|
||
|
break;
|
||
|
default:
|
||
|
throw new MWException( "Unknown row type $name!" );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getDefaultSort() {
|
||
|
return 'af_id';
|
||
|
}
|
||
|
|
||
|
function getRowClass( $row ) {
|
||
|
if ( $row->af_enabled ) {
|
||
|
return 'mw-abusefilter-list-enabled';
|
||
|
} elseif ( $row->af_deleted ) {
|
||
|
return 'mw-abusefilter-list-deleted';
|
||
|
} else {
|
||
|
return 'mw-abusefilter-list-disabled';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function isFieldSortable( $name ) {
|
||
|
$sortable_fields = [
|
||
|
'af_id',
|
||
|
'af_enabled',
|
||
|
'af_throttled',
|
||
|
'af_user_text',
|
||
|
'af_timestamp',
|
||
|
'af_hidden',
|
||
|
'af_group',
|
||
|
];
|
||
|
if ( $this->mPage->getUser()->isAllowed( 'abusefilter-log-detail' ) ) {
|
||
|
$sortable_fields[] = 'af_hit_count';
|
||
|
}
|
||
|
return in_array( $name, $sortable_fields );
|
||
|
}
|
||
|
}
|