Merge branch 'master' of ssh://gerrit.wikimedia.org:29418/mediawiki/core into Wikidata
[lhc/web/wiklou.git] / maintenance / cleanupSpam.php
index cdbba55..c253cf9 100644 (file)
 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() {
@@ -109,15 +111,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__ );
                }