Usuario:TwinkleUser/consultadeborrado.js

Nota: Después de guardar, debes refrescar la caché de tu navegador para ver los cambios. Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar. Firefox: mientras presionas Mayús pulsas el botón Actualizar, (o presiona Ctrl-Shift-R). Los usuarios de Google Chrome y Safari pueden simplemente pulsar el botón Recargar. Para más detalles e instrucciones acerca de otros exploradores, véase Ayuda:Cómo limpiar la caché.

// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
	TwinkleConfig = function() {};
}

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

function num2order( num ) {
	switch( num ) {
	case 1: return '';
	case 2: return '2nd';
	case 3: return '3rd';
	default: return num + 'th';
	}
}
function twinklexfd() {
	if( mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgCurRevisionId') == false ) {
		return;
	}
	if (typeof twinkleConfigExists !== 'undefined')
	{
		mw.util.addPortletLink( 'p-cactions', "javascript:twinklexfd.callback()", "CDB", "tw-xfd", "Consulta de Borrado", "");
	}
	else
	{
		mw.util.addPortletLink('p-cactions', 'javascript:alert("Tu cuenta es muy nueva como para usar twinkle.");', 'CDB', 'tw-xfd', 'Consulta de Borrado', '');
	}
}
$(twinklexfd);

twinklexfd.callback = function twinklexfdCallback() {

	var Window = new SimpleWindow( 600, 300 );
	Window.setTitle( "Consulta de borrado" );
	var form = new QuickForm( twinklexfd.callback.evaluate );
	var categories = form.append( {
			type: 'select',
			name: 'category',
			label: 'Selecciona la categoría: ',
			tooltip: 'Cuando es activado, una opción predefinida es activada, basándose en el nombre de espacio en el que estás. La predefinida podría ser la mas conveniente',
			event: twinklexfd.callback.change_category
		} );
	categories.append( {
			type: 'option',
			label: 'Borrado a artículo',
			selected: mw.config.get('wgNamespaceNumber') == Namespace.MAIN,
			value: 'afd'
		} );
	categories.append( {
			type: 'option',
			label: 'Borrado a plantilla',
			selected: mw.config.get('wgNamespaceNumber') == Namespace.TEMPLATE,
			value: 'tfd'
		} );
	categories.append( {
			type: 'option',
			label: 'Imagen para borrado',
			selected: mw.config.get('wgNamespaceNumber') == Namespace.IMAGE,
			value: 'ifd'
		} );
	categories.append( {
			type: 'option',
			label: 'Categoría para borrado',
			selected: mw.config.get('wgNamespaceNumber') == Namespace.CATEGORY,
			value: 'cfd'
		} );
	categories.append( {
			type: 'option',
			label: 'Miscelánea para borrado',
			selected: [ Namespace.IMAGE, Namespace.MAIN, Namespace.TEMPLATE, Namespace.CATEGORY ].indexOf( mw.config.get('wgNamespaceNumber') ) == -1 ,
			value: 'mfd'
		} );
	categories.append( {
			type: 'option',
			label: 'Redirecciones para borrado',
			selected: QueryString.equals('redirect', 'no'),
			value: 'rfd'
		} );
	categories.append( {
			type: 'option',
			label: 'Sfd',
			disabled: true,
			value: 'sfd'
		} );

	form.append( {
			type: 'field',
			label:'Work area',
			name: 'work_area'
		} );

	var result = form.render();
	Window.setContent( result );
	Window.display();

	// We must init the
	var evt = document.createEvent( "Event" );
	evt.initEvent( 'change', true, true );
	result.category.dispatchEvent( evt );

}

