Remove AbuseFilterActorMigration

Bug: T188180
Change-Id: Idcacc9f63075b621bbc858a461dc6fb7ab7a9a39
Depends-On: I7dd5fc0f9d80636b0cdf3d995fe22c1f43a5b68d
Depends-On: Ibdb2b4096f26fc6752456a05f8d70a9a6d9609ad
This commit is contained in:
Matěj Suchánek 2024-06-08 21:19:49 +02:00
parent 16aa6eaaff
commit cb08d684d5
10 changed files with 42 additions and 109 deletions

View file

@ -1,31 +0,0 @@
<?php
namespace MediaWiki\Extension\AbuseFilter;
use MediaWiki\User\ActorMigrationBase;
use MediaWiki\User\ActorStoreFactory;
/**
* Temporary class for actor migration
*/
class AbuseFilterActorMigration extends ActorMigrationBase {
public const SERVICE_NAME = 'AbuseFilterActorMigration';
/**
* @param int $stage
* @param ActorStoreFactory $actorStoreFactory
*/
public function __construct( $stage, ActorStoreFactory $actorStoreFactory ) {
parent::__construct(
[
'af_user' => [],
'afh_user' => [],
],
$stage,
$actorStoreFactory,
[ 'allowUnknown' => false ]
);
}
}

View file

