<?php
/**
- * Cleanup all spam from a given hostname
+ * Cleanup all spam from a given hostname.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* @ingroup Maintenance
*/
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once( __DIR__ . '/Maintenance.php' );
+/**
+ * Maintenance script to cleanup all spam from a given hostname.
+ *
+ * @ingroup Maintenance
+ */
class CleanupSpam extends Maintenance {
public function __construct() {
public function execute() {
global $wgLocalDatabases, $wgUser;
- $username = wfMsg( 'spambot_username' );
+ $username = wfMessage( 'spambot_username' )->text();
$wgUser = User::newFromName( $username );
if ( !$wgUser ) {
$this->error( "Invalid username", true );
$rev = Revision::newFromTitle( $title );
$currentRevId = $rev->getId();
- //FIXME: LinkFilter needs to handle Content objects! Or rather, ContentHandler needs to provide the appropriate LinkFilter.
- while ( $rev && ( $rev->isDeleted( Revision::DELETED_TEXT ) || LinkFilter::matchEntry( $rev->getText() , $domain ) ) ) {
+ while ( $rev && ( $rev->isDeleted( Revision::DELETED_TEXT )
+ || LinkFilter::matchEntry( $rev->getContent( Revision::RAW ), $domain ) ) ) {
$rev = $rev->getPrevious();
}
$page = WikiPage::factory( $title );
if ( $rev ) {
// Revert to this revision
+ $content = $rev->getContent( Revision::RAW );
+
$this->output( "reverting\n" );
- $page->doEdit( $rev->getText(), wfMsgForContent( 'spam_reverting', $domain ),
+ $page->doEditContent( $content, wfMessage( 'spam_reverting', $domain )->inContentLanguage()->text(),
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 ) );
+ $page->doDeleteArticle( wfMessage( 'spam_deleting', $domain )->inContentLanguage()->text() );
} else {
// Didn't find a non-spammy revision, blank the page
+ $handler = ContentHandler::getForTitle( $title );
+ $content = $handler->makeEmptyContent();
+
$this->output( "blanking\n" );
- $page->doEdit( '', wfMsgForContent( 'spam_blanking', $domain ) );
+ $page->doEditContent( $content, wfMessage( 'spam_blanking', $domain )->inContentLanguage()->text() );
}
$dbw->commit( __METHOD__ );
}