mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
139ca18efe
Almost all callers already provide an Authority in the form of a User object, so mostly just need to change the typehints Depends-On: I58661943c7e1acb6ff09798ee1a30be0fde3f459 Change-Id: I2ad86859c8194c14d7331f58db62b7cff4698085
152 lines
3.7 KiB
PHP
152 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Filter\AbstractFilter;
|
|
use MediaWiki\Permissions\Authority;
|
|
|
|
/**
|
|
* This class simplifies the interactions between the AbuseFilter code and Authority, knowing
|
|
* what rights are required to perform AF-related actions.
|
|
*/
|
|
class AbuseFilterPermissionManager {
|
|
public const SERVICE_NAME = 'AbuseFilterPermissionManager';
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canEdit( Authority $performer ): bool {
|
|
$block = $performer->getBlock();
|
|
return (
|
|
!( $block && $block->isSitewide() ) &&
|
|
$performer->isAllowed( 'abusefilter-modify' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canEditGlobal( Authority $performer ): bool {
|
|
return $performer->isAllowed( 'abusefilter-modify-global' );
|
|
}
|
|
|
|
/**
|
|
* Whether the user can edit the given filter.
|
|
*
|
|
* @param Authority $performer
|
|
* @param AbstractFilter $filter
|
|
* @return bool
|
|
*/
|
|
public function canEditFilter( Authority $performer, AbstractFilter $filter ): bool {
|
|
return (
|
|
$this->canEdit( $performer ) &&
|
|
!( $filter->isGlobal() && !$this->canEditGlobal( $performer ) )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Whether the user can edit a filter with restricted actions enabled.
|
|
*
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canEditFilterWithRestrictedActions( Authority $performer ): bool {
|
|
return $performer->isAllowed( 'abusefilter-modify-restricted' );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canViewPrivateFilters( Authority $performer ): bool {
|
|
return $performer->isAllowedAny(
|
|
'abusefilter-modify',
|
|
'abusefilter-view-private'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canViewPrivateFiltersLogs( Authority $performer ): bool {
|
|
return $this->canViewPrivateFilters( $performer ) ||
|
|
$performer->isAllowed( 'abusefilter-log-private' );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canViewAbuseLog( Authority $performer ): bool {
|
|
return $performer->isAllowed( 'abusefilter-log' );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canHideAbuseLog( Authority $performer ): bool {
|
|
return $performer->isAllowed( 'abusefilter-hide-log' );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canRevertFilterActions( Authority $performer ): bool {
|
|
return $performer->isAllowed( 'abusefilter-revert' );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @param bool|int $filterHidden Whether the filter is hidden
|
|
* @todo Take a Filter parameter
|
|
* @return bool
|
|
*/
|
|
public function canSeeLogDetailsForFilter( Authority $performer, $filterHidden ): bool {
|
|
if ( $filterHidden ) {
|
|
return $this->canSeeLogDetails( $performer )
|
|
&& $this->canViewPrivateFiltersLogs( $performer );
|
|
}
|
|
|
|
return $this->canSeeLogDetails( $performer );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canSeeLogDetails( Authority $performer ): bool {
|
|
return $performer->isAllowed( 'abusefilter-log-detail' );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canSeePrivateDetails( Authority $performer ): bool {
|
|
return $performer->isAllowed( 'abusefilter-privatedetails' );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canSeeHiddenLogEntries( Authority $performer ): bool {
|
|
return $performer->isAllowed( 'abusefilter-hidden-log' );
|
|
}
|
|
|
|
/**
|
|
* @param Authority $performer
|
|
* @return bool
|
|
*/
|
|
public function canUseTestTools( Authority $performer ): bool {
|
|
// TODO: make independent
|
|
return $this->canViewPrivateFilters( $performer );
|
|
}
|
|
|
|
}
|