2017-12-16 00:26:25 +00:00
|
|
|
<?php
|
|
|
|
|
2020-12-03 14:11:19 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Pager;
|
|
|
|
|
|
|
|
use Linker;
|
|
|
|
use LogicException;
|
2022-07-29 11:40:34 +00:00
|
|
|
use MediaWiki\Cache\LinkBatchFactory;
|
2021-04-17 16:57:38 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
2018-03-08 21:16:25 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
|
2021-04-17 16:57:38 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
|
2020-11-29 10:53:29 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewList;
|
2018-04-29 17:52:45 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2020-12-03 14:11:19 +00:00
|
|
|
use SpecialPage;
|
|
|
|
use stdClass;
|
|
|
|
use TablePager;
|
2023-06-07 15:41:20 +00:00
|
|
|
use UnexpectedValueException;
|
2021-09-18 18:06:16 +00:00
|
|
|
use Wikimedia\Rdbms\FakeResultWrapper;
|
2022-07-29 11:40:34 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2018-04-29 17:52:45 +00:00
|
|
|
|
2017-12-16 00:26:25 +00:00
|
|
|
/**
|
|
|
|
* Class to build paginated filter list
|
|
|
|
*/
|
|
|
|
class AbuseFilterPager extends TablePager {
|
|
|
|
|
2022-06-30 20:57:33 +00:00
|
|
|
/**
|
|
|
|
* The unique sort fields for the sort options for unique paginate
|
|
|
|
*/
|
|
|
|
private const INDEX_FIELDS = [
|
|
|
|
'af_id' => [ 'af_id' ],
|
|
|
|
'af_enabled' => [ 'af_enabled', 'af_deleted', 'af_id' ],
|
|
|
|
'af_timestamp' => [ 'af_timestamp', 'af_id' ],
|
|
|
|
'af_hidden' => [ 'af_hidden', 'af_id' ],
|
|
|
|
'af_group' => [ 'af_group', 'af_id' ],
|
|
|
|
'af_hit_count' => [ 'af_hit_count', 'af_id' ],
|
|
|
|
'af_public_comments' => [ 'af_public_comments', 'af_id' ],
|
|
|
|
];
|
|
|
|
|
2022-07-29 11:40:34 +00:00
|
|
|
/** @var ?LinkBatchFactory */
|
|
|
|
private $linkBatchFactory;
|
|
|
|
|
2021-04-17 16:57:38 +00:00
|
|
|
/** @var AbuseFilterPermissionManager */
|
2023-06-23 10:28:06 +00:00
|
|
|
private $afPermManager;
|
2021-04-17 16:57:38 +00:00
|
|
|
|
|
|
|
/** @var SpecsFormatter */
|
|
|
|
protected $specsFormatter;
|
|
|
|
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var AbuseFilterViewList The associated page
|
|
|
|
*/
|
2023-06-23 10:28:06 +00:00
|
|
|
private $mPage;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var array Query WHERE conditions
|
|
|
|
*/
|
2023-06-23 10:28:06 +00:00
|
|
|
private $conds;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
2020-10-01 11:31:04 +00:00
|
|
|
* @var string|null The pattern being searched
|
2018-11-08 14:34:32 +00:00
|
|
|
*/
|
2021-04-17 16:57:38 +00:00
|
|
|
private $searchPattern;
|
2019-10-30 12:36:19 +00:00
|
|
|
/**
|
2020-10-01 11:31:04 +00:00
|
|
|
* @var string|null The pattern search mode (LIKE, RLIKE or IRLIKE)
|
2019-10-30 12:36:19 +00:00
|
|
|
*/
|
2021-04-17 16:57:38 +00:00
|
|
|
private $searchMode;
|
2018-04-29 17:52:45 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param AbuseFilterViewList $page
|
|
|
|
* @param LinkRenderer $linkRenderer
|
2022-07-29 11:40:34 +00:00
|
|
|
* @param ?LinkBatchFactory $linkBatchFactory
|
2021-04-17 16:57:38 +00:00
|
|
|
* @param AbuseFilterPermissionManager $afPermManager
|
|
|
|
* @param SpecsFormatter $specsFormatter
|
|
|
|
* @param array $conds
|
2020-10-01 11:31:04 +00:00
|
|
|
* @param ?string $searchPattern Null if no pattern was specified
|
|
|
|
* @param ?string $searchMode
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2019-10-30 12:36:19 +00:00
|
|
|
public function __construct(
|
|
|
|
AbuseFilterViewList $page,
|
|
|
|
LinkRenderer $linkRenderer,
|
2022-07-29 11:40:34 +00:00
|
|
|
?LinkBatchFactory $linkBatchFactory,
|
2021-04-17 16:57:38 +00:00
|
|
|
AbuseFilterPermissionManager $afPermManager,
|
|
|
|
SpecsFormatter $specsFormatter,
|
|
|
|
array $conds,
|
2020-10-01 11:31:04 +00:00
|
|
|
?string $searchPattern,
|
|
|
|
?string $searchMode
|
2019-10-30 12:36:19 +00:00
|
|
|
) {
|
2021-04-17 16:57:38 +00:00
|
|
|
// needed by parent's constructor call
|
|
|
|
$this->afPermManager = $afPermManager;
|
|
|
|
$this->specsFormatter = $specsFormatter;
|
2020-10-01 11:31:04 +00:00
|
|
|
parent::__construct( $page->getContext(), $linkRenderer );
|
2017-12-16 00:26:25 +00:00
|
|
|
$this->mPage = $page;
|
2022-07-29 11:40:34 +00:00
|
|
|
$this->linkBatchFactory = $linkBatchFactory;
|
2021-04-17 16:57:38 +00:00
|
|
|
$this->conds = $conds;
|
|
|
|
$this->searchPattern = $searchPattern;
|
|
|
|
$this->searchMode = $searchMode;
|
2017-12-16 00:26:25 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getQueryInfo() {
|
2023-03-27 16:43:06 +00:00
|
|
|
$actorQuery = AbuseFilterServices::getActorMigration()->getJoin( 'af_user' );
|
2017-12-16 00:26:25 +00:00
|
|
|
return [
|
2018-03-08 21:16:25 +00:00
|
|
|
'tables' => [ 'abuse_filter' ] + $actorQuery['tables'],
|
2017-12-16 00:26:25 +00:00
|
|
|
'fields' => [
|
2018-05-03 18:32:03 +00:00
|
|
|
// All columns but af_comments
|
2017-12-16 00:26:25 +00:00
|
|
|
'af_id',
|
|
|
|
'af_enabled',
|
|
|
|
'af_deleted',
|
2018-02-17 14:09:36 +00:00
|
|
|
'af_pattern',
|
2017-12-16 00:26:25 +00:00
|
|
|
'af_global',
|
|
|
|
'af_public_comments',
|
|
|
|
'af_hidden',
|
|
|
|
'af_hit_count',
|
|
|
|
'af_timestamp',
|
|
|
|
'af_actions',
|
|
|
|
'af_group',
|
2018-05-03 18:32:03 +00:00
|
|
|
'af_throttled'
|
2018-03-08 21:16:25 +00:00
|
|
|
] + $actorQuery['fields'],
|
2021-04-17 16:57:38 +00:00
|
|
|
'conds' => $this->conds,
|
2018-03-08 21:16:25 +00:00
|
|
|
'join_conds' => $actorQuery['joins'],
|
2017-12-16 00:26:25 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-07-29 11:40:34 +00:00
|
|
|
/**
|
|
|
|
* @param IResultWrapper $result
|
|
|
|
*/
|
|
|
|
protected function preprocessResults( $result ) {
|
|
|
|
// LinkBatchFactory only provided and needed for local wiki results
|
|
|
|
if ( $this->linkBatchFactory === null || $this->getNumRows() === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$lb = $this->linkBatchFactory->newLinkBatch();
|
|
|
|
$lb->setCaller( __METHOD__ );
|
|
|
|
foreach ( $result as $row ) {
|
|
|
|
$lb->add( NS_USER, $row->af_user_text );
|
|
|
|
$lb->add( NS_USER_TALK, $row->af_user_text );
|
|
|
|
}
|
|
|
|
$lb->execute();
|
|
|
|
$result->seek( 0 );
|
|
|
|
}
|
|
|
|
|
2019-10-30 12:36:19 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* This is the same as the parent implementation if no search pattern was specified.
|
|
|
|
* Otherwise, it does a query with no limit and then slices the results à la ContribsPager.
|
|
|
|
*/
|
|
|
|
public function reallyDoQuery( $offset, $limit, $order ) {
|
2021-04-17 16:57:38 +00:00
|
|
|
if ( $this->searchMode === null ) {
|
2019-10-30 12:36:19 +00:00
|
|
|
return parent::reallyDoQuery( $offset, $limit, $order );
|
|
|
|
}
|
|
|
|
|
|
|
|
list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
|
|
|
|
$this->buildQueryInfo( $offset, $limit, $order );
|
|
|
|
|
|
|
|
unset( $options['LIMIT'] );
|
|
|
|
$res = $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
|
|
|
|
|
|
|
|
$filtered = [];
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
if ( $this->matchesPattern( $row->af_pattern ) ) {
|
2020-12-03 14:11:19 +00:00
|
|
|
$filtered[$row->af_id] = $row;
|
2019-10-30 12:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort results and enforce limit like ContribsPager
|
|
|
|
if ( $order === self::QUERY_ASCENDING ) {
|
|
|
|
ksort( $filtered );
|
|
|
|
} else {
|
|
|
|
krsort( $filtered );
|
|
|
|
}
|
|
|
|
$filtered = array_slice( $filtered, 0, $limit );
|
|
|
|
$filtered = array_values( $filtered );
|
|
|
|
return new FakeResultWrapper( $filtered );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether $subject matches the given $pattern.
|
|
|
|
*
|
|
|
|
* @param string $subject
|
|
|
|
* @return bool
|
|
|
|
* @throws LogicException
|
|
|
|
*/
|
|
|
|
private function matchesPattern( $subject ) {
|
2021-04-17 16:57:38 +00:00
|
|
|
$pattern = $this->searchPattern;
|
|
|
|
switch ( $this->searchMode ) {
|
2019-10-30 12:36:19 +00:00
|
|
|
case 'RLIKE':
|
|
|
|
return (bool)preg_match( "/$pattern/u", $subject );
|
|
|
|
case 'IRLIKE':
|
|
|
|
return (bool)preg_match( "/$pattern/ui", $subject );
|
|
|
|
case 'LIKE':
|
|
|
|
return mb_stripos( $subject, $pattern ) !== false;
|
|
|
|
default:
|
2021-04-17 16:57:38 +00:00
|
|
|
throw new LogicException( "Unknown search type {$this->searchMode}" );
|
2019-10-30 12:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2020-10-01 11:31:04 +00:00
|
|
|
* Note: this method is called by parent::__construct
|
2018-04-04 21:14:25 +00:00
|
|
|
* @return array
|
2020-12-03 14:11:19 +00:00
|
|
|
* @see Pager::getFieldNames()
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
|
|
|
public function getFieldNames() {
|
2017-12-16 00:26:25 +00:00
|
|
|
$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',
|
|
|
|
];
|
|
|
|
|
2022-07-02 13:35:00 +00:00
|
|
|
$performer = $this->getAuthority();
|
|
|
|
if ( $this->afPermManager->canSeeLogDetails( $performer ) ) {
|
2017-12-16 00:26:25 +00:00
|
|
|
$headers['af_hit_count'] = 'abusefilter-list-hitcount';
|
|
|
|
}
|
|
|
|
|
2022-07-02 13:35:00 +00:00
|
|
|
if ( $this->afPermManager->canViewPrivateFilters( $performer ) && $this->searchMode !== null ) {
|
2020-10-01 11:31:04 +00:00
|
|
|
// This is also excluded in the default view
|
2018-02-17 14:09:36 +00:00
|
|
|
$headers['af_pattern'] = 'abusefilter-list-pattern';
|
|
|
|
}
|
|
|
|
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( count( $this->getConfig()->get( 'AbuseFilterValidGroups' ) ) > 1 ) {
|
2017-12-16 00:26:25 +00:00
|
|
|
$headers['af_group'] = 'abusefilter-list-group';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $headers as &$msg ) {
|
|
|
|
$msg = $this->msg( $msg )->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $headers;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param string $name
|
2021-10-01 06:46:54 +00:00
|
|
|
* @param string|null $value
|
2018-04-04 21:14:25 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function formatValue( $name, $value ) {
|
2017-12-16 00:26:25 +00:00
|
|
|
$lang = $this->getLanguage();
|
2019-08-27 09:40:01 +00:00
|
|
|
$user = $this->getUser();
|
2020-09-22 19:11:11 +00:00
|
|
|
$linkRenderer = $this->getLinkRenderer();
|
2017-12-16 00:26:25 +00:00
|
|
|
$row = $this->mCurrentRow;
|
|
|
|
|
|
|
|
switch ( $name ) {
|
|
|
|
case 'af_id':
|
2020-09-22 19:11:11 +00:00
|
|
|
return $linkRenderer->makeLink(
|
2019-12-07 17:20:10 +00:00
|
|
|
SpecialPage::getTitleFor( 'AbuseFilter', $value ),
|
2017-12-16 00:26:25 +00:00
|
|
|
$lang->formatNum( intval( $value ) )
|
|
|
|
);
|
2018-02-17 14:09:36 +00:00
|
|
|
case 'af_pattern':
|
2019-10-30 12:36:19 +00:00
|
|
|
return $this->getHighlightedPattern( $row );
|
2017-12-16 00:26:25 +00:00
|
|
|
case 'af_public_comments':
|
2020-09-22 19:11:11 +00:00
|
|
|
return $linkRenderer->makeLink(
|
2019-12-07 17:20:10 +00:00
|
|
|
SpecialPage::getTitleFor( 'AbuseFilter', $row->af_id ),
|
2017-12-16 00:26:25 +00:00
|
|
|
$value
|
|
|
|
);
|
|
|
|
case 'af_actions':
|
|
|
|
$actions = explode( ',', $value );
|
|
|
|
$displayActions = [];
|
|
|
|
foreach ( $actions as $action ) {
|
2021-04-17 16:57:38 +00:00
|
|
|
$displayActions[] = $this->specsFormatter->getActionDisplay( $action );
|
2017-12-16 00:26:25 +00:00
|
|
|
}
|
2018-07-04 15:04:05 +00:00
|
|
|
return $lang->commaList( $displayActions );
|
2017-12-16 00:26:25 +00:00
|
|
|
case 'af_enabled':
|
|
|
|
$statuses = [];
|
|
|
|
if ( $row->af_deleted ) {
|
|
|
|
$statuses[] = $this->msg( 'abusefilter-deleted' )->parse();
|
|
|
|
} elseif ( $row->af_enabled ) {
|
|
|
|
$statuses[] = $this->msg( 'abusefilter-enabled' )->parse();
|
2018-05-03 18:32:03 +00:00
|
|
|
if ( $row->af_throttled ) {
|
|
|
|
$statuses[] = $this->msg( 'abusefilter-throttled' )->parse();
|
|
|
|
}
|
2017-12-16 00:26:25 +00:00
|
|
|
} else {
|
|
|
|
$statuses[] = $this->msg( 'abusefilter-disabled' )->parse();
|
|
|
|
}
|
|
|
|
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( $row->af_global && $this->getConfig()->get( 'AbuseFilterIsCentral' ) ) {
|
2017-12-16 00:26:25 +00:00
|
|
|
$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':
|
2021-04-17 16:57:38 +00:00
|
|
|
if ( $this->afPermManager->canSeeLogDetailsForFilter( $user, $row->af_hidden ) ) {
|
2017-12-16 00:26:25 +00:00
|
|
|
$count_display = $this->msg( 'abusefilter-hitcount' )
|
2018-07-04 15:04:05 +00:00
|
|
|
->numParams( $value )->text();
|
2020-09-22 19:11:11 +00:00
|
|
|
$link = $linkRenderer->makeKnownLink(
|
2017-12-16 00:26:25 +00:00
|
|
|
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
|
|
|
|
);
|
2016-01-21 09:57:56 +00:00
|
|
|
|
2017-12-16 00:26:25 +00:00
|
|
|
return $this->msg( 'abusefilter-edit-lastmod-text' )
|
2016-01-21 09:57:56 +00:00
|
|
|
->rawParams(
|
|
|
|
$this->mPage->getLinkToLatestDiff(
|
|
|
|
$row->af_id,
|
2021-03-08 23:54:03 +00:00
|
|
|
$lang->userTimeAndDate( $value, $user )
|
2016-01-21 09:57:56 +00:00
|
|
|
),
|
|
|
|
$userLink,
|
|
|
|
$this->mPage->getLinkToLatestDiff(
|
|
|
|
$row->af_id,
|
2021-03-08 23:54:03 +00:00
|
|
|
$lang->userDate( $value, $user )
|
2016-01-21 09:57:56 +00:00
|
|
|
),
|
|
|
|
$this->mPage->getLinkToLatestDiff(
|
|
|
|
$row->af_id,
|
2021-03-08 23:54:03 +00:00
|
|
|
$lang->userTime( $value, $user )
|
2016-01-21 09:57:56 +00:00
|
|
|
)
|
2018-07-04 15:04:05 +00:00
|
|
|
)->params(
|
2016-01-21 09:57:56 +00:00
|
|
|
wfEscapeWikiText( $row->af_user_text )
|
2019-10-30 12:36:19 +00:00
|
|
|
)->parse();
|
2017-12-16 00:26:25 +00:00
|
|
|
case 'af_group':
|
2021-04-17 16:57:38 +00:00
|
|
|
return $this->specsFormatter->nameGroup( $value );
|
2017-12-16 00:26:25 +00:00
|
|
|
default:
|
2023-06-07 15:41:20 +00:00
|
|
|
throw new UnexpectedValueException( "Unknown row type $name!" );
|
2017-12-16 00:26:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2019-10-30 12:36:19 +00:00
|
|
|
* Get the filter pattern with <b> elements surrounding the searched pattern
|
|
|
|
*
|
|
|
|
* @param stdClass $row
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getHighlightedPattern( stdClass $row ) {
|
2021-04-17 16:57:38 +00:00
|
|
|
if ( $this->searchMode === null ) {
|
2020-10-01 11:31:04 +00:00
|
|
|
throw new LogicException( 'Cannot search without a mode.' );
|
|
|
|
}
|
2019-10-30 12:36:19 +00:00
|
|
|
$maxLen = 50;
|
2021-04-17 16:57:38 +00:00
|
|
|
if ( $this->searchMode === 'LIKE' ) {
|
|
|
|
$position = mb_stripos( $row->af_pattern, $this->searchPattern );
|
|
|
|
$length = mb_strlen( $this->searchPattern );
|
2019-10-30 12:36:19 +00:00
|
|
|
} else {
|
2021-04-17 16:57:38 +00:00
|
|
|
$regex = '/' . $this->searchPattern . '/u';
|
|
|
|
if ( $this->searchMode === 'IRLIKE' ) {
|
2019-10-30 12:36:19 +00:00
|
|
|
$regex .= 'i';
|
|
|
|
}
|
|
|
|
|
|
|
|
$matches = [];
|
2021-09-11 00:44:40 +00:00
|
|
|
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
|
|
|
|
$check = @preg_match(
|
2019-10-30 12:36:19 +00:00
|
|
|
$regex,
|
|
|
|
$row->af_pattern,
|
|
|
|
$matches
|
|
|
|
);
|
|
|
|
// This may happen in case of catastrophic backtracking, or regexps matching
|
|
|
|
// the empty string.
|
|
|
|
if ( $check === false || strlen( $matches[0] ) === 0 ) {
|
|
|
|
return htmlspecialchars( mb_substr( $row->af_pattern, 0, 50 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$length = mb_strlen( $matches[0] );
|
|
|
|
$position = mb_strpos( $row->af_pattern, $matches[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
$remaining = $maxLen - $length;
|
|
|
|
if ( $remaining <= 0 ) {
|
|
|
|
$pattern = '<b>' .
|
|
|
|
htmlspecialchars( mb_substr( $row->af_pattern, $position, $maxLen ) ) .
|
|
|
|
'</b>';
|
|
|
|
} else {
|
|
|
|
// Center the snippet on the matched string
|
|
|
|
$minoffset = max( $position - round( $remaining / 2 ), 0 );
|
|
|
|
$pattern = mb_substr( $row->af_pattern, $minoffset, $maxLen );
|
|
|
|
$pattern =
|
|
|
|
htmlspecialchars( mb_substr( $pattern, 0, $position - $minoffset ) ) .
|
|
|
|
'<b>' .
|
|
|
|
htmlspecialchars( mb_substr( $pattern, $position - $minoffset, $length ) ) .
|
|
|
|
'</b>' .
|
|
|
|
htmlspecialchars( mb_substr(
|
|
|
|
$pattern,
|
|
|
|
$position - $minoffset + $length,
|
|
|
|
$remaining - ( $position - $minoffset + $length )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $pattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
|
|
|
public function getDefaultSort() {
|
2017-12-16 00:26:25 +00:00
|
|
|
return 'af_id';
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
|
|
|
public function getTableClass() {
|
2019-03-22 14:52:21 +00:00
|
|
|
return parent::getTableClass() . ' mw-abusefilter-list-scrollable';
|
2018-02-17 14:09:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param stdClass $row
|
|
|
|
* @return string
|
2020-12-03 14:11:19 +00:00
|
|
|
* @see TablePager::getRowClass()
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
|
|
|
public function getRowClass( $row ) {
|
2017-12-16 00:26:25 +00:00
|
|
|
if ( $row->af_enabled ) {
|
2018-05-03 18:32:03 +00:00
|
|
|
return $row->af_throttled ? 'mw-abusefilter-list-throttled' : 'mw-abusefilter-list-enabled';
|
2017-12-16 00:26:25 +00:00
|
|
|
} elseif ( $row->af_deleted ) {
|
|
|
|
return 'mw-abusefilter-list-deleted';
|
|
|
|
} else {
|
|
|
|
return 'mw-abusefilter-list-disabled';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2022-06-30 20:57:33 +00:00
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2022-06-30 20:57:33 +00:00
|
|
|
public function getIndexField() {
|
|
|
|
return [ self::INDEX_FIELDS[$this->mSort] ];
|
2017-12-16 00:26:25 +00:00
|
|
|
}
|
2018-07-15 23:55:31 +00:00
|
|
|
|
|
|
|
/**
|
2023-06-12 14:24:40 +00:00
|
|
|
* @param string $field
|
|
|
|
*
|
2022-06-30 20:57:33 +00:00
|
|
|
* @return bool
|
2018-07-15 23:55:31 +00:00
|
|
|
*/
|
2023-06-12 14:24:40 +00:00
|
|
|
public function isFieldSortable( $field ) {
|
|
|
|
if ( ( $field === 'af_hit_count' || $field === 'af_public_comments' )
|
2022-06-30 20:57:33 +00:00
|
|
|
&& !$this->afPermManager->canSeeLogDetails( $this->getAuthority() )
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-12 14:24:40 +00:00
|
|
|
return isset( self::INDEX_FIELDS[$field] );
|
2018-07-15 23:55:31 +00:00
|
|
|
}
|
2017-12-16 00:26:25 +00:00
|
|
|
}
|