twinklexfd.callback.change_category = function twinklexfdCallbackChangeCategory(e) {
	var value = e.target.value;
	var root = e.target.form;
	var old_area;
	var childNodes = root.childNodes;
	for( var i = 0; i < childNodes.length; ++i ) {
		var node = childNodes[i];
		if( 
			node instanceof Element &&
			node.getAttribute( 'name' ) == 'work_area' 
		) {
			old_area = node;
			break;
		}
	}
	var work_area = null;

	switch( value ) {
	case 'afd':
		work_area = new QuickForm.element( { 
				type: 'field',
				label: 'Artículos para borrado',
				name: 'work_area'
			} );
		var afd_category = work_area.append( { 
				type:'select',
				name:'xfdcat',
				label:'Escoge la categoría a la que pertenece' 
			} );

		afd_category.append( { type:'option', label:'Desconocido', value:'?', selected:true } );
		afd_category.append( { type:'option', label:'Media y música', value:'M' } );
		afd_category.append( { type:'option', label:'Organización, corporación o producto', value:'O' } );
		afd_category.append( { type:'option', label:'Biografía', value:'B' } );
		afd_category.append( { type:'option', label:'Sociedad', value:'S' } );
		afd_category.append( { type:'option', label:'Internet', value:'W' } );
		afd_category.append( { type:'option', label:'Juegos o deportes', value:'G' } );
		afd_category.append( { type:'option', label:'Ciencia y tecnología', value:'T' } );
		afd_category.append( { type:'option', label:'Ficción y artes', value:'F' } );
		afd_category.append( { type:'option', label:'Lugares y transportes', value:'P' } );
		afd_category.append( { type:'option', label:'Inclasificable', value:'I' } );
		afd_category.append( { type:'option', label:'Sin debate todavía', value:'U' } );

		work_area.append( {
				type: 'textarea',
				name: 'xfdreason',
				label: 'Reason: '
			} );
		work_area.append( { type:'submit' } );
		work_area = work_area.render();
		old_area.parentNode.replaceChild( work_area, old_area );
		break;
	case 'tfd':
		work_area = new QuickForm.element( { 
				type: 'field',
				label: 'Plantillas para borrado',
				name: 'work_area'
			} );
		work_area.append( {
				type: 'textarea',
				name: 'xfdreason',
				label: 'Razón: '
			} );
		work_area.append( { type:'submit' } );
		work_area = work_area.render();
		old_area.parentNode.replaceChild( work_area, old_area );
		break;
	case 'mfd':
		work_area = new QuickForm.element( { 
				type: 'field',
				label: 'Miscellany for deletion',
				name: 'work_area'
			} );
		work_area.append( {
				type: 'textarea',
				name: 'xfdreason',
				label: 'Reason: '
			} );
		work_area.append( { type:'submit' } );
		work_area = work_area.render();
		old_area.parentNode.replaceChild( work_area, old_area );
		break;
	case 'ifd':
		work_area = new QuickForm.element( { 
				type: 'field',
				label: 'Images for deletion',
				name: 'work_area'
			} );
		work_area.append( {
				type: 'checkbox',
				name: 'pui',
				list: [
					{
						label: 'Possible unfree image',
						value: 'pui',
						tooltip: 'Image have disputed source or licensing information'
					}
				]
			} );
		work_area.append( {
				type: 'textarea',
				name: 'xfdreason',
				label: 'Reason: '
			} );
		work_area.append( { type:'submit' } );
		work_area = work_area.render();
		old_area.parentNode.replaceChild( work_area, old_area );
		break;
	case 'cfd':
		work_area = new QuickForm.element( { 
				type: 'field',
				label: 'Categories for discussion',
				name: 'work_area'
			} );
		var cfd_category = work_area.append( {
				type: 'select',
				label: 'Choose type of action wanted: ',
				name: 'xfdcat',
				event: function(e) {
					var value = e.target.value;
					var target = e.target.form.xfdtarget;
					if( value == 'cfd' ) {
						target.disabled = true;
					} else {
						target.disabled = false;
					}
				}
			} );
		cfd_category.append( { type:'option', label: 'Deletion', value: 'cfd', selected:true } );
		cfd_category.append( { type:'option', label:'Merge', value:'cfm' } );
		cfd_category.append( { type:'option', label:'Renaming', value:'cfr' } );
		cfd_category.append( { type:'option', label:'Convert into article', value:'cfc' } );

		work_area.append( {
				type: 'input',
				name: 'xfdtarget',
				label: 'Target page: ',
				disabled: true,
				value: ''
			} );
		work_area.append( {
				type: 'textarea',
				name: 'xfdreason',
				label: 'Reason: '
			} );
		work_area.append( { type:'submit' } );
		work_area = work_area.render();
		old_area.parentNode.replaceChild( work_area, old_area );
		break;
	case 'rfd':
		work_area = new QuickForm.element( { 
				type: 'field',
				label: 'Redirects for discussion',
				name: 'work_area'
			} );
		work_area.append( {
				type: 'textarea',
				name: 'xfdreason',
				label: 'Reason: '
			} );
		work_area.append( { type:'submit' } );
		work_area = work_area.render();
		old_area.parentNode.replaceChild( work_area, old_area );
		break;
	default:
		work_area = new QuickForm.element( { 
				type: 'field',
				label: 'Nothing for anything',
				name: 'work_area'
			} );
		work_area = work_area.render();
		old_area.parentNode.replaceChild( work_area, old_area );
		break;
	}
}

