mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-15 02:03:53 +00:00
Inject a user into RCVariableGenerator
Needed in ::addUploadVars Bug: T263033 Change-Id: Iedde4a39dcc3192616e36a45690a0619efeb7309
This commit is contained in:
parent
ed160a69a7
commit
801e1f57e5
|
@ -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!
|
||||
|
|
|
@ -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 ) : [],
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue