From 22bb1e6a498a25ae827550c4fee733a9293e16a6 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Mon, 14 May 2012 23:24:31 +0400 Subject: [PATCH] Allow cleanupSpam.php optionally delete offending pages Change-Id: I69387df1b3d404a6d00d8073e58d7556c7ab9298 --- RELEASE-NOTES-1.20 | 2 ++ languages/messages/MessagesEn.php | 1 + maintenance/cleanupSpam.php | 18 ++++++++++++------ maintenance/language/messages.inc | 1 + 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index dba0737703..fefb6864d1 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -68,6 +68,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. * (bug 4220) the XML dump format schema now have unique identity constraints for page and revision identifiers. Patch by Elvis Stansvik. * (bug 35705) QUnit upgraded from 1.2.0 to 1.7.0 +* cleanupSpam.php now can delete spam pages if --delete was specified instead of blanking + them. === Bug fixes in 1.20 === * (bug 30245) Use the correct way to construct a log page title. diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 1fdb65ad33..b7275f89a2 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -3692,6 +3692,7 @@ This is probably caused by a link to a blacklisted external site.', 'spambot_username' => 'MediaWiki spam cleanup', 'spam_reverting' => 'Reverting to last revision not containing links to $1', 'spam_blanking' => 'All revisions contained links to $1, blanking', +'spam_deleting' => 'All revisions contained links to $1, deleting', # Info page 'pageinfo-title' => 'Information for "$1"', diff --git a/maintenance/cleanupSpam.php b/maintenance/cleanupSpam.php index 8a760cdc04..f104899f84 100644 --- a/maintenance/cleanupSpam.php +++ b/maintenance/cleanupSpam.php @@ -24,11 +24,13 @@ require_once( dirname( __FILE__ ) . '/Maintenance.php' ); class CleanupSpam extends Maintenance { + public function __construct() { parent::__construct(); $this->mDescription = "Cleanup all spam from a given hostname"; $this->addOption( 'all', 'Check all wikis in $wgLocalDatabases' ); - $this->addArg( 'hostname', 'Hostname that was spamming' ); + $this->addOption( 'delete', 'Delete pages containing only spam instead of blanking them' ); + $this->addArg( 'hostname', 'Hostname that was spamming, single * wildcard in the beginning allowed' ); } public function execute() { @@ -108,15 +110,19 @@ class CleanupSpam extends Maintenance { $dbw = wfGetDB( DB_MASTER ); $dbw->begin( __METHOD__ ); $page = WikiPage::factory( $title ); - if ( !$rev ) { - // Didn't find a non-spammy revision, blank the page - $this->output( "blanking\n" ); - $page->doEdit( '', wfMsgForContent( 'spam_blanking', $domain ) ); - } else { + if ( $rev ) { // Revert to this revision $this->output( "reverting\n" ); $page->doEdit( $rev->getText(), wfMsgForContent( 'spam_reverting', $domain ), EDIT_UPDATE, $rev->getId() ); + } elseif ( $this->hasOption( 'delete' ) ) { + // Didn't find a non-spammy revision, blank the page + $this->output( "deleting\n" ); + $page->doDeleteArticle( wfMsgForContent( 'spam_deleting', $domain ) ); + } else { + // Didn't find a non-spammy revision, blank the page + $this->output( "blanking\n" ); + $page->doEdit( '', wfMsgForContent( 'spam_blanking', $domain ) ); } $dbw->commit( __METHOD__ ); } diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 493fcc55cf..fbdef20a69 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2634,6 +2634,7 @@ $wgMessageStructure = array( 'spambot_username', 'spam_reverting', 'spam_blanking', + 'spam_deleting', ), 'info' => array( 'pageinfo-title', -- 2.20.1