mediawiki-extensions-AbuseF.../includes/Pager/GlobalAbuseFilterPager.php
STran ca23e9f06b Convert af_hidden into a bitmask
Protected variables will cause the filter using them to become
protected as well. `af_hidden` can be used to track this flag,
as it is a TINYINT and can be converted into a bitmask with no
schema changes.

This is not a backwards-compatible change, as now all checks must
check the `hidden` flag specifically or otherwise will be cast to
true if any flag is set.

To support this change:
- "hidden" is considered a flag set in the `af_hidden`. This is a
  change in concept with no need for updates to the column values,
  as there is currently only one flag in the bitmask.
- `Flag`s store the bitmask as well as the state of single flags
  and can return either.
- Any checks against the `af_hidden` value no longer check a
  boolean value and instead now check the `hidden` flag value.

Bug: T363906
Change-Id: I358205cb1119cf1e4004892c37e36e0c0a864f37
2024-05-28 00:59:08 -07:00

90 lines
2.8 KiB
PHP

<?php
namespace MediaWiki\Extension\AbuseFilter\Pager;
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
use MediaWiki\Extension\AbuseFilter\CentralDBManager;
use MediaWiki\Extension\AbuseFilter\FilterUtils;
use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewList;
use MediaWiki\Linker\LinkRenderer;
/**
* Class to build paginated filter list for wikis using global abuse filters
*/
class GlobalAbuseFilterPager extends AbuseFilterPager {
/**
* @param AbuseFilterViewList $page
* @param LinkRenderer $linkRenderer
* @param AbuseFilterPermissionManager $afPermManager
* @param SpecsFormatter $specsFormatter
* @param CentralDBManager $centralDBManager
* @param array $conds
*/
public function __construct(
AbuseFilterViewList $page,
LinkRenderer $linkRenderer,
AbuseFilterPermissionManager $afPermManager,
SpecsFormatter $specsFormatter,
CentralDBManager $centralDBManager,
array $conds
) {
// Set database before parent constructor to avoid setting it there
$this->mDb = $centralDBManager->getConnection( DB_REPLICA );
parent::__construct( $page, $linkRenderer, null, $afPermManager, $specsFormatter, $conds, null, null );
}
/**
* @param string $name
* @param string|null $value
* @return string
*/
public 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()->parseInlineAsInterface( $value );
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_hit_count':
// If the rule is hidden, don't show it, even to privileged local admins
if ( FilterUtils::isHidden( $row->af_hidden ) ) {
return '';
}
return $this->msg( 'abusefilter-hitcount' )->numParams( $value )->parse();
case 'af_timestamp':
$user = $this->getUser();
return $this->msg(
'abusefilter-edit-lastmod-text',
$lang->userTimeAndDate( $value, $user ),
$row->af_user_text,
$lang->userDate( $value, $user ),
$lang->userTime( $value, $user ),
$row->af_user_text
)->parse();
case 'af_group':
// If this is global, local name probably doesn't exist, but try
return $this->specsFormatter->nameGroup( $value );
default:
return parent::formatValue( $name, $value );
}
}
}