mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 15:30:42 +00:00
Merge "Remove AbuseFilter::filterHidden and ::getGlobalFilterDescription"
This commit is contained in:
commit
914f0f4a13
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
|
||||
use MediaWiki\Extension\AbuseFilter\CentralDBNotAvailableException;
|
||||
use MediaWiki\Extension\AbuseFilter\Filter\Filter;
|
||||
use MediaWiki\Extension\AbuseFilter\Filter\FilterNotFoundException;
|
||||
use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner;
|
||||
use MediaWiki\Extension\AbuseFilter\VariableGenerator\VariableGenerator;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
|
@ -102,22 +100,6 @@ class AbuseFilter {
|
|||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $filterID The ID of the filter
|
||||
* @param bool|int $global Whether the filter is global
|
||||
* @return bool
|
||||
* @deprecated Call ::isHidden on a Filter object
|
||||
*/
|
||||
public static function filterHidden( $filterID, $global = false ) {
|
||||
$lookup = AbuseFilterServices::getFilterLookup();
|
||||
try {
|
||||
return $lookup->getFilter( $filterID, $global )->isHidden();
|
||||
} catch ( CentralDBNotAvailableException | FilterNotFoundException $_ ) {
|
||||
// DWIM if no central DB is available or the filter doesn't exist
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Since 1.35 Use VariableGenerator::addTitleVars
|
||||
* @param Title|null $title
|
||||
|
@ -927,34 +909,6 @@ class AbuseFilter {
|
|||
return $lang->commaList( $flags_display );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $filterID
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getGlobalFilterDescription( $filterID ) : ?string {
|
||||
global $wgAbuseFilterCentralDB;
|
||||
|
||||
if ( !$wgAbuseFilterCentralDB ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
static $cache = [];
|
||||
if ( isset( $cache[$filterID] ) ) {
|
||||
return $cache[$filterID];
|
||||
}
|
||||
|
||||
$fdb = AbuseFilterServices::getCentralDBManager()->getConnection( DB_REPLICA );
|
||||
|
||||
$cache[$filterID] = (string)$fdb->selectField(
|
||||
'abuse_filter',
|
||||
'af_public_comments',
|
||||
[ 'af_id' => $filterID ],
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
return $cache[$filterID];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives either the user-specified name for a group,
|
||||
* or spits the input back out
|
||||
|
|
|
@ -1074,6 +1074,7 @@ class AbuseFilterRunner {
|
|||
private function insertLocalLogEntries( array $logRows, IDatabase $dbw ) {
|
||||
global $wgAbuseFilterNotifications, $wgAbuseFilterNotificationsPrivate;
|
||||
|
||||
$lookup = AbuseFilterServices::getFilterLookup();
|
||||
$varDump = AbuseFilter::storeVarDump( $this->vars );
|
||||
$varDump = "tt:$varDump";
|
||||
|
||||
|
@ -1111,7 +1112,7 @@ class AbuseFilterRunner {
|
|||
|
||||
if ( $wgAbuseFilterNotifications !== false ) {
|
||||
list( $filterID, $global ) = AbuseFilter::splitGlobalName( $data['afl_filter'] );
|
||||
if ( AbuseFilter::filterHidden( $filterID, $global ) && !$wgAbuseFilterNotificationsPrivate ) {
|
||||
if ( $lookup->getFilter( $filterID, $global )->isHidden() && !$wgAbuseFilterNotificationsPrivate ) {
|
||||
continue;
|
||||
}
|
||||
$this->publishEntry( $dbw, $entry, $wgAbuseFilterNotifications );
|
||||
|
|
|
@ -213,6 +213,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
$lang = $this->getLanguage();
|
||||
$user = $this->getUser();
|
||||
$afPermManager = AbuseFilterServices::getPermissionManager();
|
||||
$lookup = AbuseFilterServices::getFilterLookup();
|
||||
$actions = $filterObj->getActions();
|
||||
|
||||
$out->addSubtitle( $this->msg(
|
||||
|
@ -224,7 +225,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
// We use filterHidden() to ensure that if a public filter is made private, the public
|
||||
// revision is also hidden.
|
||||
if (
|
||||
( $filterObj->isHidden() || ( $filter !== null && AbuseFilter::filterHidden( $filter ) ) ) &&
|
||||
( $filterObj->isHidden() || ( $filter !== null && $lookup->getFilter( $filter, false )->isHidden() ) ) &&
|
||||
!$afPermManager->canViewPrivateFilters( $user )
|
||||
) {
|
||||
$out->addHTML( $this->msg( 'abusefilter-edit-denied' )->escaped() );
|
||||
|
|
|
@ -38,7 +38,7 @@ class AbuseFilterViewHistory extends AbuseFilterView {
|
|||
$out->setPageTitle( $this->msg( 'abusefilter-filter-log' ) );
|
||||
}
|
||||
|
||||
if ( $filter && AbuseFilter::filterHidden( $filter )
|
||||
if ( $filter && AbuseFilterServices::getFilterLookup()->getFilter( $filter, false )->isHidden()
|
||||
&& !$afPermManager->canViewPrivateFilters( $this->getUser() )
|
||||
) {
|
||||
$out->addWikiMsg( 'abusefilter-history-error-hidden' );
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
|
||||
use MediaWiki\Extension\AbuseFilter\CentralDBNotAvailableException;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
|
@ -47,6 +48,7 @@ class ApiQueryAbuseLog extends ApiQueryBase {
|
|||
*/
|
||||
public function execute() {
|
||||
$afPermManager = AbuseFilterServices::getPermissionManager();
|
||||
$lookup = AbuseFilterServices::getFilterLookup();
|
||||
// Same check as in SpecialAbuseLog
|
||||
$this->checkUserRightsAny( 'abusefilter-log' );
|
||||
|
||||
|
@ -78,7 +80,12 @@ class ApiQueryAbuseLog extends ApiQueryBase {
|
|||
}
|
||||
foreach ( $params['filter'] as $filter ) {
|
||||
list( $filterID, $global ) = AbuseFilter::splitGlobalName( $filter );
|
||||
if ( AbuseFilter::filterHidden( $filterID, $global ) ) {
|
||||
try {
|
||||
$isHidden = $lookup->getFilter( $filterID, $global )->isHidden();
|
||||
} catch ( CentralDBNotAvailableException $_ ) {
|
||||
$isHidden = false;
|
||||
}
|
||||
if ( $isHidden ) {
|
||||
$this->dieWithError(
|
||||
[ 'apierror-permissiondenied', $this->msg( 'action-abusefilter-log-private' ) ]
|
||||
);
|
||||
|
@ -189,7 +196,7 @@ class ApiQueryAbuseLog extends ApiQueryBase {
|
|||
}
|
||||
if ( $fld_filter ) {
|
||||
if ( $global ) {
|
||||
$entry['filter'] = AbuseFilter::getGlobalFilterDescription( $filterID );
|
||||
$entry['filter'] = $lookup->getFilter( $filterID, true )->getName();
|
||||
} else {
|
||||
$entry['filter'] = $row->af_public_comments;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
||||
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
|
||||
use MediaWiki\Extension\AbuseFilter\CentralDBNotAvailableException;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
@ -529,7 +530,7 @@ class SpecialAbuseLog extends AbuseFilterSpecialPage {
|
|||
if ( !$this->afPermissionManager->canViewPrivateFiltersLogs( $user ) ) {
|
||||
$searchedForPrivate = false;
|
||||
foreach ( $filtersList as $index => $filterData ) {
|
||||
if ( AbuseFilter::filterHidden( ...$filterData ) ) {
|
||||
if ( AbuseFilterServices::getFilterLookup()->getFilter( ...$filterData )->isHidden() ) {
|
||||
unset( $filtersList[$index] );
|
||||
$searchedForPrivate = true;
|
||||
}
|
||||
|
@ -1164,10 +1165,11 @@ class SpecialAbuseLog extends AbuseFilterSpecialPage {
|
|||
|
||||
if ( $global ) {
|
||||
// Pull global filter description
|
||||
$globalDesc = AbuseFilter::getGlobalFilterDescription( $filterID );
|
||||
if ( $globalDesc !== null ) {
|
||||
$lookup = AbuseFilterServices::getFilterLookup();
|
||||
try {
|
||||
$globalDesc = $lookup->getFilter( $filterID, true )->getName();
|
||||
$escaped_comments = Sanitizer::escapeHtmlAllowEntities( $globalDesc );
|
||||
} else {
|
||||
} catch ( CentralDBNotAvailableException $_ ) {
|
||||
$escaped_comments = $this->msg( 'abusefilter-log-description-not-available' )->escaped();
|
||||
}
|
||||
$filter_hidden = AbuseFilter::getFilter( $row->afl_filter )->af_hidden;
|
||||
|
|
Loading…
Reference in a new issue