Wiktenauer logo.png

MediaWiki:Gadget-instantDelete.js

From Wiktenauer
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
/**
 * Instantly delete a page in the file namespace.
 * @author Krinkle, 2011
 * @author Bryan, 2007
 * @source commons.wikimedia.org/wiki/MediaWiki:Gadget-instantDelete.js
 * @version 1.0 (2011-12-28)
 * @compatible MediaWiki 1.18
 */
( function () {
"use strict";
	
	function vqdNow(){
		var reason, container;
		reason = document.getElementById('vqdReason').value;
		container = document.getElementById('vqdContainer');
		$(container).text('Loading...');

		$.getJSON( mw.util.wikiScript( 'api' ), {
			format: 'json',
			action: 'query',
			prop: 'info',
			intoken: 'delete',
			titles: mw.config.get( 'wgPageName' )
		}, function ( data ) {
			var id, page, token;
			if ( !data || !data.query || !data.query.pages ) {
				return;
			}
			for ( id in data.query.pages ) {
				page = data.query.pages[id];
				if ( page.deletetoken ) {
					token = page.deletetoken;
					break;
				}
			}
			if ( !token ) {
				return;
			}

			$.ajax({
				url: mw.util.wikiScript( 'api' ),
				data: {
					format: 'json',
					action: 'delete',
					title: mw.config.get( 'wgPageName' ),
					reason: reason,
					token: token
				},
				type: 'POST',
				success: function(data){
					if(data && !data.error){
						$(container).text('Page deleted.');
					} else {
						$(container).text('Deletion failed.');
					}
				},
				error: function(){
						$(container).text('Deletion failed.');
				}
			});
			
		});
	}

	function veryQuickDelete (){
		var form, inputbox, submit, container, filetoc;
	
		form = document.createElement('form');
		form.onsubmit = function () { return false; };
		form.style.display = 'inline';
		
		inputbox = document.createElement('input');
		inputbox.value = 'Gallery maintenance';
		inputbox.id = 'vqdReason';
		inputbox.size = '60';
		form.appendChild(inputbox);
		
		submit = document.createElement('input');
		submit.type = 'submit';
		submit.value = 'Delete';
		submit.onclick = vqdNow;
		form.appendChild(submit);
		
		container = document.createElement('li');
		container.id = 'vqdContainer';
		container.appendChild(form);
	
		filetoc = document.getElementById('filetoc');
		if (filetoc) {
			filetoc.appendChild(container);
		}
	}
	
	if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
		$( document ).ready( veryQuickDelete );
	}

}());