3 require_once( 'commandLine.inc' );
4 require_once( "$IP/includes/LinkFilter.php" );
6 function cleanupArticle( $id, $domain ) {
7 $title = Title
::newFromID( $id );
9 print "Internal error: no page for ID $id\n";
13 print $title->getPrefixedDBkey() . " ...";
14 $rev = Revision
::newFromTitle( $title );
15 $revId = $rev->getId();
16 $currentRevId = $revId;
18 while ( $rev && LinkFilter
::matchEntry( $rev->getText() , $domain ) ) {
19 # Revision::getPrevious can't be used in this way before MW 1.6 (Revision.php 1.26)
20 #$rev = $rev->getPrevious();
21 $revId = $title->getPreviousRevisionID( $revId );
23 $rev = Revision
::newFromTitle( $title, $revId );
28 if ( $revId == $currentRevId ) {
29 // The regex didn't match the current article text
30 // This happens e.g. when a link comes from a template rather than the page itself
31 print "False match\n";
33 $dbw = wfGetDB( DB_MASTER
);
34 $dbw->immediateBegin();
36 // Didn't find a non-spammy revision, blank the page
38 $article = new Article( $title );
39 $article->updateArticle( '', wfMsg( 'spam_blanking', $domain ),
43 // Revert to this revision
45 $article = new Article( $title );
46 $article->updateArticle( $rev->getText(), wfMsg( 'spam_reverting', $domain ), false, false );
48 $dbw->immediateCommit();
52 //------------------------------------------------------------------------------
57 $username = wfMsg( 'spambot_username' );
59 $wgUser = User
::newFromName( $username );
60 // Create the user if necessary
61 if ( !$wgUser->getID() ) {
62 $wgUser->addToDatabase();
65 if ( !isset( $args[0] ) ) {
66 print "Usage: php cleanupSpam.php <hostname>\n";
70 $like = LinkFilter
::makeLike( $spec );
72 print "Not a valid hostname specification: $spec\n";
76 $dbr = wfGetDB( DB_SLAVE
);
78 if ( isset($options['all']) ) {
79 // Clean up spam on all wikis
80 $dbr = wfGetDB( DB_SLAVE
);
81 print "Finding spam on " . count($wgLocalDatabases) . " wikis\n";
83 foreach ( $wgLocalDatabases as $db ) {
84 $count = $dbr->selectField( "`$db`.externallinks", 'COUNT(*)',
85 array( 'el_index LIKE ' . $dbr->addQuotes( $like ) ), $fname );
88 passthru( "php cleanupSpam.php $db $spec | sed s/^/$db: /" );
97 // Clean up spam on this wiki
98 $res = $dbr->select( 'externallinks', array( 'DISTINCT el_from' ),
99 array( 'el_index LIKE ' . $dbr->addQuotes( $like ) ), $fname );
100 $count = $dbr->numRows( $res );
101 print "Found $count articles containing $spec\n";
102 while ( $row = $dbr->fetchObject( $res ) ) {
103 cleanupArticle( $row->el_from
, $spec );