User:Gimmetrow/test2.js

importScript('User:AzaToth/twinkleclose.js'); importScript('User:AzaToth/twinkledeprod.js'); importScript('User:AzaToth/twinklespeedy.js'); importScript('User:AzaToth/morebits.js'); importScript('User:AzaToth/twinklebatchprotect.js'); // If TwinkleConfig aint exist. if( typeof( TwinkleConfig ) == 'undefined' ) { TwinkleConfig = {}; }

/** TwinkleConfig.summaryAd (string) If ad should be added or not to summary, default TWINKLE */ if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) { TwinkleConfig.summaryAd = " using TW"; }

/** TwinkleConfig.deletionSummaryAd (string) If ad should be added or not to deletion summary, default TWINKLE */ if( typeof( TwinkleConfig.deletionSummaryAd ) == 'undefined' ) { TwinkleConfig.deletionSummaryAd = " using TW"; }

function twinkledeli { if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) { return; }	if( userIsInGroup( 'sysop' ) ) {

mw.util.addPortletLink( 'p-cactions', "javascript:twinkledeli.callback", "deli", "tw-deli", "Delete image found on page", ""); } } $(twinkledeli);

function getChecked( nodelist ) { if( !( nodelist instanceof NodeList ) ) { return nodelist.checked ? [ nodelist.value ] : []; }	var result = []; for(var i = 0; i < nodelist.length; ++i ) { if( nodelist[i].checked ) { result.push( nodelist[i].value ); }	}	return result; }

twinkledeli.callback = function twinklesdeliCallback { var Window = new SimpleWindow( 800, 400 ); Window.setTitle( "Delete images on page" );

var form = new QuickForm( twinkledeli.callback.evaluate ); form.append( {			type: 'checkbox',			list: [				{ 					label: 'Delete images',					name: 'delete_image',					value: 'delete',					checked: true				},				{					label: 'Remove image instances on this page',					name: 'unlink_image',					value: 'unlink',					checked: true				}			]		} ); form.append( {			type: 'textarea',			name: 'reason',			label: 'Reason: '		} ); if( wgNamespaceNumber == Namespace.CATEGORY ) { var query = { 'action': 'query', 'generator': 'categorymembers', 'gcmcategory': wgTitle, 'gcmnamespace': Namespace.IMAGE, 'gcmlimit' : 5000, // the max for sysops 'prop': 'imageinfo' };	} else { var query = { 'action': 'query', 'generator': 'images', 'titles': wgPageName, 'prop': 'imageinfo' };	}	var wikipedia_api = new Wikipedia.api( 'Grabbing images', query, function( self ) {			var xmlDoc = self.responseXML;			var snapshot = xmlDoc.evaluate('//page[@imagerepository="local"]', xmlDoc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );			var list = [];			for ( var i = 0; i < snapshot.snapshotLength; ++i ) {				var object = snapshot.snapshotItem(i);				var image = xmlDoc.evaluate('@title', object, null, XPathResult.STRING_TYPE, null ).stringValue;				var user = xmlDoc.evaluate('imageinfo/ii/@user', object, null, XPathResult.STRING_TYPE, null ).stringValue;				list.push( {label:image + ' (' + user + ')', value:image, checked:true});			}			self.params.form.append( { type: 'checkbox', name: 'images', list: list }			)			self.params.form.append( { type:'submit' } );

var result = self.params.form.render; self.params.Window.setContent( result );

} );

wikipedia_api.params = { form:form, Window:Window }; wikipedia_api.post; var root = document.createElement( 'div' ); Status.init( root ); Window.setContent( root ); Window.display; }

twinkledeli.callback.evaluate = function twinkledeliCallbackEvaluate(event) { wgPageName = wgPageName.replace( /_/g, ' ' ); // for queen/king/whatever and country! var images = getChecked( event.target.images ); var reason = event.target.reason.value; var delete_image = event.target.delete_image.checked; var unlink_image = event.target.unlink_image.checked; if( ! reason ) { return; }	Status.init( event.target ); if( delete_image ) { for( var i = 0; i < images.length; ++i ) { var image = images[i]; var query = { 'action': 'query', 'titles': image }			var wikipedia_api = new Wikipedia.api( 'Checking if image ' + image + ' exists', query, twinkledeli.callbacks.main ); wikipedia_api.params = { image:image, reason:reason }; wikipedia_api.post; }	}

if( unlink_image ) { var query = { 'title': wgPageName, 'action': 'submit' };		var wikipedia_wiki = new Wikipedia.wiki( 'Removing image instances', query, twinkledeli.callbacks.unlinkImageInstances ); wikipedia_wiki.params = { images:images, reason:reason }; wikipedia_wiki.get; } } twinkledeli.callbacks = { main: function( self ) { var xmlDoc = self.responseXML; var normal = xmlDoc.evaluate( '//normalized/n[@from="' + self.params.image.replace( /"/g, '\\"') + '"]/@to', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue; if( normal ) { self.params.image = normal; }		var exists = xmlDoc.evaluate( 'boolean(//pages/page[@title="' + self.params.image.replace( /"/g, '\\"') + '" and not(@missing)])', xmlDoc, null, XPathResult.BOOLEAN_TYPE, null ).booleanValue;

if( ! exists ) { self.statelem.error( "It seems that the page doesn't exists, perhaps it has already been deleted" ); return; }		var query = { 'title': self.params.image, 'action': 'delete' };		var wikipedia_wiki = new Wikipedia.wiki( 'Deleting image ' + self.params.image, query, twinkledeli.callbacks.deleteImage ); wikipedia_wiki.params = self.params; wikipedia_wiki.followRedirect = false; wikipedia_wiki.get; },	deleteImage: function( self ) { var form = this.responseXML.getElementById( 'deleteconfirm' ); if( ! form ) { // Hell, image deletion is b0rked :(			form = this.responseXML.getElementsByTagName( 'form' )[0];			var postData = {				'wpReason': "Deleted because \"" + self.params.reason + "\"." + TwinkleConfig.deletionSummaryAd,				'wpEditToken': form.wpEditToken.value			}			self.post( postData );		} else {

var postData = { 'wpWatch': form.wpWatch.checked ? '' : undefined, 'wpReason': "Deleted because \"" + self.params.reason + "\"." + TwinkleConfig.deletionSummaryAd, 'wpEditToken': form.wpEditToken.value }			self.post( postData ); }	},	unlinkImageInstances: function( self ) { var form = self.responseXML.getElementById('editform'); var text = form.wpTextbox1.value; var images = self.params.images; var wikiPage = new Mediawiki.Page( text );

for( var i = 0; i < images.length; ++i ) { var image = images[i].replace( /^Image:/, '' ); wikiPage.commentOutImage( image, 'Commented out' ); }		text = wikiPage.getText; var postData = { 'wpMinoredit': form.wpMinoredit.checked ? '' : undefined, 'wpWatchthis': undefined, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': "Removing instances of images beacuse \"" + self.params.reason.toUpperCaseFirstChar + "\";" + TwinkleConfig.deletionSummaryAd, 'wpTextbox1': text };		self.post( postData ); } }

importScript('User:AzaToth/twinkleimage.js'); importScript('User:AzaToth/twinklebatchdelete.js'); importScript('User:AzaToth/twinkledeprod.js') importScript('User:^demon/vero.js')