diff --git a/includes/AbuseFilter.php b/includes/AbuseFilter.php index f667da8a8..815ee7285 100644 --- a/includes/AbuseFilter.php +++ b/includes/AbuseFilter.php @@ -1,9 +1,7 @@ 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 diff --git a/includes/AbuseFilterRunner.php b/includes/AbuseFilterRunner.php index 78d68ced5..f4aec235d 100644 --- a/includes/AbuseFilterRunner.php +++ b/includes/AbuseFilterRunner.php @@ -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 ); diff --git a/includes/Views/AbuseFilterViewEdit.php b/includes/Views/AbuseFilterViewEdit.php index a246f5613..12dc93482 100644 --- a/includes/Views/AbuseFilterViewEdit.php +++ b/includes/Views/AbuseFilterViewEdit.php @@ -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() ); diff --git a/includes/Views/AbuseFilterViewHistory.php b/includes/Views/AbuseFilterViewHistory.php index d1d1d7c7e..8c0e9c1a7 100644 --- a/includes/Views/AbuseFilterViewHistory.php +++ b/includes/Views/AbuseFilterViewHistory.php @@ -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' ); diff --git a/includes/api/ApiQueryAbuseLog.php b/includes/api/ApiQueryAbuseLog.php index 80068c46b..d61ee5408 100644 --- a/includes/api/ApiQueryAbuseLog.php +++ b/includes/api/ApiQueryAbuseLog.php @@ -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; } diff --git a/includes/special/SpecialAbuseLog.php b/includes/special/SpecialAbuseLog.php index 452ab78dd..a231d08a1 100644 --- a/includes/special/SpecialAbuseLog.php +++ b/includes/special/SpecialAbuseLog.php @@ -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;