View difference between Paste ID: CGwyHHg8 and HBeEwK2t
SHOW: | | - or go back to the newest paste.
1
/*
2
 * Ajax batch delete thingy, version [0.0.3] by Grunny
3
 * Based on: http://en.wikipedia.org/wiki/User:Splarka/ajaxbatchdelete.js
4
 * Converted to use jQuery
5
 * Protection added by Joeytje50 (caek)
6
 */
7
$( function () {
8
        if( skin === 'monobook' ) {
9
                addPortletLink( 'p-tb', wgServer + wgScriptPath + '/index.php?title=Special:BlankPage&blankspecial=ajaxjqbd', 'Batch Delete');
10
        } else {
11
                $( '#my-tools-menu' ).prepend( '<li class="custom"><a href="' + wgServer + wgScriptPath + '/index.php?title=Special:BlankPage&blankspecial=ajaxjqbd" rel="nofollow">Batch Delete</a></li>' );
12
        }
13
} );
14
 
15
if( wgCanonicalSpecialPageName === 'Blankpage' && $.getUrlVar( 'blankspecial' ) === 'ajaxjqbd' ) {
16
        document.title = 'Ajax Batch Delete';
17
        $( createAjaxDeleteForm );
18
}
19
 
20
function createAjaxDeleteForm() {
21
        var     pageHeading = ( skin === 'oasis' ) ? ( $( '.AdminDashboardArticleHeader' ).length ? '.AdminDashboardArticleHeader > h1' : '.WikiaPageHeader > h1' ) : 'h1.firstHeading',
22
                $bodyId = $( '#mw-content-text > p' ),
23
                bdelFormHtml = '<form id="ajaxdeleteform" action="javascript:void(0);"><textarea style="height: 20em; width: 50%;" id="abd-textarea">'
24
                        + '</textarea><p><label for="abd-reason">Delete reason: </label><input type="text" style="width: 20em;" id="abd-reason" />'
25
                        + '</p><p><input type="button" id="abd-startbutton" value="start" onclick="ajaxDeleteStart()" /></p></form><pre id="abd-output"></pre>';
26
        $( pageHeading ).text( 'Ajax Batch Delete' );
27
        $bodyId.text( 'List of pages to delete:' );
28
        $bodyId.after( bdelFormHtml );
29
}
30
 
31
function ajaxDeleteStart() {
32
        document.getElementById( 'abd-startbutton' ).disabled = true;
33-
        var     txt = document.getElementById( 'abd-textarea' ),
33+
        var	txt = document.getElementById( 'abd-textarea' );
34-
		txt.value = txt.value.replace(/\n{2,}/g,'\n'),
34+
		txt.value = txt.value.replace(/\n{2,}/g,'\n');
35-
                deletes = txt.value.split( '\n' ),
35+
	var	deletes = txt.value.split( '\n' ),
36
                page = deletes[0],
37
                reason = document.getElementById( 'abd-reason' ).value,
38
                badchars = /(\#|\<|\>|\[|\]|\{|\}|\|)/;
39
        if( page === '' ) {
40
                $( '#abd-output' ).append( '* Done! Nothing left to do, or next line is blank.\n' );
41
                document.getElementById( 'abd-startbutton' ).disabled = false;
42
        } else {
43
                if( badchars.test( page ) ) {
44
                        $( '#abd-output' ).append( '! Illegal characters detected, skipping:' + page + '\n' );
45
                        setTimeout( ajaxDeleteStart, 1000 );
46
                } else {
47
                        $( '#abd-output' ).append( '> Attempting to delete [[' + page + ']]\n' );
48
                        ajaxBatchDeleteAPage( page, reason );
49
                }
50
        }
51
        deletes = deletes.slice(1,deletes.length);
52
        txt.value = deletes.join( '\n' );
53
}
54
 
55
function ajaxBatchDeleteAPage( title, reason ) {
56
        var url =  wgServer + wgScriptPath + '/api.php?action=query&prop=info&intoken=delete|protect&titles=' + encodeURIComponent( title ) + '&format=json';
57
        $.getJSON( url, function( data ) {
58
                for ( var p in data.query.pages ) {
59
                        break;
60
                }
61
                var     DT = data.query.pages[p].deletetoken,
62
                        PT = data.query.pages[p].protecttoken,
63
                        url1 = wgServer + wgScriptPath + '/api.php?title=' + encodeURIComponent( title ) + '&reason=' + encodeURIComponent( reason ) + '&format=json',
64
                        url2 = url1 + '&action=protect&protections=create=sysop&token=' + encodeURIComponent( PT );
65
                        url1 += '&action=delete&token=' + encodeURIComponent( DT );
66
                $.post( url1, function() {
67
                        $( '#abd-output' ).append( '  > Deleted\n' );
68
                        $( '#abd-output' ).append( '> Attempting to fully protect [[' + title + ']]\n' );
69
                        $.post( url2, function() {
70
                                $( '#abd-output' ).append( '  > Fully protected\n' );
71
                                setTimeout( ajaxDeleteStart, 1000 );
72
                        });
73
                });
74
        });
75
}