MediaWiki:Gadget-spamBlock.js

// 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 ) { /* create link */// Create links for each new account to be able to one click deal with obvious spam accounts 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 );    // Create the link to click to block this account and delete all the contributions    $( this ).after( ' | spam' );  } );

/* process click */// This is what will happen when a link is clicked $( '.spammer-link' ).click( function ( e ) {   e.preventDefault;    /* get spammer */// Who we cleaning up after?    var thisSpammer = $( this ).attr( 'id' ).replace( 'spammer-link-', '' );    /* block */// First step is to block the account to prevent further damage    ( new mw.Api ).postWithToken( 'block', { action: 'block',// Blocks the account user: thisSpammer, expiry: 'infinite',// Block forever reason: 'Vandalism only account. Blocking with DeSpammer.' } );   /* contribs */// Get all the contributions of a user to be able to rollback or delete as needed.    ( new mw.Api ).get( { action: 'query', list: 'usercontribs',// Get a list of contributions for the user. ucuser: thisSpammer, 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 ) {          /* delete */// This is a new page created by the vandal, just delete it.          ( 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 ) {          /* rollback */// This is an existing page edited by the vandal, roll it back to what it was.          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',// Won't need to get the token once we get to MW1.24+. prop: 'revisions',// Won't need to get the token once we get to MW1.24+. rvtoken: 'rollback',// Won't need to get the token once we get to MW1.24+. titles: thisTitle// Won't need to get the token once we get to MW1.24+. } ).done( function( gotToken ) {// Won't need to get the token once we get to MW1.24+. var thisRollbackToken = gotToken.query.pages[ thisPageId ].revisions[ 0 ].rollbacktoken; ( new mw.Api ).post( {// Use .postWithToken( 'rollback', ... once we get to MW1.24+. action: 'rollback',// Rollback all revisions of this page. summary: 'Page edited by vandalism only account. Rollback by DeSpammer.', token: thisRollbackToken,// Won't need this token once we get to MW1.24+. markbot: true,// I want these changes to be marked as bot, need to research what it will take for that to happen. user: thisSpammer, title: thisTitle } );         } );        } else { /* leave alone */// 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. } ); } //