@ -304,14 +304,6 @@ class AbuseFilterServices {
return ( $services ?? MediaWikiServices::getInstance() )->get( EditRevUpdater::SERVICE_NAME );
}
/**
* @param ContainerInterface|null $services
* @return AbuseFilterActorMigration
*/
public static function getActorMigration( ContainerInterface $services = null ): AbuseFilterActorMigration {
return ( $services ?? MediaWikiServices::getInstance() )->get( AbuseFilterActorMigration::SERVICE_NAME );
}
/**
* @param ContainerInterface|null $services
* @return BlockedDomainStorage

View file

@ -22,7 +22,6 @@ use ApiBase;
use ApiQuery;
use ApiQueryBase;
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
use MediaWiki\Extension\AbuseFilter\Filter\Flags;
use MediaWiki\Extension\AbuseFilter\FilterUtils;
use MediaWiki\Utils\MWTimestamp;
@ -92,10 +91,9 @@ class QueryAbuseFilters extends ApiQueryBase {
$this->addFieldsIf( 'af_actions', $fld_actions );
$this->addFieldsIf( 'af_comments', $fld_comments );
if ( $fld_user ) {
$actorQuery = AbuseFilterServices::getActorMigration()->getJoin( 'af_user' );
$this->addTables( $actorQuery['tables'] );
$this->addFields( [ 'af_user_text' => $actorQuery['fields']['af_user_text'] ] );
$this->addJoinConds( $actorQuery['joins'] );
$this->addTables( 'actor' );
$this->addFields( [ 'af_user_text' => 'actor_name' ] );
$this->addJoinConds( [ 'actor' => [ 'JOIN', 'actor_id = af_actor' ] ] );
}
$this->addFieldsIf( 'af_timestamp', $fld_time );

View file

@ -10,7 +10,7 @@ use MediaWiki\Extension\AbuseFilter\Filter\Flags;
use MediaWiki\Extension\AbuseFilter\Special\SpecialAbuseFilter;
use MediaWiki\Permissions\Authority;
use MediaWiki\Status\Status;
use MediaWiki\User\ActorMigrationBase;
use MediaWiki\User\ActorNormalization;
use MediaWiki\User\UserIdentity;
use Wikimedia\Rdbms\LBFactory;
@ -26,6 +26,9 @@ class FilterStore {
/** @var LBFactory */
private $lbFactory;
/** @var ActorNormalization */
private $actorNormalization;
/** @var FilterProfiler */
private $filterProfiler;
@ -44,40 +47,37 @@ class FilterStore {
/** @var EmergencyCache */
private $emergencyCache;
/** @var ActorMigrationBase */
private $actorMigration;
/**
* @param ConsequencesRegistry $consequencesRegistry
* @param LBFactory $lbFactory
* @param ActorNormalization $actorNormalization
* @param FilterProfiler $filterProfiler
* @param FilterLookup $filterLookup
* @param ChangeTagsManager $tagsManager
* @param FilterValidator $filterValidator
* @param FilterCompare $filterCompare
* @param EmergencyCache $emergencyCache
* @param ActorMigrationBase $actorMigration
*/
public function __construct(
ConsequencesRegistry $consequencesRegistry,
LBFactory $lbFactory,
ActorNormalization $actorNormalization,
FilterProfiler $filterProfiler,
FilterLookup $filterLookup,
ChangeTagsManager $tagsManager,
FilterValidator $filterValidator,
FilterCompare $filterCompare,
EmergencyCache $emergencyCache,
ActorMigrationBase $actorMigration
EmergencyCache $emergencyCache
) {
$this->consequencesRegistry = $consequencesRegistry;
$this->lbFactory = $lbFactory;
$this->actorNormalization = $actorNormalization;
$this->filterProfiler = $filterProfiler;
$this->filterLookup = $filterLookup;
$this->tagsManager = $tagsManager;
$this->filterValidator = $filterValidator;
$this->filterCompare = $filterCompare;
$this->emergencyCache = $emergencyCache;
$this->actorMigration = $actorMigration;
}
/**
@ -142,7 +142,7 @@ class FilterStore {
// Set last modifier.
$newRow['af_timestamp'] = $dbw->timestamp();
$newRow += $this->actorMigration->getInsertValues( $dbw, 'af_user', $userIdentity );
$newRow['af_actor'] = $this->actorNormalization->acquireActorId( $userIdentity, $dbw );
$isNew = $filterId === null;

View file

@ -6,7 +6,6 @@ use HtmlArmor;
use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\Context\IContextSource;
use MediaWiki\Extension\AbuseFilter\AbuseFilter;
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
use MediaWiki\Extension\AbuseFilter\Filter\Flags;
use MediaWiki\Extension\AbuseFilter\FilterLookup;
use MediaWiki\Extension\AbuseFilter\Special\SpecialAbuseFilter;
@ -14,10 +13,8 @@ use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
use MediaWiki\Html\Html;
use MediaWiki\Linker\Linker;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\MediaWikiServices;
use MediaWiki\Pager\TablePager;
use MediaWiki\Title\Title;
use MediaWiki\User\UserRigorOptions;
use UnexpectedValueException;
use Wikimedia\Rdbms\IResultWrapper;
@ -139,8 +136,8 @@ class AbuseFilterHistoryPager extends TablePager {
break;
case 'afh_user_text':
$formatted =
Linker::userLink( $row->afh_user, $row->afh_user_text ) . ' ' .
Linker::userToolLinks( $row->afh_user, $row->afh_user_text );
Linker::userLink( $row->afh_user ?? 0, $row->afh_user_text ) . ' ' .
Linker::userToolLinks( $row->afh_user ?? 0, $row->afh_user_text );
break;
case 'afh_public_comments':
$formatted = htmlspecialchars( $value, ENT_QUOTES, 'UTF-8', false );
@ -206,15 +203,15 @@ class AbuseFilterHistoryPager extends TablePager {
* @return array
*/
public function getQueryInfo() {
$afActorMigration = AbuseFilterServices::getActorMigration();
$actorQuery = $afActorMigration->getJoin( 'afh_user' );
$info = [
'tables' => [ 'abuse_filter_history', 'abuse_filter' ] + $actorQuery['tables'],
'tables' => [ 'abuse_filter_history', 'abuse_filter', 'actor' ],
// All fields but afh_deleted on abuse_filter_history
'fields' => [
'afh_filter',
'afh_timestamp',
'afh_public_comments',
'afh_user' => 'actor_user',
'afh_user_text' => 'actor_name',
'afh_flags',
'afh_comments',
'afh_actions',
@ -222,7 +219,7 @@ class AbuseFilterHistoryPager extends TablePager {
'afh_changed_fields',
'afh_pattern',
'af_hidden'
] + $actorQuery['fields'],
],
'conds' => [],
'join_conds' => [
'abuse_filter' =>
@ -230,14 +227,12 @@ class AbuseFilterHistoryPager extends TablePager {
'LEFT JOIN',
'afh_filter=af_id',
],
] + $actorQuery['joins'],
'actor' => [ 'JOIN', 'actor_id = afh_actor' ],
]
];
if ( $this->user !== null ) {
$user = MediaWikiServices::getInstance()->getUserFactory()
->newFromName( $this->user, UserRigorOptions::RIGOR_NONE );
$whereQuery = $afActorMigration->getWhere( $this->mDb, 'afh_user', $user );
$info['conds'][] = $whereQuery['conds'];
$info['conds']['actor_name'] = $this->user;
}
if ( $this->filter ) {

View file

@ -5,7 +5,6 @@ namespace MediaWiki\Extension\AbuseFilter\Pager;
use LogicException;
use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
use MediaWiki\Extension\AbuseFilter\FilterUtils;
use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewList;
@ -97,9 +96,8 @@ class AbuseFilterPager extends TablePager {
* @return array
*/
public function getQueryInfo() {
$actorQuery = AbuseFilterServices::getActorMigration()->getJoin( 'af_user' );
return [
'tables' => [ 'abuse_filter' ] + $actorQuery['tables'],
'tables' => [ 'abuse_filter', 'actor' ],
'fields' => [
// All columns but af_comments
'af_id',
@ -108,15 +106,19 @@ class AbuseFilterPager extends TablePager {
'af_pattern',
'af_global',
'af_public_comments',
'af_user' => 'actor_user',
'af_user_text' => 'actor_name',
'af_hidden',
'af_hit_count',
'af_timestamp',
'af_actions',
'af_group',
'af_throttled'
] + $actorQuery['fields'],
],
'conds' => $this->conds,
'join_conds' => $actorQuery['joins'],
'join_conds' => [
'actor' => [ 'JOIN', 'actor_id = af_actor' ],
]
];
}
@ -318,11 +320,11 @@ class AbuseFilterPager extends TablePager {
case 'af_timestamp':
$userLink =
Linker::userLink(
$row->af_user,
$row->af_user ?? 0,
$row->af_user_text
) .
Linker::userToolLinks(
$row->af_user,
$row->af_user ?? 0,
$row->af_user_text
);

View file

@ -2,7 +2,6 @@
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Context\RequestContext;
use MediaWiki\Extension\AbuseFilter\AbuseFilterActorMigration;
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager as PermManager;
use MediaWiki\Extension\AbuseFilter\AbuseLogger;
use MediaWiki\Extension\AbuseFilter\AbuseLoggerFactory;
@ -195,13 +194,13 @@ return [
return new FilterStore(
$services->get( ConsequencesRegistry::SERVICE_NAME ),
$services->getDBLoadBalancerFactory(),
$services->getActorNormalization(),
$services->get( FilterProfiler::SERVICE_NAME ),
$services->get( FilterLookup::SERVICE_NAME ),
$services->get( ChangeTagsManager::SERVICE_NAME ),
$services->get( FilterValidator::SERVICE_NAME ),
$services->get( FilterCompare::SERVICE_NAME ),
$services->get( EmergencyCache::SERVICE_NAME ),
$services->get( AbuseFilterActorMigration::SERVICE_NAME )
$services->get( EmergencyCache::SERVICE_NAME )
);
},
ConsequencesFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): ConsequencesFactory {
@ -376,14 +375,6 @@ return [
WikiMap::getCurrentWikiDbDomain()->getId()
);
},
AbuseFilterActorMigration::SERVICE_NAME => static function (
MediaWikiServices $services
): AbuseFilterActorMigration {
return new AbuseFilterActorMigration(
SCHEMA_COMPAT_NEW,
$services->getActorStoreFactory(),
);
},
BlockedDomainStorage::SERVICE_NAME => static function (
MediaWikiServices $services
): BlockedDomainStorage {

View file

@ -12,9 +12,8 @@ require_once "$IP/maintenance/Maintenance.php";
use LoggedUpdateMaintenance;
use ManualLogEntry;
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
use MediaWiki\Extension\AbuseFilter\Special\SpecialAbuseFilter;
use MediaWiki\User\User;
use MediaWiki\User\UserIdentityValue;
use Wikimedia\Rdbms\IExpression;
use Wikimedia\Rdbms\LikeValue;
@ -52,23 +51,20 @@ class AddMissingLoggingEntries extends LoggedUpdateMaintenance {
$legacyParamsLike = new LikeValue( $logParamsConcat, $db->anyString() );
// Non-legacy entries are a serialized array with 'newId' and 'historyId' keys
$newLogParamsLike = new LikeValue( $db->anyString(), 'historyId', $db->anyString() );
$actorQuery = AbuseFilterServices::getActorMigration()->getJoin( 'afh_user' );
// Find all entries in abuse_filter_history without logging entry of same timestamp
$afhResult = $db->newSelectQueryBuilder()
->select( [ 'afh_id', 'afh_filter', 'afh_timestamp', 'afh_deleted' ] )
->fields( $actorQuery['fields'] )
->select( [ 'afh_id', 'afh_filter', 'afh_timestamp', 'afh_deleted', 'actor_user', 'actor_name' ] )
->from( 'abuse_filter_history' )
->join( 'actor', null, [ 'actor_id = afh_actor' ] )
->leftJoin( 'logging', null, [
'afh_timestamp = log_timestamp',
$db->expr( 'log_params', IExpression::LIKE, $legacyParamsLike ),
'log_type' => 'abusefilter',
] )
->tables( $actorQuery['tables'] )
->where( [
'log_id' => null,
$db->expr( 'log_params', IExpression::NOT_LIKE, $newLogParamsLike ),
] )
->joinConds( $actorQuery['joins'] )
->caller( __METHOD__ )
->fetchResultSet();
@ -120,16 +116,7 @@ class AddMissingLoggingEntries extends LoggedUpdateMaintenance {
if ( $count % 100 === 0 ) {
$this->waitForReplication();
}
$user = User::newFromAnyId(
$row->afh_user ?? null,
$row->afh_user_text ?? null,
$row->afh_actor ?? null
);
if ( $user === null ) {
// This isn't supposed to happen.
continue;
}
$user = new UserIdentityValue( (int)( $row->actor_user ?? 0 ), $row->actor_name );
// This copies the code in FilterStore
$logEntry = new ManualLogEntry( 'abusefilter', 'modify' );

View file

@ -49,10 +49,9 @@ class FilterStoreTest extends MediaWikiIntegrationTestCase {
/** @var FilterStore $filterStore */
$filterStore = TestingAccessWrapper::newFromObject( AbuseFilterServices::getFilterStore() );
$row = $filterStore->filterToDatabaseRow( $filter, $oldFilter );
$row += AbuseFilterServices::getActorMigration()->getInsertValues(
$this->db,
'af_user',
$this->getTestUser()->getUserIdentity()
$row['af_actor'] = $this->getServiceContainer()->getActorNormalization()->acquireActorId(
$this->getTestUser()->getUserIdentity(),
$this->db
);
$this->db->newInsertQueryBuilder()
->insertInto( 'abuse_filter' )

View file

@ -10,7 +10,7 @@ use MediaWiki\Extension\AbuseFilter\FilterLookup;
use MediaWiki\Extension\AbuseFilter\FilterProfiler;
use MediaWiki\Extension\AbuseFilter\FilterStore;
use MediaWiki\Extension\AbuseFilter\FilterValidator;
use MediaWiki\User\ActorMigrationBase;
use MediaWiki\User\ActorNormalization;
use MediaWikiUnitTestCase;
use Wikimedia\Rdbms\LBFactory;
@ -27,13 +27,13 @@ class FilterStoreTest extends MediaWikiUnitTestCase {
new FilterStore(
$this->createMock( ConsequencesRegistry::class ),
$this->createMock( LBFactory::class ),
$this->createMock( ActorNormalization::class ),
$this->createMock( FilterProfiler::class ),
$this->createMock( FilterLookup::class ),
$this->createMock( ChangeTagsManager::class ),
$this->createMock( FilterValidator::class ),
$this->createMock( FilterCompare::class ),
$this->createMock( EmergencyCache::class ),
$this->createMock( ActorMigrationBase::class )
$this->createMock( EmergencyCache::class )
)
);
}