From 3413d15b68781617b0f3377ad06100e10a296d83 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Thu, 11 Mar 2021 11:50:44 +0100 Subject: [PATCH] Apply proper visibility checks for recentchanges queries Follow-up: I6063c02fa261c4cc0e6dbbb2db4e111eb85912c2 Bug: T274152 Bug: T274158 Change-Id: I71a6d521bd12931ce60eec4d2dc35af19146000f --- includes/Pager/AbuseFilterExaminePager.php | 2 +- includes/View/AbuseFilterView.php | 19 ++++++++++++++++--- includes/View/AbuseFilterViewTestBatch.php | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/includes/Pager/AbuseFilterExaminePager.php b/includes/Pager/AbuseFilterExaminePager.php index e1e0788a2..fcaecbb16 100644 --- a/includes/Pager/AbuseFilterExaminePager.php +++ b/includes/Pager/AbuseFilterExaminePager.php @@ -59,7 +59,7 @@ class AbuseFilterExaminePager extends ReverseChronologicalPager { } $conds[] = $this->mPage->buildTestConditions( $dbr ); - $conds = array_merge( $conds, $this->mPage->buildVisibilityConditions() ); + $conds = array_merge( $conds, $this->mPage->buildVisibilityConditions( $dbr, $this->getAuthority() ) ); $rcQuery = RecentChange::getQueryInfo(); $info = [ diff --git a/includes/View/AbuseFilterView.php b/includes/View/AbuseFilterView.php index 421d09f9e..922430145 100644 --- a/includes/View/AbuseFilterView.php +++ b/includes/View/AbuseFilterView.php @@ -7,6 +7,8 @@ use Flow\Data\Listener\RecentChangesListener; use IContextSource; use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager; use MediaWiki\Linker\LinkRenderer; +use MediaWiki\Permissions\Authority; +use MediaWiki\Revision\RevisionRecord; use MWException; use OOUI; use RecentChange; @@ -189,11 +191,22 @@ abstract class AbuseFilterView extends ContextSource { } /** - * @todo Check what the user can actually see and use a proper bitmask. Core should provide such a method though. + * @todo Core should provide a method for this (T233222) + * @param IDatabase $db + * @param Authority $authority * @return array */ - public function buildVisibilityConditions() : array { - return [ 'rc_deleted' => 0 ]; + public function buildVisibilityConditions( IDatabase $db, Authority $authority ) : array { + if ( !$authority->isAllowed( 'deletedhistory' ) ) { + $bitmask = RevisionRecord::DELETED_USER; + } elseif ( !$authority->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) { + $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED; + } else { + $bitmask = 0; + } + return $bitmask + ? [ $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" ] + : []; } /** diff --git a/includes/View/AbuseFilterViewTestBatch.php b/includes/View/AbuseFilterViewTestBatch.php index 81cdec118..549f11d37 100644 --- a/includes/View/AbuseFilterViewTestBatch.php +++ b/includes/View/AbuseFilterViewTestBatch.php @@ -258,7 +258,7 @@ class AbuseFilterViewTestBatch extends AbuseFilterView { $action = $this->mTestAction !== '0' ? $this->mTestAction : false; $conds[] = $this->buildTestConditions( $dbr, $action ); - $conds = array_merge( $conds, $this->buildVisibilityConditions() ); + $conds = array_merge( $conds, $this->buildVisibilityConditions( $dbr, $this->getAuthority() ) ); $rcQuery = RecentChange::getQueryInfo(); $res = $dbr->select(