Inject a user into RCVariableGenerator

Needed in ::addUploadVars

Bug: T263033
Change-Id: Iedde4a39dcc3192616e36a45690a0619efeb7309
This commit is contained in:
DannyS712 2020-09-20 22:07:57 +00:00
parent ed160a69a7
commit 801e1f57e5
4 changed files with 22 additions and 7 deletions

View file

@ -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!

View file

@ -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 ) : [],

View file

@ -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 ) {

View file

@ -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 );