User:Pirr-fduser/ajaxbatchdelete.js

/* * AjaxBatchDelete.js, * [originally] by User:Splarka on Wikipedia, * Converted to use jQuery by User:Grunny, * translated by User:Piteeek. */ /*jshint forin:true, noempty:true, eqeqeq:true, laxbreak:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, browser:true, jquery:true */ /*Globalne MediaWiki*/ ( function ( mw, $, window, document ) {	"use strict";	var skin = mw.config.get( 'skin' ),		wgServer = mw.config.get( 'wgServer' ),		wgScriptPath = mw.config.get( 'wgScriptPath' );	function createAjaxDeleteForm {		var	pageHeading = ( skin === 'oasis' ) ? ( $( '.AdminDashboardArticleHeader' ).length ? '.AdminDashboardArticleHeader > h1' : '.WikiaPageHeader > h1' ) : 'h1.firstHeading',			$bodyId = $( '#mw-content-text > p' ),			bdelFormHtml = ''				+ ' Powód usunięcia: '				+ '   ';		$( pageHeading ).text( 'Masowe usuwanie (skrypt AjaxBatchDelete)' );		$bodyId.text( 'Strony do usunięcia::' );		$bodyId.after( bdelFormHtml );		$( '#abd-startbutton' ).click( ajaxDeleteStart );	}	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( '* Zakończono! (Nie zostało nic do usunięcia lub następna linia jest pusta)\n' ); document.getElementById( 'abd-startbutton' ).removeAttribute( 'disabled' ); } else { if( badchars.test( page ) ) { $( '#abd-output' ).append( '! Wykryto niedozwolone znaki, pomijam stronę' + page + '\n' ); setTimeout( ajaxDeleteStart, 1000 ); } else { $( '#abd-output' ).append( '> Przygotowywanie do usunięcia ' + page + '\n' ); ajaxBatchDeleteAPage( page, reason ); }		}		deletes = deletes.slice( 1, deletes.length ); txt.value = deletes.join( '\n' ); }	function ajaxBatchDeleteAPage( title, deleteReason ) { var token = mw.user.tokens.get( 'editToken' ), url = wgServer + wgScriptPath + '/api.php?action=delete&title=' + window.encodeURIComponent( title ) + '&reason=' + window.encodeURIComponent( deleteReason ) + '&format=json&token=' + window.encodeURIComponent( token ); $.post( url, function( data ) {			if( data.error ) {				$( '#abd-output' ).append( '  > Error: ' + data.error.info + '\n' );			} else {				$( '#abd-output' ).append( '  > Deleted\n' );			}			setTimeout( ajaxDeleteStart, 1000 );		} ); }	$( function {		// Link dla skórki Monobook/Oasis		if( skin === 'monobook' ) {			window.addPortletLink( 'p-tb', wgServer + wgScriptPath + '/index.php?title=Special:BlankPage&blankspecial=ajaxjqbd', 'Seryjne usuwanie' );		} else {			$( '#my-tools-menu' ).prepend( ' Seryjne usuwanie' );		}		// Tworzenie formy usuwania w Ajax, lecz tylko na stronie Special:Blankpage?blankspecial=ajaxjqbd		if( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Blankpage' && $.getUrlVar( 'blankspecial' ) === 'ajaxjqbd' ) {			document.title = 'Masowe usuwanie (skrypt AjaxBatchDelete)';			createAjaxDeleteForm;		}	} ); } ( mediaWiki, jQuery, window, document ) ); /*