Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $( function () {
- if( skin === 'monobook' ) {
- addPortletLink( 'p-tb', wgServer + wgScriptPath + '/index.php?title=Special:BlankPage&blankspecial=ajaxjqbd', 'Batch Delete');
- } else {
- $( '#my-tools-menu' ).prepend( '<li class="custom"><a href="' + wgServer + wgScriptPath + '/index.php?title=Special:BlankPage&blankspecial=ajaxjqbd" rel="nofollow">Batch Delete</a></li>' );
- }
- } );
- if( wgCanonicalSpecialPageName === 'Blankpage' && $.getUrlVar( 'blankspecial' ) === 'ajaxjqbd' ) {
- document.title = 'Ajax Batch Delete';
- $( createAjaxDeleteForm );
- }
- function createAjaxDeleteForm() {
- var pageHeading = ( skin === 'oasis' ) ? ( $( '.AdminDashboardArticleHeader' ).length ? '.AdminDashboardArticleHeader > h1' : '.WikiaPageHeader > h1' ) : 'h1.firstHeading',
- $bodyId = $( '#mw-content-text > p' ),
- bdelFormHtml = '<form id="ajaxdeleteform" action="javascript:void(0);"><textarea style="height: 20em; width: 50%;" id="abd-textarea">'
- + '</textarea><p><label for="abd-reason">Delete reason: </label><input type="text" style="width: 20em;" id="abd-reason" />'
- + '</p><p><input type="button" id="abd-startbutton" value="start" onclick="ajaxDeleteStart()" /></p></form><pre id="abd-output"></pre>';
- $( pageHeading ).text( 'Ajax Batch Delete' );
- $bodyId.text( 'List of pages to delete:' );
- $bodyId.after( bdelFormHtml );
- }
- function ajaxDeleteStart() {
- document.getElementById( 'abd-startbutton' ).setAttribute( 'disabled', 'disabled' );
- var txt = document.getElementById( 'abd-textarea' ),
- deletes = txt.value.split( '\n' ),
- page = deletes[0],
- reason = document.getElementById( 'abd-reason' ).value,
- badchars = /(\#|\<|\>|\[|\]|\{|\}|\|)/;
- if( page === '' ) {
- $( '#abd-output' ).append( '* Done! Nothing left to do, or next line is blank.\n' );
- document.getElementById( 'abd-startbutton' ).removeAttribute( 'disabled');
- } else {
- if( badchars.test( page ) ) {
- $( '#abd-output' ).append( '! Illegal characters detected, skipping:' + page + '\n' );
- setTimeout( ajaxDeleteStart, 1000 );
- } else {
- $( '#abd-output' ).append( '> Attempting to delete [[' + page + ']]\n' );
- ajaxBatchDeleteAPage( page, reason );
- }
- }
- deletes = deletes.slice(1,deletes.length);
- txt.value = deletes.join( '\n' );
- }
- function ajaxBatchDeleteAPage( title, reason ) {
- var url = wgServer + wgScriptPath + '/api.php?action=query&prop=info&intoken=delete|protect&titles=' + encodeURIComponent( title ) + '&format=json';
- $.getJSON( url, function( data ) {
- for ( var p in data.query.pages ) {
- break;
- }
- var DT = data.query.pages[p].deletetoken,
- PT = data.query.pages[p].protecttoken,
- url1 = wgServer + wgScriptPath + '/api.php?title=' + encodeURIComponent( title ) + '&reason=' + encodeURIComponent( reason ) + '&format=json',
- url2 = url1 + '&action=protect&protections=create=sysop&token=' + encodeURIComponent( PT );
- url1 += '&action=delete&token=' + encodeURIComponent( DT );
- $.post( url1, function() {
- $( '#abd-output' ).append( ' > Deleted\n' );
- $( '#abd-output' ).append( '> Attempting to fully protect [[' + page + ']]\n' );
- $.post( url2, function() {
- $( '#abd-output' ).append( ' > Fully protected\n' );
- setTimeout( ajaxDeleteStart, 1000 );
- });
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement