From 801e1f57e56731b9da145cf6f8978fbfc62ec3ec Mon Sep 17 00:00:00 2001 From: DannyS712 Date: Sun, 20 Sep 2020 22:07:57 +0000 Subject: [PATCH] Inject a user into RCVariableGenerator Needed in ::addUploadVars Bug: T263033 Change-Id: Iedde4a39dcc3192616e36a45690a0619efeb7309 --- .../VariableGenerator/RCVariableGenerator.php | 22 +++++++++++++++---- includes/Views/AbuseFilterViewExamine.php | 2 +- includes/Views/AbuseFilterViewTestBatch.php | 3 ++- includes/api/ApiAbuseFilterCheckMatch.php | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/includes/VariableGenerator/RCVariableGenerator.php b/includes/VariableGenerator/RCVariableGenerator.php index dfa1ce555..8c4a1d81b 100644 --- a/includes/VariableGenerator/RCVariableGenerator.php +++ b/includes/VariableGenerator/RCVariableGenerator.php @@ -9,6 +9,7 @@ use MWFileProps; use MWTimestamp; use RecentChange; use Title; +use User; /** * This class contains the logic used to create AbuseFilterVariableHolder objects used to @@ -20,33 +21,46 @@ class RCVariableGenerator extends VariableGenerator { */ protected $rc; + /** @var User */ + private $contextUser; + /** * @param AbuseFilterVariableHolder $vars * @param RecentChange $rc + * @param User $contextUser */ - public function __construct( AbuseFilterVariableHolder $vars, RecentChange $rc ) { + public function __construct( + AbuseFilterVariableHolder $vars, + RecentChange $rc, + User $contextUser + ) { parent::__construct( $vars ); $this->rc = $rc; + $this->contextUser = $contextUser; } /** * Get an instance for a given rc_id. * + * @todo FIXME this method doesn't appear to have any uses + * * @param int $id * @param AbuseFilterVariableHolder $vars + * @param User $contextUser * @return self|null */ public static function newFromId( int $id, - AbuseFilterVariableHolder $vars + AbuseFilterVariableHolder $vars, + User $contextUser ) : ?self { $rc = RecentChange::newFromId( $id ); if ( !$rc ) { return null; } - return new self( $vars, $rc ); + return new self( $vars, $rc, $contextUser ); } /** @@ -160,7 +174,7 @@ class RCVariableGenerator extends VariableGenerator { $time = $this->rc->getParam( 'img_timestamp' ); $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( - $title, [ 'time' => $time, 'private' => true ] + $title, [ 'time' => $time, 'private' => $this->contextUser ] ); if ( !$file ) { // FixMe This shouldn't happen! diff --git a/includes/Views/AbuseFilterViewExamine.php b/includes/Views/AbuseFilterViewExamine.php index d2f0312aa..6ef6354d3 100644 --- a/includes/Views/AbuseFilterViewExamine.php +++ b/includes/Views/AbuseFilterViewExamine.php @@ -128,7 +128,7 @@ class AbuseFilterViewExamine extends AbuseFilterView { } $vars = new AbuseFilterVariableHolder(); - $varGenerator = new RCVariableGenerator( $vars, $rc ); + $varGenerator = new RCVariableGenerator( $vars, $rc, $this->getUser() ); $vars = $varGenerator->getVars(); $out->addJsConfigVars( [ 'wgAbuseFilterVariables' => $vars ? $vars->dumpAllVars( true ) : [], diff --git a/includes/Views/AbuseFilterViewTestBatch.php b/includes/Views/AbuseFilterViewTestBatch.php index 8e51f1d74..ac8643e52 100644 --- a/includes/Views/AbuseFilterViewTestBatch.php +++ b/includes/Views/AbuseFilterViewTestBatch.php @@ -214,10 +214,11 @@ class AbuseFilterViewTestBatch extends AbuseFilterView { $counter = 1; + $contextUser = $this->getUser(); foreach ( $res as $row ) { $vars = new AbuseFilterVariableHolder(); $rc = RecentChange::newFromRow( $row ); - $varGenerator = new RCVariableGenerator( $vars, $rc ); + $varGenerator = new RCVariableGenerator( $vars, $rc, $contextUser ); $vars = $varGenerator->getVars(); if ( !$vars ) { diff --git a/includes/api/ApiAbuseFilterCheckMatch.php b/includes/api/ApiAbuseFilterCheckMatch.php index b1e0308b8..3d39fd390 100644 --- a/includes/api/ApiAbuseFilterCheckMatch.php +++ b/includes/api/ApiAbuseFilterCheckMatch.php @@ -28,7 +28,7 @@ class ApiAbuseFilterCheckMatch extends ApiBase { $vars = new AbuseFilterVariableHolder(); // @phan-suppress-next-line PhanTypeMismatchArgumentNullable T240141 - $varGenerator = new RCVariableGenerator( $vars, $rc ); + $varGenerator = new RCVariableGenerator( $vars, $rc, $this->getUser() ); $vars = $varGenerator->getVars(); } elseif ( $params['logid'] ) { $dbr = wfGetDB( DB_REPLICA );