Advertisement
Joeytje50

Untitled

Oct 8th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $( function () {
  2.     if( skin === 'monobook' ) {
  3.         addPortletLink( 'p-tb', wgServer + wgScriptPath + '/index.php?title=Special:BlankPage&blankspecial=ajaxjqbd', 'Batch Delete');
  4.     } else {
  5.         $( '#my-tools-menu' ).prepend( '<li class="custom"><a href="' + wgServer + wgScriptPath + '/index.php?title=Special:BlankPage&blankspecial=ajaxjqbd" rel="nofollow">Batch Delete</a></li>' );
  6.     }
  7. } );
  8.  
  9. if( wgCanonicalSpecialPageName === 'Blankpage' && $.getUrlVar( 'blankspecial' ) === 'ajaxjqbd' ) {
  10.     document.title = 'Ajax Batch Delete';
  11.     $( createAjaxDeleteForm );
  12. }
  13.  
  14. function createAjaxDeleteForm() {
  15.     var pageHeading = ( skin === 'oasis' ) ? ( $( '.AdminDashboardArticleHeader' ).length ? '.AdminDashboardArticleHeader > h1' : '.WikiaPageHeader > h1' ) : 'h1.firstHeading',
  16.         $bodyId = $( '#mw-content-text > p' ),
  17.         bdelFormHtml = '<form id="ajaxdeleteform" action="javascript:void(0);"><textarea style="height: 20em; width: 50%;" id="abd-textarea">'
  18.             + '</textarea><p><label for="abd-reason">Delete reason: </label><input type="text" style="width: 20em;" id="abd-reason" />'
  19.             + '</p><p><input type="button" id="abd-startbutton" value="start" onclick="ajaxDeleteStart()" /></p></form><pre id="abd-output"></pre>';
  20.     $( pageHeading ).text( 'Ajax Batch Delete' );
  21.     $bodyId.text( 'List of pages to delete:' );
  22.     $bodyId.after( bdelFormHtml );
  23. }
  24.  
  25. function ajaxDeleteStart() {
  26.     document.getElementById( 'abd-startbutton' ).setAttribute( 'disabled', 'disabled' );
  27.     var txt = document.getElementById( 'abd-textarea' ),
  28.         deletes = txt.value.split( '\n' ),
  29.         page = deletes[0],
  30.         reason = document.getElementById( 'abd-reason' ).value,
  31.         badchars = /(\#|\<|\>|\[|\]|\{|\}|\|)/;
  32.     if( page === '' ) {
  33.         $( '#abd-output' ).append( '* Done! Nothing left to do, or next line is blank.\n' );
  34.         document.getElementById( 'abd-startbutton' ).removeAttribute( 'disabled');
  35.     } else {
  36.         if( badchars.test( page ) ) {
  37.             $( '#abd-output' ).append( '! Illegal characters detected, skipping:' + page + '\n' );
  38.             setTimeout( ajaxDeleteStart, 1000 );
  39.         } else {
  40.             $( '#abd-output' ).append( '> Attempting to delete [[' + page + ']]\n' );
  41.             ajaxBatchDeleteAPage( page, reason );
  42.         }
  43.     }
  44.     deletes = deletes.slice(1,deletes.length);
  45.     txt.value = deletes.join( '\n' );
  46. }
  47.  
  48. function ajaxBatchDeleteAPage( title, reason ) {
  49.     var url =  wgServer + wgScriptPath + '/api.php?action=query&prop=info&intoken=delete|protect&titles=' + encodeURIComponent( title ) + '&format=json';
  50.     $.getJSON( url, function( data ) {
  51.         for ( var p in data.query.pages ) {
  52.             break;
  53.         }
  54.         var DT = data.query.pages[p].deletetoken,
  55.             PT = data.query.pages[p].protecttoken,
  56.             url1 = wgServer + wgScriptPath + '/api.php?title=' + encodeURIComponent( title ) + '&reason=' + encodeURIComponent( reason ) + '&format=json',
  57.             url2 = url1 + '&action=protect&protections=create=sysop&token=' + encodeURIComponent( PT );
  58.             url1 += '&action=delete&token=' + encodeURIComponent( DT );
  59.         $.post( url1, function() {
  60.             $( '#abd-output' ).append( '  > Deleted\n' );
  61.             $( '#abd-output' ).append( '> Attempting to fully protect [[' + page + ']]\n' );
  62.             $.post( url2, function() {
  63.                 $( '#abd-output' ).append( '  > Fully protected\n' );
  64.                 setTimeout( ajaxDeleteStart, 1000 );
  65.             });
  66.         });
  67.     });
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement