X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FcleanupBlocks.php;h=db51e4b3d495dd941bacb87aefe40faaa1aa30ad;hb=18974098ef5c05c50d939b1d3f6c05f8706980df;hp=7a3034fb78b0e5bcb3dc1a8866ca8d1e23abb5bf;hpb=b5906606e1aa1a795231fb813b766818b1dd6c25;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/cleanupBlocks.php b/maintenance/cleanupBlocks.php index 7a3034fb78..db51e4b3d4 100644 --- a/maintenance/cleanupBlocks.php +++ b/maintenance/cleanupBlocks.php @@ -23,6 +23,8 @@ require_once __DIR__ . '/Maintenance.php'; +use MediaWiki\Block\DatabaseBlock; + /** * Maintenance script to clean up user blocks with user names not matching the * 'user' table. @@ -39,12 +41,14 @@ class CleanupBlocks extends Maintenance { public function execute() { $db = $this->getDB( DB_MASTER ); + $blockQuery = DatabaseBlock::getQueryInfo(); $max = $db->selectField( 'ipblocks', 'MAX(ipb_user)' ); // Step 1: Clean up any duplicate user blocks - for ( $from = 1; $from <= $max; $from += $this->mBatchSize ) { - $to = min( $max, $from + $this->mBatchSize - 1 ); + $batchSize = $this->getBatchSize(); + for ( $from = 1; $from <= $max; $from += $batchSize ) { + $to = min( $max, $from + $batchSize - 1 ); $this->output( "Cleaning up duplicate ipb_user ($from-$to of $max)\n" ); $delete = []; @@ -53,8 +57,8 @@ class CleanupBlocks extends Maintenance { 'ipblocks', [ 'ipb_user' ], [ - "ipb_user >= $from", - "ipb_user <= $to", + "ipb_user >= " . (int)$from, + "ipb_user <= " . (int)$to, ], __METHOD__, [ @@ -65,21 +69,24 @@ class CleanupBlocks extends Maintenance { foreach ( $res as $row ) { $bestBlock = null; $res2 = $db->select( - 'ipblocks', - '*', + $blockQuery['tables'], + $blockQuery['fields'], [ 'ipb_user' => $row->ipb_user, - ] + ], + __METHOD__, + [], + $blockQuery['joins'] ); foreach ( $res2 as $row2 ) { - $block = Block::newFromRow( $row2 ); + $block = DatabaseBlock::newFromRow( $row2 ); if ( !$bestBlock ) { $bestBlock = $block; continue; } // Find the most-restrictive block. Can't use - // Block::chooseBlock because that's for IP blocks, not + // DatabaseBlock::chooseBlock because that's for IP blocks, not // user blocks. $keep = null; if ( $keep === null && $block->getExpiry() !== $bestBlock->getExpiry() ) { @@ -87,11 +94,12 @@ class CleanupBlocks extends Maintenance { $keep = $block->getExpiry() > $bestBlock->getExpiry(); } if ( $keep === null ) { - foreach ( [ 'createaccount', 'sendemail', 'editownusertalk' ] as $action ) { - if ( $block->prevents( $action ) xor $bestBlock->prevents( $action ) ) { - $keep = $block->prevents( $action ); - break; - } + if ( $block->isCreateAccountBlocked() xor $bestBlock->isCreateAccountBlocked() ) { + $keep = $block->isCreateAccountBlocked(); + } elseif ( $block->isEmailBlocked() xor $bestBlock->isEmailBlocked() ) { + $keep = $block->isEmailBlocked(); + } elseif ( $block->isUsertalkEditAllowed() xor $bestBlock->isUsertalkEditAllowed() ) { + $keep = $block->isUsertalkEditAllowed(); } } @@ -114,8 +122,8 @@ class CleanupBlocks extends Maintenance { } // Step 2: Update the user name in any blocks where it doesn't match - for ( $from = 1; $from <= $max; $from += $this->mBatchSize ) { - $to = min( $max, $from + $this->mBatchSize - 1 ); + for ( $from = 1; $from <= $max; $from += $batchSize ) { + $to = min( $max, $from + $batchSize - 1 ); $this->output( "Cleaning up mismatched user name ($from-$to of $max)\n" ); $res = $db->select( @@ -123,8 +131,8 @@ class CleanupBlocks extends Maintenance { [ 'ipb_id', 'user_name' ], [ 'ipb_user = user_id', - "ipb_user >= $from", - "ipb_user <= $to", + "ipb_user >= " . (int)$from, + "ipb_user <= " . (int)$to, 'ipb_address != user_name', ], __METHOD__ @@ -143,5 +151,5 @@ class CleanupBlocks extends Maintenance { } } -$maintClass = "CleanupBlocks"; +$maintClass = CleanupBlocks::class; require_once RUN_MAINTENANCE_IF_MAIN;