Update cleanupSpam.php to hide its activity from RecentChanges
authorMarcoAurelio <maurelio@tools.wmflabs.org>
Tue, 19 Sep 2017 20:26:14 +0000 (22:26 +0200)
committerLegoktm <legoktm@member.fsf.org>
Fri, 29 Sep 2017 05:28:49 +0000 (05:28 +0000)
Spam cleanup activities, mostly when it comes from automated processes
(the so called 'spambots') can involve a fair ammount of edits and log
actions to accomplish.

As such, to avoid flooding Special:RecentChanges, this script will now
set a bot flag on the script run so its edits and actions won't show
up in that special page.

To prepare this patch I had the help of Bartosz Dziewoński which I'd
also like to thank and I'll credit as co-author as well.

Bug: T176206
Co-Authored-By: Bartosz Dziewoński <matma.rex@gmail.com>
Change-Id: Ifde08056a7481b877b4b82699cc0a5ea3f962dd9

maintenance/cleanupSpam.php

index 4e47cfb..fc3cc5b 100644 (file)
@@ -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 ) {
@@ -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__ );