X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FcleanupSpam.php;h=fc3cc5b8df094a21e33106d0e1bd12ed789eea74;hb=fea3bbcdae4f052f769ab466df6e1f5d47d1383c;hp=e6471dd1c4e028d95d472e1a75e777e8de0a6a28;hpb=fa8e1a9b00d872f445b65312f554db03230a5502;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/cleanupSpam.php b/maintenance/cleanupSpam.php index e6471dd1c4..fc3cc5b8df 100644 --- a/maintenance/cleanupSpam.php +++ b/maintenance/cleanupSpam.php @@ -32,7 +32,7 @@ class CleanupSpam extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Cleanup all spam from a given hostname"; + $this->addDescription( 'Cleanup all spam from a given hostname' ); $this->addOption( 'all', 'Check all wikis in $wgLocalDatabases' ); $this->addOption( 'delete', 'Delete pages containing only spam instead of blanking them' ); $this->addArg( @@ -49,10 +49,9 @@ class CleanupSpam extends Maintenance { if ( !$wgUser ) { $this->error( "Invalid username specified in 'spambot_username' message: $username", true ); } - // Create the user if necessary - if ( !$wgUser->getId() ) { - $wgUser->addToDatabase(); - } + // Hack: Grant bot rights so we don't flood RecentChanges + $wgUser->addGroup( 'bot' ); + $spec = $this->getArg(); $like = LinkFilter::makeLikeArray( $spec ); if ( !$like ) { @@ -64,14 +63,14 @@ class CleanupSpam extends Maintenance { $this->output( "Finding spam on " . count( $wgLocalDatabases ) . " wikis\n" ); $found = false; foreach ( $wgLocalDatabases as $wikiID ) { - $dbr = wfGetDB( DB_SLAVE, array(), $wikiID ); + $dbr = $this->getDB( DB_REPLICA, [], $wikiID ); $count = $dbr->selectField( 'externallinks', 'COUNT(*)', - array( 'el_index' . $dbr->buildLike( $like ) ), __METHOD__ ); + [ 'el_index' . $dbr->buildLike( $like ) ], __METHOD__ ); if ( $count ) { $found = true; $cmd = wfShellWikiCmd( "$IP/maintenance/cleanupSpam.php", - array( '--wiki', $wikiID, $spec ) ); + [ '--wiki', $wikiID, $spec ] ); passthru( "$cmd | sed 's/^/$wikiID: /'" ); } } @@ -83,9 +82,9 @@ class CleanupSpam extends Maintenance { } else { // Clean up spam on this wiki - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'externallinks', array( 'DISTINCT el_from' ), - array( 'el_index' . $dbr->buildLike( $like ) ), __METHOD__ ); + $dbr = $this->getDB( DB_REPLICA ); + $res = $dbr->select( 'externallinks', [ 'DISTINCT el_from' ], + [ 'el_index' . $dbr->buildLike( $like ) ], __METHOD__ ); $count = $dbr->numRows( $res ); $this->output( "Found $count articles containing $spec\n" ); foreach ( $res as $row ) { @@ -120,7 +119,7 @@ class CleanupSpam extends Maintenance { // This happens e.g. when a link comes from a template rather than the page itself $this->output( "False match\n" ); } else { - $dbw = wfGetDB( DB_MASTER ); + $dbw = $this->getDB( DB_MASTER ); $this->beginTransaction( $dbw, __METHOD__ ); $page = WikiPage::factory( $title ); if ( $rev ) { @@ -131,7 +130,7 @@ class CleanupSpam extends Maintenance { $page->doEditContent( $content, wfMessage( 'spam_reverting', $domain )->inContentLanguage()->text(), - EDIT_UPDATE, + EDIT_UPDATE | EDIT_FORCE_BOT, $rev->getId() ); } elseif ( $this->hasOption( 'delete' ) ) { @@ -148,7 +147,8 @@ class CleanupSpam extends Maintenance { $this->output( "blanking\n" ); $page->doEditContent( $content, - wfMessage( 'spam_blanking', $domain )->inContentLanguage()->text() + wfMessage( 'spam_blanking', $domain )->inContentLanguage()->text(), + EDIT_UPDATE | EDIT_FORCE_BOT ); } $this->commitTransaction( $dbw, __METHOD__ );