User:Majr/fileNuke.js

function deleteFiles( files, reason, count ) { if ( count === undefined ) { count = 0; }	if ( !files[count] ) { return; }	var api = new mw.Api api.get( {		action: 'query',		list: 'backlinks',		blredirect: 1,		bltitle: files[count],		bllimit: 5000	} ).done( function( data ) {		var backlinks = data.query ? data.query.backlinks : null;		if ( !backlinks.length || ( backlinks.length === 1 && backlinks[0].title === files[count] ) ) {			api.post( { action: 'delete', token: mw.user.tokens.get( 'editToken' ), title: files[count], reason: reason } ).done( function { console.info( 'Deleted:', files[count] ); mw.notify( 'Deleted: ' + files[count] ); deleteFiles( files, reason, count + 1 ); } ).fail( function( _, error ) { console.warn( error.error.info ); mw.notify( error.error.info, { title: 'Error', autoHide: false } ); } );		} else {			console.info( 'Skipped:', files[count] );			mw.notify( 'Skipped: ' + files[count] );			deleteFiles( files, reason, count + 1 );		}	} ).fail( function( _, error ) {		console.warn( error.error.info );		mw.notify( error.error.info, { title: 'Error', autoHide: false } )		deleteFiles( files, reason, count + 1 );	} ); }

if ( $( '#gallery-list' ).length ) { $( '#gallery-list' ) .append( ' Delete ' ) .append( '' ); $( '#gallery-list > .delete' ).click( function {		var reason = $( '#gallery-list > .reason' ).val;		deleteFiles( $( '#gallery-list > textarea' ).val.split( '\n' ), reason );	} ); }