2013-09-23 14:39:16 +00:00
|
|
|
<?php
|
2017-10-19 07:40:22 +00:00
|
|
|
|
2013-09-23 14:39:16 +00:00
|
|
|
if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
} else {
|
2016-01-06 20:17:41 +00:00
|
|
|
$IP = __DIR__ . '/../../..';
|
2013-09-23 14:39:16 +00:00
|
|
|
}
|
2015-09-28 18:03:35 +00:00
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
2013-09-23 14:39:16 +00:00
|
|
|
|
2019-03-29 10:00:18 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2013-09-23 14:39:16 +00:00
|
|
|
/**
|
|
|
|
* Adds rows missing per https://bugzilla.wikimedia.org/show_bug.cgi?id=52919
|
|
|
|
*/
|
|
|
|
class AddMissingLoggingEntries extends Maintenance {
|
2016-12-12 21:29:51 +00:00
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
2018-02-10 00:45:16 +00:00
|
|
|
$this->requireExtension( 'Abuse Filter' );
|
2016-12-12 21:29:51 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see Maintenance::execute
|
|
|
|
*/
|
2013-09-23 14:39:16 +00:00
|
|
|
public function execute() {
|
2017-06-15 14:23:34 +00:00
|
|
|
$logParams = [];
|
|
|
|
$afhRows = [];
|
2013-09-23 14:39:16 +00:00
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
// Find all entries in abuse_filter_history without logging entry of same timestamp
|
2017-08-30 02:51:39 +00:00
|
|
|
$afhResult = wfGetDB( DB_REPLICA, 'vslow' )->select(
|
2017-06-15 14:23:34 +00:00
|
|
|
[ 'abuse_filter_history', 'logging' ],
|
|
|
|
[ 'afh_id', 'afh_filter', 'afh_timestamp', 'afh_user', 'afh_deleted', 'afh_user_text' ],
|
|
|
|
[ 'log_id IS NULL' ],
|
2013-09-23 14:39:16 +00:00
|
|
|
__METHOD__,
|
2017-06-15 14:23:34 +00:00
|
|
|
[],
|
|
|
|
[ 'logging' => [
|
2015-09-28 18:03:35 +00:00
|
|
|
'LEFT JOIN',
|
|
|
|
'afh_timestamp = log_timestamp AND ' .
|
|
|
|
'SUBSTRING_INDEX(log_params, \'\n\', 1) = afh_id AND log_type = \'abusefilter\''
|
2017-06-15 14:23:34 +00:00
|
|
|
] ]
|
2013-09-23 14:39:16 +00:00
|
|
|
);
|
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
// Because the timestamp matches aren't exact (sometimes a couple of
|
|
|
|
// seconds off), we need to check all our results and ignore those that
|
|
|
|
// do actually have log entries
|
2013-09-23 14:39:16 +00:00
|
|
|
foreach ( $afhResult as $row ) {
|
2015-08-22 22:28:18 +00:00
|
|
|
$logParams[] = $row->afh_id . "\n" . $row->afh_filter;
|
2013-09-23 14:39:16 +00:00
|
|
|
$afhRows[$row->afh_id] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !count( $afhRows ) ) {
|
|
|
|
$this->error( "Nothing to do.", 1 );
|
|
|
|
}
|
|
|
|
|
2017-08-30 02:51:39 +00:00
|
|
|
$logResult = wfGetDB( DB_REPLICA )->select(
|
2013-09-23 14:39:16 +00:00
|
|
|
'logging',
|
2017-06-15 14:23:34 +00:00
|
|
|
[ 'log_params' ],
|
|
|
|
[ 'log_type' => 'abusefilter', 'log_params' => $logParams ],
|
2013-09-23 14:39:16 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( $logResult as $row ) {
|
2018-04-04 21:14:25 +00:00
|
|
|
// id . '\n' . filter
|
2019-05-15 15:34:57 +00:00
|
|
|
$afhId = explode( "\n", $row->log_params, 2 )[0];
|
2015-09-28 18:03:35 +00:00
|
|
|
// Forget this row had any issues - it just has a different timestamp in the log
|
|
|
|
unset( $afhRows[$afhId] );
|
2013-09-23 14:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !count( $afhRows ) ) {
|
|
|
|
$this->error( "Nothing to do.", 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2019-03-29 10:00:18 +00:00
|
|
|
$factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
2017-08-30 17:06:44 +00:00
|
|
|
|
2013-09-23 14:39:16 +00:00
|
|
|
$count = 0;
|
|
|
|
foreach ( $afhRows as $row ) {
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $count % 100 === 0 ) {
|
2019-03-29 10:00:18 +00:00
|
|
|
$factory->waitForReplication();
|
2013-09-23 14:39:16 +00:00
|
|
|
}
|
2018-03-09 21:23:38 +00:00
|
|
|
$user = User::newFromAnyId( $row->afh_user, $row->afh_user_text, null );
|
2013-09-23 14:39:16 +00:00
|
|
|
$dbw->insert(
|
|
|
|
'logging',
|
2017-06-15 14:23:34 +00:00
|
|
|
[
|
2013-09-23 14:39:16 +00:00
|
|
|
'log_type' => 'abusefilter',
|
|
|
|
'log_action' => 'modify',
|
|
|
|
'log_timestamp' => $row->afh_timestamp,
|
|
|
|
'log_namespace' => -1,
|
2015-08-22 23:01:18 +00:00
|
|
|
'log_title' => SpecialPageFactory::getLocalNameFor( 'AbuseFilter' ) . '/' . $row->afh_filter,
|
2013-09-23 14:39:16 +00:00
|
|
|
'log_params' => $row->afh_id . '\n' . $row->afh_filter,
|
|
|
|
'log_deleted' => $row->afh_deleted,
|
2018-03-09 21:23:38 +00:00
|
|
|
] + CommentStore::getStore()->insert( $dbw, 'log_comment', '' )
|
|
|
|
+ ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $user ),
|
2013-09-23 14:39:16 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->output( "Inserted " . $count . " rows.\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 00:41:40 +00:00
|
|
|
$maintClass = AddMissingLoggingEntries::class;
|
2013-09-23 14:39:16 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|