MediaWiki:Gadget-spamBlock.js

/* Note, this script doesn't currently work if there is more than one new account in the list and you use the enhanced list (that condenses things by page).

var Spammer = ''; $( '.mw-changeslist-log-newusers' ).find( '.mw-usertoollinks' ).find( 'a[title^="Special:Block/"]' ).each( function( i ) { Spammer = this.title.substr( this.title.lastIndexOf( '/' ) + 1 ); console.log( Spammer ); } );

// if ( mw.config.get( 'wgNamespaceNumber' ) === -1// Special page && mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Recentchanges'// Recent Changes  && ( $.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) !== -1// You are a sysop || $.inArray( 'bureaucrat', mw.config.get( 'wgUserGroups' ) ) !== -1// or a bureaucrat || $.inArray( 'steward', mw.config.get( 'wgUserGroups' ) ) !== -1// or a steward ) { var Spammer = $( 'td a[title="Special:Log/newusers"]' ).siblings( '.mw-usertoollinks' ).find( 'a[title^="Special:Block/"]' ).attr( 'title' ).lastIndexOf( '/' ) ;// Index of the last '/' in the title attribute for the block link  Spammer = $( 'td a[title="Special:Log/newusers"]' ).siblings( '.mw-usertoollinks' ).find( 'a[title^="Special:Block/"]' ).attr( 'title' ).substr( ++Spammer);// Everything after the last '/' in the title attribute for the block link which should be the username

$( 'td a[title="Special:Log/newusers"]' ).siblings( '.mw-usertoollinks' ).find( 'a[title^="Special:Block/"]' ).after( ' | spam' );// Creates a link to click to block an account and delete all the contributions

$( '#spammer-link-' + Spammer ).click( function ( e ) {   e.preventDefault;    ( new mw.Api ).postWithToken( 'block', { action: 'block',// Blocks the account user: Spammer, expiry: 'infinite',// Block forever reason: 'Vandalism only account. Blocking with DeSpammer.' } );

( new mw.Api ).get( {     action: 'query',      list: 'usercontribs',// Get a list of contributions for the user      ucuser: Spammer,      ucprop: 'ids|title|flags',// Get the pageid and new/top(/minor) flags for the edit      uclimit: 'max'// Get all that you can    } ).done( function( ucResponse ) {      $.each( ucResponse.query.usercontribs, function( i ) { if( this.new !== undefined ) { ( new mw.Api ).postWithToken( 'delete', {           action: 'delete',// Deletes a single page            reason: 'Page created by vandalism only account. Deletion by DeSpammer.',            pageid: this.pageid          } ); } else if ( this.top !== undefined ) { var thisPageId = this.pageid;// because we're nesting Api calls, "this" will change. var thisTitle = this.title;// because we're nesting Api calls, "this" will change. ( new mw.Api ).get( {// Won't need to get the token once we get to MW1.24+           action: 'query',            prop: 'revisions',            rvtoken: 'rollback',            titles: this.title          } ).done( function( gotToken ) {            var thisRollbackToken = gotToken.query.pages[ thisPageId ].revisions[ 0 ].rollbacktoken;            ( new mw.Api ).post( {// Use .postWithToken( 'rollback', /* .. */ ) once we get to MW1.24+ action: 'rollback',// Rollsback all revisions of a page summary: 'Page edited by vandalism only account. Rollback by DeSpammer.', token: thisRollbackToken, markbot: true, user: Spammer, title: thisTitle } );         } );        } else { /* Assume that someone else has edited, reverted, deleted, or otherwise fixed this contribution */ }     } );    } );    /* Reload the page */ //window.location.reload( true );// Disabled for now because I have to redo this script a little with promises (that I don't yet understand completely) in orded to have it wait for everything else to be done before reloading. } ); } //