twinklexfd.callbacks = {
	afd: {
		main: function ( self ) {
			var xmlDoc = self.responseXML;
			var titles = xmlDoc.evaluate( '//allpages/p/@title', xmlDoc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );

			// There has been no earlier entries with this prefix, just go on.
			if( titles.snapshotLength <= 0 ) {
				self.params.numbering = self.params.number = '';
				numbering = number = '';
			} else {
				var number = 0;
				for( var i = 0; i < titles.snapshotLength; ++i ) {
					var title = titles.snapshotItem(i).value;

					// First, simple test, is there an instance with this exact name?
					if( title == 'Wikipedia:Consultas de borrado//' + mw.config.get('wgPageName') ) {
						number = Math.max( number, 1 );
						continue;
					}

					var order_re = new RegExp( '^' +
							RegExp.escape( 'Wikipedia:Consultas de borrado/' + mw.config.get('wgPageName'), true ) +
							'\\s*\\(\\s*(\\d+)(?:(?:th|nd|rd|st) nom(?:ination)?)?\\s*\\)\\s*$'
					);
					var match = order_re.exec( title );

					// No match; A non-good value
					if( match == null ) {
						continue;
					}

					// A match, set number to the max of current
					number = Math.max( number, Number(match[1]) );
				}
				self.params.number = num2order( parseInt( number ) + 1);
				self.params.numbering = number > 0 ? ' (' + self.params.number + ' nomination)' : '';
			}

			Status.info( 'Next discussion page","[[Wikipedia:Consultas de borrado/' + mw.config.get('wgPageName') + self.params.numbering + ']]' );

			// Tagging article
			var query = {
				'title': mw.config.get('wgPageName'),
				'action': 'submit'
			};
			var wikipedia_wiki = new Wikipedia.wiki( 'Tagging article with deletion tag', query, twinklexfd.callbacks.afd.article );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();

			// Discussion page
			query = {
				'title': 'Wikipedia:Consultas de borrado/' + mw.config.get('wgPageName') + self.params.numbering,
				'action': 'submit'
			};

			// Updating data for the action completed event
			Wikipedia.actionCompleted.redirect = query['title'];
			Wikipedia.actionCompleted.notice = "Nomination completed, redirecting now to the discussion page";

			var wikipedia_wiki = new Wikipedia.wiki( 'Creating article deletion discussion page', query, twinklexfd.callbacks.afd.discussionPage );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();

			// Todays list
			var date = new Date();

			query = {
				'title': 'Wikipedia:Articles for deletion/Log/' + date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate(),
				'action': 'submit'
			};

			var wikipedia_wiki = new Wikipedia.wiki( 'Adding discussion to todays list', query, twinklexfd.callbacks.afd.todaysList );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();

			// Notification to first contributor

			var query = {
				'action': 'query',
				'prop': 'revisions',
				'titles': mw.config.get('wgPageName'),
				'rvlimit': 1,
				'rvprop': 'user',
				'rvdir': 'newer'
			}
			var callback = function( self ) {
				var xmlDoc = self.responseXML;
				var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
				var query = {
					'title': 'User talk:' + user,
					'action': 'submit'
				};
				var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinklexfd.callbacks.afd.userNotification );
				wikipedia_wiki.params = self.params;
				wikipedia_wiki.get();
			}
			var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback );
			wikipedia_api.params = self.params;
			wikipedia_api.post();
		},
		article: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': undefined, // Per memo
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Nominated for deletion; see [[Wikipedia:Articles for deletion/" + mw.config.get('wgPageName') + self.params.numbering + ']].'+ TwinkleConfig.summaryAd,
				'wpTextbox1': "\{\{" + ( self.params.number == '' ? "subst:cdb\}\}\n" : 'subst:afdx|' + self.params.number + "}}\n" ) + form.wpTextbox1.value
			};
			self.post( postData );
		},
		discussionPage: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Abriendo consulta de borrado a  \[\[" + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': "\{\{subst:cdb2|pg=" + mw.config.get('wgPageName') + "|cat=" + self.params.xfdcat + "|texto=" + self.params.reason + " \~\~\~\~\}\}\n"
			};
			self.post( postData );
		},
		todaysList: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var old_text = form.wpTextbox1.value;

			var text = old_text.replace( /(<\!-- Add new entries to the TOP of the following list -->\n+)/, "$1\{\{subst:afd3|pg=" + mw.config.get('wgPageName') + self.params.numbering + "\}\}\n");
			if( text == old_text ) {
				self.statelem.error( 'failed to find target spot to add the discussion to.' );
				return;
			}
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Adding \[\[Wikipedia:Articles for deletion/" + mw.config.get('wgPageName') + self.params.numbering + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			text += "\n\{\{subst:AFDWarning|1=" + mw.config.get('wgPageName') + ( self.params.numbering != '' ? '|order=&#32;' + self.params.numbering : '' ) + "\}\} \~\~\~\~";
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'AfD nomination of \[\[' + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}
	},
	tfd: {
		taggingTemplate: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': undefined, // Per memo
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Nominated for deletion; see \[\[Wikipedia:Templates for deletion#" + mw.config.get('wgPageName') + '\]\].'+ TwinkleConfig.summaryAd,
				'wpTextbox1': "<noinclude>\{\{tfd|" + mw.config.get('wgTitle') + "\}\}\n</noinclude>" + form.wpTextbox1.value
			};
			self.post( postData );
		},
		todaysList: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var old_text = form.wpTextbox1.value;
			text = old_text.replace( '-->', "-->\n\{\{subst:tfd2|" + mw.config.get('wgTitle') + "|text=" + self.params.reason + ". \~\~\~\~\}\}");
			if( text == old_text ) {
				self.statelem.error( 'failed to find target spot to add the discussion to.' );
				return;
			}
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Adding [[Template:" + mw.config.get('wgTitle') + ']].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			text += "\n\{\{subst:tfdnotice|1=" + mw.config.get('wgTitle') + "\}\} \~\~\~\~";
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'TfD nomination of \[\[Template:' + mw.config.get('wgTitle') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}
	},
	mfd: {
		main: function( self ) {
			var xmlDoc = self.responseXML;
			var titles = xmlDoc.evaluate( '//allpages/p/@title', xmlDoc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );

			// There has been no earlier entries with this prefix, just go on.
			if( titles.snapshotLength <= 0 ) {
				self.params.numbering = self.params.number = '';
				numbering = number = '';
			} else {
				var number = 0;
				for( var i = 0; i < titles.snapshotLength; ++i ) {
					var title = titles.snapshotItem(i).value;

					// First, simple test, is there an instance with this exact name?
					if( title == 'Wikipedia:Articles for deletion/' + mw.config.get('wgPageName') ) {
						number = Math.max( number, 1 );
						continue;
					}

					var order_re = new RegExp( '^' +
							RegExp.escape( 'Wikipedia:Miscellany for deletion/' + mw.config.get('wgPageName'), true ) +
							'\\s*\\(\\s*(\\d+)(?:(?:th|nd|rd|st) nom(?:ination)?)?\\s*\\)\\s*$'
					);
					var match = order_re.exec( title );

					// No match; A non-good value
					if( match == null ) {
						continue;
					}

					// A match, set number to the max of current
					number = Math.max( number, Number(match[1]) );
				}
				self.params.number = num2order( parseInt( number ) + 1);
				self.params.numbering = number > 0 ? ' (' + self.params.number + ' nomination)' : '';
			}


			self.statelem.info( 'next in order is [[Wikipedia:Miscellany for deletion/' + mw.config.get('wgPageName') + self.params.numbering + ']]');

			// Tagging article
			var query = {
				'title': mw.config.get('wgPageName'),
				'action': 'submit'
			};

			var wikipedia_wiki = new Wikipedia.wiki( 'Tagging page with deletion tag', query, twinklexfd.callbacks.mfd.taggingPage );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();

			// Discussion page
			var query = {
				'title': 'Wikipedia:Miscellany for deletion/' + mw.config.get('wgPageName') + this.params.numbering,
				'action': 'submit'
			};

			// Updating data for the action completed event
			Wikipedia.actionCompleted.redirect = query['title'];
			Wikipedia.actionCompleted.notice = "Nomination completed, redirecting now to the discussion page";

			wikipedia_wiki = new Wikipedia.wiki( 'Creating page deletion discussion page', query, twinklexfd.callbacks.mfd.discussionPage );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();

			// Todays list
			var query = {
				'title': 'Wikipedia:Miscellany for deletion',
				'action': 'submit',
				'section': 2
			};

			wikipedia_wiki = new Wikipedia.wiki( 'Adding deletion discussion to todays list', query, twinklexfd.callbacks.mfd.todaysList );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();

			// Notification to first contributor
			var query = {
				'action': 'query',
				'prop': 'revisions',
				'titles': mw.config.get('wgPageName'),
				'rvlimit': 1,
				'rvprop': 'user',
				'rvdir': 'newer'
			}
			var callback = function( self ) {
				var xmlDoc = self.responseXML;
				var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
				var query = {
					'title': 'User talk:' + user,
					'action': 'submit'
				};
				var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinklexfd.callbacks.mfd.userNotification );
				wikipedia_wiki.params = self.params;
				wikipedia_wiki.get();
			}
			var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback );
			wikipedia_api.params = self.params;
			wikipedia_api.post();
		},
		taggingPage: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': undefined, // Per memo
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Nominated for deletion; see [[Wikipedia:Miscellany for deletion/" + mw.config.get('wgPageName') + self.params.numbering + ']].'+ TwinkleConfig.summaryAd,
				'wpTextbox1': "\{\{" + ( self.params.number == '' ? "subst:mfd\}\}\n" : 'subst:mfdx|' + self.params.number + "}}\n" ) + form.wpTextbox1.value
			};
			self.post( postData );
		},
		discussionPage: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Creating deletion discussion page for \[\[" + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': "\{\{subst:mfd2|pg=" + mw.config.get('wgPageName') + "|text=" + self.params.reason + " \~\~\~\~\}\}\n"
			};
			self.post( postData );
		},
		todaysList: function( self ) {
			var form = self.responseXML.getElementById('editform');

			var text = form.wpTextbox1.value;
			var date = new Date();

			var month =  new Number( date.getUTCMonth() + 1 );
			var day =  new Number( date.getUTCDate() );
			var year = new Number( date.getUTCFullYear() );
			var today_date = year.zeroFill( 4 ) + '-' + month.zeroFill( 2 ) + '-' + day.zeroFill( 2 );
			var today_regex = new RegExp( "(\\=\\=\\=\\[\\[" + RegExp.escape( today_date ) + "\\]\\]\\=\\=\\=)" );
			var new_data = "\n\{\{subst:mfd3|pg=" + mw.config.get('wgPageName') + self.params.numbering + "\}\}";

			if( today_regex.test( text ) ) { // we have a section allready
				self.statelem.info( 'Found todays section, proceeding to add new entry' );
				text = text.replace( today_regex, "$1\n" + new_data );
			} else { // we need to create a new section
				self.statelem.info( 'No section for today found, proceeding to create one' );
				var old_text = text;
				text = text.replace( '-->', "-->\n===\[\[" + today_date + "\]\]===\n" + new_data );
				if( text == old_text ) {
					self.statelem.error( 'failed to find target spot to add the discussion to' );
					return;
				}
			}

			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Adding \[\[Wikipedia:Miscellany for deletion/" + mw.config.get('wgPageName') + self.params.numbering + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			text += "\n\{\{subst:MFDWarning|1=" + mw.config.get('wgPageName') + ( self.params.numbering != '' ? '|order=&#32;' + this.params.numbering : '' ) + "\}\} \~\~\~\~";
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'MfD nomination of \[\[' + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}
	},
	ifd: {
		main: function( self ) {
			var xmlDoc = self.responseXML;
			var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
			self.params.uploader = user;
			var query = {
				'title': 'Wikipedia:Images and media for deletion/' + self.params.date,
				'action': 'submit'
			};

			wikipedia_wiki = new Wikipedia.wiki( 'Adding deletion discussion to todays list', query, twinklexfd.callbacks.ifd.todaysList );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();

			// Updating data for the action completed event
			Wikipedia.actionCompleted.redirect = query['title'];
			Wikipedia.actionCompleted.notice = "Nomination completed, redirecting now to the discussion page";

			// Notification to first contributor

			var query = {
				'title': 'User talk:' + self.params.uploader,
				'action': 'submit'
			};
			wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + self.params.uploader + ')', query, twinklexfd.callbacks.ifd.userNotification );
			wikipedia_wiki.get();
		},
		taggingImage: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': undefined, // Per 
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "This image is being considered for deletion in accordance with Wikipedia's [[Wikipedia:Deletion policy|Deletion policy]]; See \[\[Wikipedia:Images for deletion#" + mw.config.get('wgPageName') + '\]\].'+ TwinkleConfig.summaryAd,
				'wpTextbox1': "\{\{ifd|log=" + self.params.date + "\}\}\n" + form.wpTextbox1.value
			};
			self.post( postData );
		},
		todaysList: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Adding discussion for \[\[:" + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': form.wpTextbox1.value + "\n\{\{subst:ifd2|1=" + mw.config.get('wgTitle') + "|Uploader=" + self.params.uploader + "|Reason=" + self.params.reason + "\}\} \~\~\~\~"
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			text += "\n\{\{subst:idw|1=" + mw.config.get('wgPageName') + "\}\}";
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'Notification: IfD nomination of \[\[' + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		},
		tagInstancesMain: function( self ) {
			var xmlDoc = self.responseXML;
			var nsResolver = xmlDoc.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
			var snapshot = xmlDoc.evaluate('//imageusage/iu/@title', xmlDoc, nsResolver, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );

			if( snapshot.snapshotLength == 0 ) {
				return;
			}

			var statusIndicator = new Status('Tagging instances image', '0%');
			var total = snapshot.snapshotLength * 2;

			var date = new Date();
			var dateString = date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();

			imageTaggingCounter = 0;
			var onsuccess = function( self ) {
				var obj = self.params.obj;
				var total = self.params.total;
				var now = parseInt( 100 * ++imageTaggingCounter/total ) + '%';
				obj.update( now );
				self.statelem.unlink();
				if( imageTaggingCounter == total ) {
					obj.info( now + ' (completed)' );
					Wikipedia.removeCheckpoint();
				}
			}

			var onloaded = onsuccess;

			var onloading = function( self ) {}


			Wikipedia.addCheckpoint();
			for ( var i = 0; i < snapshot.snapshotLength; ++i ) {
				var title = snapshot.snapshotItem(i).value;
				var query = {
					'title': title,
					'action': 'submit'
				}
				var wikipedia_wiki = new Wikipedia.wiki( "Tagging of " + title, query, twinklexfd.callbacks.ifd.tagInstances );
				wikipedia_wiki.params = { title:title, total:total, obj:statusIndicator, date:dateString };
				wikipedia_wiki.onloading = onloading;
				wikipedia_wiki.onloaded = onloaded;
				wikipedia_wiki.onsuccess = onsuccess;
				wikipedia_wiki.get();
			}
		},
		tagInstances: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var text = form.wpTextbox1.value;
			var old_text = text;
			var wikiPage = new Mediawiki.Page( text );

			var tag = "\{\{ifdc|1=Image:" + mw.config.get('wgTitle') + "|log=" + self.params.date + "\}\}";
			wikiPage.addToImageComment( mw.config.get('wgTitle'), tag );

			text = wikiPage.getText();
			if( text == old_text ) {
				// Nothing to do, return
				self.onsuccess( self );
				Wikipedia.actionCompleted();
				return;
			}
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'Tagging [[:Image:' + mw.config.get('wgTitle') + "]] which is up for deletion at [[WP:IFD|Images for deletion]]" + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}
	},
	pui: {
		taggingImage: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': undefined, // Per 
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "This image has been listed on [[Wikipedia:Possibly unfree images]] because the information on its source or copyright status is disputed; See \[\[Wikipedia:Possibly unfree images#" + mw.config.get('wgPageName') + '\]\].'+ TwinkleConfig.summaryAd,
				'wpTextbox1': "\{\{pui|log=" + self.params.date + "\}\}\n" + form.wpTextbox1.value
			};
			self.post( postData );
		},
		todaysList: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Adding discussion for \[\[:" + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': form.wpTextbox1.value + "\n\{\{subst:pui2|image=" + mw.config.get('wgTitle') + "|reason=" + self.params.reason + "\}\} \~\~\~\~"
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			text += "\n\{\{subst:idw-pui|1=" + mw.config.get('wgPageName') + "\}\} --\~\~\~\~";
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'Notification: PUI posting of \[\[' + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		},
		tagInstancesMain: function( self ) {
			var xmlDoc = self.responseXML;
			var nsResolver = xmlDoc.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
			var snapshot = xmlDoc.evaluate('//imageusage/iu/@title', xmlDoc, nsResolver, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );

			if( snapshot.snapshotLength == 0 ) {
				return;
			}
			var statusIndicator = new Status('Tagging instances image', '0%');
			var total = snapshot.snapshotLength * 2;

			var date = new Date();
			var dateString = date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();

			imageTaggingCounter = 0;
			var onsuccess = function( self ) {
				var obj = self.params.obj;
				var total = self.params.total;
				var now = parseInt( 100 * ++imageTaggingCounter/total ) + '%';
				obj.update( now );
				self.statelem.unlink();
				if( imageTaggingCounter == total ) {
					obj.info( now + ' (completed)' );
					Wikipedia.removeCheckpoint();
				}
			}
			var onloaded = onsuccess;

			var onloading = function( wikipedia_wiki ) {}


			Wikipedia.addCheckpoint();
			for ( var i = 0; i < snapshot.snapshotLength; ++i ) {
				var title = snapshot.snapshotItem(i).value;
				var query = {
					'title': title,
					'action': 'submit'
				}
				var wikipedia_wiki = new Wikipedia.wiki( "Tagging " + title, query, twinklexfd.callbacks.pui.tagInstances );
				wikipedia_wiki.params = { title:title, total:total, obj:statusIndicator, date:dateString };
				wikipedia_wiki.onloading = onloading;
				wikipedia_wiki.onloaded = onloaded;
				wikipedia_wiki.onsuccess = onsuccess;
				wikipedia_wiki.get();
			}
		},
		tagInstances: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var text = form.wpTextbox1.value;
			var old_text = text;
			var wikiPage = new Mediawiki.Page( text );

			var tag = "\{\{puic|1=Image:" + mw.config.get('wgTitle') + "|log=" + self.params.date + "\}\}";
			wikiPage.addToImageComment( mw.config.get('wgTitle'), tag );

			text = wikiPage.getText();
			if( text == old_text ) {
				// Nothing to do, return
				self.onsuccess( self );
				Wikipedia.actionCompleted();
				return;
			}
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'Tagging [[:Image:' + mw.config.get('wgTitle') + "]] which have been listed on [[WP:PUI|Possible unfree images]]" + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}

	},
	cfd: {
		taggingCategory: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var added_data = "";
			var summary = "";
			switch( self.params.xfdcat ) {
			case 'cfd':
				added_data = "\{\{subst:cfd\}\}";
				summary = "This category is being considered for deletion in accordance with [[WP:CDP|CDP]];" + TwinkleConfig.summaryAd;
				break;
			case 'cfm':
				added_data = "\{\{subst:cfm|" + self.params.target.replace('Category:','') + "\}\}";
				summary = "This category is being considered for merging in accordance with [[WP:CDP|CDP]];" + TwinkleConfig.summaryAd;
				break;
			case 'cfr':
				added_data = "\{\{subst:cfr|" + self.params.target.replace('Category:','') + "\}\}";
				summary = "This category is being considered for renaming in accordance with [[WP:CDP|CDP]];" + TwinkleConfig.summaryAd;
				break;
			case 'cfc':
				added_data = "\{\{subst:cfc|" + self.params.target + "\}\}";
				summary = "This category is being considered for conversion in accordance with [[WP:CDP|CDP]];" + TwinkleConfig.summaryAd;
				break;
			}
			var postData = {
				'wpMinoredit': undefined, // Per the cabal
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': summary,
				'wpTextbox1': added_data + "\n" + form.wpTextbox1.value
			};
			self.post( postData );
		},
		todaysList: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var added_data = "";
			var summary = "";
			switch( this.params.xfdcat ) {
			case 'cfd':
				added_data = "\{\{subst:cfd2|1=" + mw.config.get('wgTitle') + "|text=" + self.params.reason + " \~\~\~\~\}\}";
				summary = "Added delete nomination of [[:" + mw.config.get('wgPageName') + "]];" + TwinkleConfig.summaryAd;
				break;
			case 'cfm':
				added_data = "\{\{subst:cfm2|1=" + mw.config.get('wgTitle') + "|2=" + self.params.target + "|text=" + self.params.reason + " \~\~\~\~\}\}";
				summary = "Added merge nomination of [[:" + mw.config.get('wgPageName') + "]];" + TwinkleConfig.summaryAd;
				break;
			case 'cfr':
				added_data = "\{\{subst:cfr2|1=" + mw.config.get('wgTitle') + "|2=" + self.params.target + "|text=" + self.params.reason + " \~\~\~\~\}\}";
				summary = "Added rename nomination of [[:" + mw.config.get('wgPageName') + "]];" + TwinkleConfig.summaryAd;
				break;
			case 'cfc':
				added_data = "\{\{subst:cfc2|1=" + mw.config.get('wgTitle') + "|2=" + self.params.target + "|text=" + self.params.reason + " \~\~\~\~\}\}";
				summary = "Added convert nomination of [[:" + mw.config.get('wgPageName') + "]];" + TwinkleConfig.summaryAd;
				break;
			}
			var old_text = form.wpTextbox1.value;

			text = old_text.replace( '-->', "-->\n" + added_data );
			if( text == old_text ) {
				self.statelem.error( 'failed to find target spot to add the discussion to' );
				return;
			}
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': summary,
				'wpTextbox1': text
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			var intext = "";
			switch( self.params.xfdcat ) {
			case 'cfd':
				intext = 'for deletion';
				break;
			case 'cfm':
				intext = 'for merging into \{\{lc|' + self.params.target + "\}\}" ;
				break;
			case 'cfr':
				intext = 'for renaming to \{\{lc|' + self.params.target + "\}\}" ;
				break;
			case 'cfc':
				intext = 'for converting into an article named \{\{lc|' + self.params.target + "\}\}" ;
				break;
			}
			text += "\n==CfD nomination of [[:" + mw.config.get('wgPageName') + "]]==\nI have nominated \{\{lc|" + mw.config.get('wgTitle') + "\}\} " + intext + ". Your opinions on the matter are welcome; please participate in the discussion by adding your comments at [[" + self.params.todaysPage + "#" + mw.config.get('wgPageName') + "|the discussion page]]. Thank you. \~\~\~\~";

			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'Notification: CfD nomination of \[\[:' + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}
	},
	rfd: {
		main: function( self ) {
			var xmlDoc = self.responseXML;
			var target = xmlDoc.evaluate( '//redirects/r/@to', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
			if( !target ) {
				self.statelem.error( 'no target of this redirect, aborting' );
				return;
			}
			self.params.target = target;

			// Tagging redirect
			var query = {
				'title': mw.config.get('wgPageName'),
				'action': 'submit'
			};

			wikipedia_wiki = new Wikipedia.wiki( 'Tagging redirect with rfd tag', query, twinklexfd.callbacks.rfd.taggingRedirect );
			wikipedia_wiki.followRedirect = false;
			wikipedia_wiki.get();

			var date = new Date();
			var today = date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();
			var query = {
				'title': 'Wikipedia:Redirects for discussion/Log/' + today,
				'action': 'submit'
			};

			wikipedia_wiki = new Wikipedia.wiki( 'Adding deletion discussion to todays list', query, twinklexfd.callbacks.rfd.todaysList );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();

			// Updating data for the action completed event
			Wikipedia.actionCompleted.redirect = query['title'];
			Wikipedia.actionCompleted.notice = "Nomination completed, redirecting now to the discussion page";

			self.params.todaysPage = query['title'];

			// Notifying initial contributor
			var query = {
				'action': 'query',
				'prop': 'revisions',
				'titles': mw.config.get('wgPageName'),
				'rvlimit': 1,
				'rvprop': 'user',
				'rvdir': 'newer'
			}
			var callback = function( self ) {
				var xmlDoc = self.responseXML;
				var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
				var query = {
					'title': 'User talk:' + user,
					'action': 'submit'
				};
				var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinklexfd.callbacks.rfd.userNotification );
				wikipedia_wiki.params = self.params;
				wikipedia_wiki.get();
			}
			var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback );
			wikipedia_api.params = self.params;
			wikipedia_api.post();

		},
		taggingRedirect: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var postData = {
				'wpMinoredit': undefined, // Per 
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "This redirect has been listed on [[Wikipedia:Redirects for discussion]]\]\]." + TwinkleConfig.summaryAd,
				'wpTextbox1': "\{\{rfd\}\}\n" + form.wpTextbox1.value
			};
			self.post( postData );
		},
		todaysList: function( self ) {
			var form = self.responseXML.getElementById('editform');
			var old_text = form.wpTextbox1.value;
			var text = old_text.replace( /(<\!-- Add new entries directly below this line -->\n+)/, "$1\{\{subst:rfd2|redirect="+ mw.config.get('wgPageName') + "|target=" + self.params.target + "|text=" + self.params.reason.toUpperCaseFirstChar() +"\}\} \~\~\~\~\n" );
			if( text == old_text ) {
				self.statelem.error( 'failed to find target spot to add the discussion to.' );
				return;
			}
 
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': "Adding [[" + mw.config.get('wgPageName') + ']].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		},
		userNotification: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var text = form.wpTextbox1.value;
			text += "\n==RfD nomination of [[:" + mw.config.get('wgPageName') + "]]==\nI have nominated " + ln( mw.config.get('wgNamespaceNumber'), mw.config.get('wgTitle') ) + " for discussion. Your opinions on the matter are welcome; please participate in the discussion by adding your comments at [[" + self.params.todaysPage + "#" + mw.config.get('wgPageName') + "|the discussion page]]. Thank you. \~\~\~\~";
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSection': '',
				'wpSummary': 'Notification: RFD posting of \[\[' + mw.config.get('wgPageName') + '\]\].' + TwinkleConfig.summaryAd,
				'wpTextbox1': text
			};
			self.post( postData );
		}
	}
}

twinklexfd.callback.evaluate = function(e) {

	wgPageName = mw.config.get('wgPageName').replace( /_/g, ' ' ); // for queen/king/whatever and country!

	var type =  e.target.category.value;
	var reason = e.target.xfdreason.value;
	if( type in {'afd':'','cfd':''} ) {
		var xfdcat = e.target.xfdcat.value;
	}
	if( type == 'ifd' ) {
		var pui = e.target.pui.checked;
	}

	Status.init( e.target );

	if( type == null ) {
		Status.error( 'Error', 'no action given' );
		return;
	}

	switch( type ) {
	case 'afd': // AFD
		var query = {
			'action': 'query',
			'list': 'allpages',
			'apprefix': 'Articles for deletion/' + mw.config.get('wgPageName'),
			'apnamespace': 4,
			'apfilterredir': 'nonredirects',
			'aplimit': userIsInGroup( 'sysop' ) ? 5000 : 500
		};
		var wikipedia_api = new Wikipedia.api( 'Tagging article with deletion tag', query, twinklexfd.callbacks.afd.main );
		wikipedia_api.params = { reason:reason, xfdcat:xfdcat };
		wikipedia_api.post();
		break;
	case 'tfd': // TFD

		Wikipedia.addCheckpoint();
		// Tagging article
		var query = {
			'title': mw.config.get('wgPageName'),
			'action': 'submit'
		};
		wikipedia_wiki = new Wikipedia.wiki( 'Tagging template with deletion tag', query, twinklexfd.callbacks.tfd.taggingTemplate );
		wikipedia_wiki.get();

		// Adding discussion
		var date = new Date();

		query = {
			'title': 'Wikipedia:Templates for deletion/Log/' + date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate(),
			'action': 'submit',
			'section': 1
		};

		// Updating data for the action completed event
		Wikipedia.actionCompleted.redirect = query['title'];
		Wikipedia.actionCompleted.notice = "Nomination completed, redirecting now to the list of today";

		wikipedia_wiki = new Wikipedia.wiki( 'Adding discussion to todays list', query, twinklexfd.callbacks.tfd.todaysList );
		wikipedia_wiki.params = { reason:reason };
		wikipedia_wiki.get();

		var query = {
			'action': 'query',
			'prop': 'revisions',
			'titles': mw.config.get('wgPageName'),
			'rvlimit': 1,
			'rvprop': 'user',
			'rvdir': 'newer'
		}
		var callback = function( self ) {
			var xmlDoc = self.responseXML;
			var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
			var query = {
				'title': 'User talk:' + user,
				'action': 'submit'
			};
			var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinklexfd.callbacks.tfd.userNotification );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();
		}
		var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback );
		wikipedia_api.params = self.params;
		wikipedia_api.post();

		Wikipedia.removeCheckpoint();
		break;
	case 'mfd': // MFD

		var query = {
			'action': 'query',
			'list': 'allpages',
			'apprefix': 'Miscellany for deletion/' + mw.config.get('wgPageName'),
			'apnamespace': 4,
			'apfilterredir': 'nonredirects',
			'aplimit': userIsInGroup( 'sysop' ) ? 5000 : 500
		};
		var wikipedia_api = new Wikipedia.api( 'Quering allpages', query, twinklexfd.callbacks.mfd.main );
		wikipedia_api.params = { reason:reason, xfdcat:xfdcat };
		wikipedia_api.post();
		break;
	case 'ifd': // IFD

		var date = new Date();
		var dateString = date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();
		var params = { reason: reason, date: dateString };

		Wikipedia.addCheckpoint();
		if( pui ) {
			// Tagging image
			var query = {
				'title': mw.config.get('wgPageName'),
				'action': 'submit'
			};

			var wikipedia_wiki = new Wikipedia.wiki( 'Tagging image with PUI tag', query, twinklexfd.callbacks.pui.taggingImage );
			wikipedia_wiki.params = params;
			wikipedia_wiki.get();
			// Adding discussion

			query = {
				'title': 'Wikipedia:Possibly unfree images/' + dateString,
				'action': 'submit'
			};

			// Updating data for the action completed event
			Wikipedia.actionCompleted.redirect = query['title'];
			Wikipedia.actionCompleted.notice = "Nomination completed, redirecting now to the list of today";

			wikipedia_wiki = new Wikipedia.wiki( 'Adding discussion to todays list', query, twinklexfd.callbacks.pui.todaysList );
			wikipedia_wiki.params = params;
			wikipedia_wiki.get();

			var query = {
				'action': 'query',
				'prop': 'revisions',
				'titles': mw.config.get('wgPageName'),
				'rvlimit': 1,
				'rvprop': 'user',
				'rvdir': 'newer'
			}
			var callback = function( self ) {
				var xmlDoc = self.responseXML;
				var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
				var query = {
					'title': 'User talk:' + user,
					'action': 'submit'
				};
				var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinklexfd.callbacks.pui.userNotification );
				wikipedia_wiki.params = self.params;
				wikipedia_wiki.get();
			}
			var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback );
			wikipedia_api.params = params;
			wikipedia_api.post();

			Wikipedia.removeCheckpoint();

			// adding tag to captions
			var query = {
				'action': 'query',
				'list': 'imageusage',
				'titles': mw.config.get('wgPageName'),
				'iulimit': userIsInGroup( 'sysop' ) ? 5000 : 500 // 500 is max for normal users, 5000 for bots and sysops
			};

			var wikipedia_api = new Wikipedia.api( 'Grabbing image links', query, twinklexfd.callbacks.pui.tagInstancesMain );
			wikipedia_api.post();

		} else {
			// Tagging image
			var query = {
				'title': mw.config.get('wgPageName'),
				'action': 'submit'
			};

			var wikipedia_wiki = new Wikipedia.wiki( 'Tagging image with deletion tag', query, twinklexfd.callbacks.ifd.taggingImage );
			wikipedia_wiki.params = params;
			wikipedia_wiki.get();

			// Contributor specific edits
			var query = {
				'action': 'query',
				'prop': 'revisions',
				'titles': mw.config.get('wgPageName'),
				'rvlimit': 1,
				'rvprop': 'user',
				'rvdir': 'newer'
			}
			var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, twinklexfd.callbacks.ifd.main );
			wikipedia_api.params = params;
			wikipedia_api.post();

			// adding tag to captions
			var query = {
				'action': 'query',
				'list': 'imageusage',
				'titles': mw.config.get('wgPageName'),
				'iulimit': userIsInGroup( 'sysop' ) ? 5000 : 500 // 500 is max for normal users, 5000 for bots and sysops
			};

			var wikipedia_api = new Wikipedia.api( 'Grabbing image links', query, twinklexfd.callbacks.ifd.tagInstancesMain );
			wikipedia_api.post();
		}
		Wikipedia.removeCheckpoint();
		break;
	case 'cfd':
		Wikipedia.addCheckpoint();
		if( e.target.xfdtarget ) {
			var target = e.target.xfdtarget.value.replace( /^\:?Category\:/, '' );
		} else {
			var target = '';
		}

		var date = new Date();
		var todaysPage = 'Wikipedia:Categories for discussion/Log/' + date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();

		// Updating data for the action completed event
		Wikipedia.actionCompleted.redirect = todaysPage;
		Wikipedia.actionCompleted.notice = "Nomination completed, redirecting now to the discussion page";

		// Tagging category

		var query = {
			'title': mw.config.get('wgPageName'),
			'action': 'submit'
		};
		var params = { reason:reason, xfdcat:xfdcat, target:target };

		var wikipedia_wiki = new Wikipedia.wiki( 'Tagging category with tag', query, twinklexfd.callbacks.cfd.taggingCategory );
		wikipedia_wiki.params = params;
		wikipedia_wiki.get();

		// Todays list
		var query = {
			'title': todaysPage,
			'action': 'submit',
			'section': 2
		};

		var wikipedia_wiki = new Wikipedia.wiki( 'Adding discussion to todays list', query, twinklexfd.callbacks.cfd.todaysList );
		wikipedia_wiki.params = params;
		wikipedia_wiki.get();

		// Notification to first contributor
		var query = {
			'action': 'query',
			'prop': 'revisions',
			'titles': mw.config.get('wgPageName'),
			'rvlimit': 1,
			'rvprop': 'user',
			'rvdir': 'newer'
		}
		var callback = function( self ) {
			var xmlDoc = self.responseXML;
			var user = xmlDoc.evaluate( '//rev/@user', xmlDoc, null, XPathResult.STRING_TYPE, null ).stringValue;
			var query = {
				'title': 'User talk:' + user,
				'action': 'submit'
			};
			var wikipedia_wiki = new Wikipedia.wiki( 'Notifying of initial contributor (' + user + ')', query, twinklexfd.callbacks.cfd.userNotification );
			wikipedia_wiki.params = self.params;
			wikipedia_wiki.get();
		}
		var wikipedia_api = new Wikipedia.api( 'Grabbing data of initial contributor', query, callback );
		wikipedia_api.params = { xfdcat:xfdcat, target:target, todaysPage:todaysPage };
		wikipedia_api.post();
		Wikipedia.removeCheckpoint();
		break;
	case 'rfd':
		var query = {
			'action': 'query',
			'titles': mw.config.get('wgPageName'),
			'redirects': true
		};
		var wikipedia_api = new Wikipedia.api( 'Quering redirect', query, twinklexfd.callbacks.rfd.main );
		wikipedia_api.params = { reason:reason };
		wikipedia_api.post();
		break;
	}
}