User:Timotab/twinklexfd.js

// If TwinkleConfig aint exist. if( typeof( TwinkleConfig ) == 'undefined' ) { TwinkleConfig = function {}; } /** TwinkleConfig.summaryAd (string) If ad should be added or not to summary, default TWINKLE */ if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) { TwinkleConfig.summaryAd = " using TW"; } function num2order( num ) { switch( num ) { case 1: return ''; case 2: return '2nd'; case 3: return '3rd'; default: return num + 'th'; } } function twinklexfd { if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) { return; }	mw.util.addPortletLink( 'p-cactions', "javascript:twinklexfd.callback", "xfd", "tw-xfd", "Anything for deletion", ""); } $(twinklexfd); twinklexfd.callback = function twinklexfdCallback { var Window = new SimpleWindow( 600, 300 ); Window.setTitle( "Anything for deletion" ); var form = new QuickForm( twinklexfd.callback.evaluate ); var categories = form.append( {			type: 'select',			name: 'category',			label: 'Select wanted type of category: ',			tooltip: 'When activated, a default choice is choosen, based on what namespace you are in. This default should be the most appropriate',			event: twinklexfd.callback.change_category		} ); categories.append( {			type: 'option',			label: 'Afd',			selected: wgNamespaceNumber == Namespace.MAIN,			value: 'afd'		} ); categories.append( {			type: 'option',			label: 'Tfd',			selected: wgNamespaceNumber == Namespace.TEMPLATE,			value: 'tfd'		} ); categories.append( {			type: 'option',			label: 'Ifd/PUI',			selected: wgNamespaceNumber == Namespace.IMAGE,			value: 'ifd'		} ); categories.append( {			type: 'option',			label: 'Cfd',			selected: wgNamespaceNumber == Namespace.CATEGORY,			value: 'cfd'		} ); categories.append( {			type: 'option',			label: 'Mfd',			selected: [ Namespace.IMAGE, Namespace.MAIN, Namespace.TEMPLATE, Namespace.CATEGORY ].indexOf( wgNamespaceNumber ) == -1 ,			value: 'mfd'		} ); categories.append( {			type: 'option',			label: 'Rfd',			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: 'Articles for deletion',				name: 'work_area'			} ); var afd_category = work_area.append( { 				type:'select',				name:'xfdcat',				label:'Choose what category this nomination belongs in' 			} ); afd_category.append( { type:'option', label:'Unknown', value:'?', selected:true } ); afd_category.append( { type:'option', label:'Media and music', value:'M' } ); afd_category.append( { type:'option', label:'Organisation, corporation, or product', value:'O' } ); afd_category.append( { type:'option', label:'Biographical', value:'B' } ); afd_category.append( { type:'option', label:'Society topics', value:'S' } ); afd_category.append( { type:'option', label:'Web or internet', value:'W' } ); afd_category.append( { type:'option', label:'Games or sports', value:'G' } ); afd_category.append( { type:'option', label:'Science and technology', value:'T' } ); afd_category.append( { type:'option', label:'Fiction and the arts', value:'F' } ); afd_category.append( { type:'option', label:'Places and transportation', value:'P' } ); afd_category.append( { type:'option', label:'Indiscernible or unclassifiable topic', value:'I' } ); afd_category.append( { type:'option', label:'Debate not yet sorted', 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: 'Templates 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 '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 ); var number = 0; for( var i = 0; i < titles.snapshotLength; ++i ) { var title = titles.snapshotItem(i).value; title = title.replace( /(first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh)/, function(v) {						return {							'first': '1st',							'second': '2nd',							'third': '3rd',							'fourth': '4th',							'fifth': '5th',							'sixth': '6th',							'seventh': '7th',							'eighth': '8th',							'ninth': '9th',							'tenth': '10th',							'eleventh': '11th'						}[v];					} ); var n = /\(\s*(\d+)(?:(?:th|nd|rd|st) nom(?:ination)?)?\s*\)\s*$/.exec( title ); if( n && n[1] > number ) { number = n[1]; } else if( number == 0 ) { number = 1; }			}			if( number == 0 ) { self.params.numbering = self.params.number = ''; numbering = number = ''; } else { self.params.number = num2order( parseInt( number ) + 1); self.params.numbering = ' (' + self.params.number + ' nomination)'; }			Status.info( 'Next discussion page is Articles for deletion/' + wgPageName + self.params.numbering + '' ); // Tagging article var query = { 'title': 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:Articles for deletion/' + 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': 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, 'wpSummary': "Nominated for deletion; see Articles for deletion/" + wgPageName + self.params.numbering + '.'+ TwinkleConfig.summaryAd, 'wpTextbox1': "\{\{" + ( self.params.number == '' ? "subst:afd\}\}\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, 'wpSummary': "Creating deletion discussion page for \[\[" + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': "\{\{subst:afd2|pg=" + wgPageName + "|cat=" + self.params.xfdcat + "|text=" + 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=" + wgPageName + self.params.numbering + "\}\}\n"); if( text == old_text ) { Status.error( self.currentAction + ': 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, 'wpSummary': "Adding \[\[Wikipedia:Articles for deletion/" + 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=" + 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, 'wpSummary': 'AfD nomination of \[\[' + 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, 'wpSummary': "Nominated for deletion; see \[\[Wikipedia:Templates for deletion#" + wgPageName + '\]\].'+ TwinkleConfig.summaryAd, 'wpTextbox1': " \{\{tfd|" + wgTitle + "\}\}\n " + 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|" + wgTitle + "|text=" + self.params.reason + ". \~\~\~\~\}\}"); if( text == old_text ) { Status.error( self.currentAction + ': 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, 'wpSummary': "Adding Template:" + 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=" + 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, 'wpSummary': 'TfD nomination of \[\[Template:' + 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 ); var number = 0; for( var i = 0; i < titles.snapshotLength; ++i ) { var title = titles.snapshotItem(i).value; title = title.replace( /(first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh)/, function(v) {						return {							'first': '1st',							'second': '2nd',							'third': '3rd',							'fourth': '4th',							'fifth': '5th',							'sixth': '6th',							'seventh': '7th',							'eighth': '8th',							'ninth': '9th',							'tenth': '10th',							'eleventh': '11th'						}[v];					} ); var n = /\(\s*(\d+)(?:(?:th|nd|rd|st) nom(?:ination)?)?\s*\)\s*$/.exec( title ); if( n && n[1] > number ) { number = n[1]; } else if( number == 0 ) { number = 1; }			}			if( number == 0 ) { self.params.numbering = self.params.number = ''; numbering = number = ''; } else { self.params.number = num2order( parseInt( number ) + 1); self.params.numbering = ' (' + self.params.number + ' nomination)'; }Status.info( 'next in order is Miscellany for deletion/' + wgPageName + this.params.numbering + ''); // Tagging article var query = { 'title': 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/' + 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': 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, 'wpSummary': "Nominated for deletion; see Miscellany for deletion/" + 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, 'wpSummary': "Creating deletion discussion page for \[\[" + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': "\{\{subst:mfd2|pg=" + 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 ); Status.info( 'todays date: ' + today_date ); var today_regex = new RegExp( "(\\=\\=\\=\\[\\[" + RegExp.escape( today_date ) + "\\]\\]\\=\\=\\=)" ); var new_data = "\n\{\{subst:mfd3|pg=" + wgPageName + self.params.numbering + "\}\}"; if( today_regex.test( text ) ) { // we have a section allready Status.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 Status.info( 'No section for today found, proceeding to ccreate one' ); var old_text = text; text = text.replace( '-->', "-->\n===\[\[" + today_date + "\]\]===\n" + new_data ); if( text == old_text ) { Status.error( self.currentAction + ': 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, 'wpSummary': "Adding \[\[Wikipedia:Miscellany for deletion/" + 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=" + 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, 'wpSummary': 'MfD nomination of \[\[' + 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, 'wpSummary': "This image is being considered for deletion in accordance with Wikipedia's Deletion policy; See \[\[Wikipedia:Images for deletion#" + 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, 'wpSummary': "Adding discussion for \[\[:" + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': form.wpTextbox1.value + "\n\{\{subst:ifd2|1=" + 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=" + 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, 'wpSummary': 'Notification: IfD nomination of \[\[' + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': text };			self.post( postData ); },		tagInstancesMain: function( self ) { var statusIndicator = document.createElement( 'div' ); Status.status( [ statusIndicator ] ); statusIndicator.appendChild( document.createTextNode( 'Tagging instances image, status: ' ) ); statusIndicator.appendChild( document.createTextNode( '0%' ) ); 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 ); var total = snapshot.snapshotLength * 2; var date = new Date; var dateString = date.getUTCFullYear + ' ' + date.getUTCMonthName + ' ' + date.getUTCDate; imageTaggingCounter = 0; var onsuccess = function( wikipedia_wiki ) { var obj = wikipedia_wiki.params.obj; var total = wikipedia_wiki.params.total; obj.replaceChild( document.createTextNode( parseInt( 100 * ++imageTaggingCounter/total ) + '%' ), obj.lastChild ); if( imageTaggingCounter == total ) { Status.info( 'tagging of instances 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:" + wgTitle + "|log=" + self.params.date + "\}\}"; wikiPage.addToImageComment( 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, 'wpSummary': 'Tagging Image:' + wgTitle + " which is up for deletion at 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, 'wpSummary': "This image has been listed on Possibly unfree images because the information on its source or copyright status is disputed; See \[\[Wikipedia:Possibly unfree images#" + 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, 'wpSummary': "Adding discussion for \[\[:" + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': form.wpTextbox1.value + "\n\{\{subst:pui2|image=" + 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=" + 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, 'wpSummary': 'Notification: PUI posting of \[\[' + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': text };			self.post( postData ); },		tagInstancesMain: function( self ) { var statusIndicator = document.createElement( 'div' ); Status.status( [ statusIndicator ] ); statusIndicator.appendChild( document.createTextNode( 'Tagging instances image, status: ' ) ); statusIndicator.appendChild( document.createTextNode( '0%' ) ); 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 ); var total = snapshot.snapshotLength * 2; var date = new Date; var dateString = date.getUTCFullYear + ' ' + date.getUTCMonthName + ' ' + date.getUTCDate; imageTaggingCounter = 0; var onsuccess = function( wikipedia_wiki ) { var obj = wikipedia_wiki.params.obj; var total = wikipedia_wiki.params.total; obj.replaceChild( document.createTextNode( parseInt( 100 * ++imageTaggingCounter/total ) + '%' ), obj.lastChild ); if( imageTaggingCounter == total ) { Status.info( 'tagging of instances 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 of " + 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:" + wgTitle + "|log=" + self.params.date + "\}\}"; wikiPage.addToImageComment( 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, 'wpSummary': 'Tagging Image:' + wgTitle + " which have been listed on 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 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 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 CDP;" + TwinkleConfig.summaryAd; break; case 'cfc': added_data = "\{\{subst:cfc|" + self.params.target + "\}\}"; summary = "This category is being considered for conversion in accordance with 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, '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=" + wgTitle + "|text=" + self.params.reason + " \~\~\~\~\}\}"; summary = "Added delete nomination of " + wgPageName + ";" + TwinkleConfig.summaryAd; break; case 'cfm': added_data = "\{\{subst:cfm2|1=" + wgTitle + "|2=" + self.params.target + "|text=" + self.params.reason + " \~\~\~\~\}\}"; summary = "Added merge nomination of " + wgPageName + ";" + TwinkleConfig.summaryAd; break; case 'cfr': added_data = "\{\{subst:cfr2|1=" + wgTitle + "|2=" + self.params.target + "|text=" + self.params.reason + " \~\~\~\~\}\}"; summary = "Added rename nomination of " + wgPageName + ";" + TwinkleConfig.summaryAd; break; case 'cfc': added_data = "\{\{subst:cfc2|1=" + wgTitle + "|2=" + self.params.target + "|text=" + self.params.reason + " \~\~\~\~\}\}"; summary = "Added convert nomination of " + wgPageName + ";" + TwinkleConfig.summaryAd; break; }			var old_text = form.wpTextbox1.value; text = old_text.replace( '-->', "-->\n" + added_data ); if( text == old_text ) { Status.error( self.currentAction + ': 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, '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 " + wgPageName + "==\nI have nominated \{\{lc|" + wgTitle + "\}\} " + intext + ". Your opinions on the matter are welcome; please participate in the discussion by adding your comments at 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, 'wpSummary': 'Notification: CfD nomination of \[\[:' + 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 ) { Status.error( 'No target of this redirect, aborting.' ); return; }			self.params.target = target; // Tagging redirect var query = { 'title': wgPageName, 'action': 'submit' };			wikipedia_wiki = new Wikipedia.wiki( 'Tagging redirect with rfd tag', query, twinklexfd.callbacks.rfd.taggingRedirect ); 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': 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, 'wpSummary': "This redirect has been listed on Redirects for discussion\]\]." + TwinkleConfig.summaryAd, 'wpTextbox1': "\{\{rfd\}\}\n" + form.wpTextbox1.value };			self.post( postData ); },		todaysList: function( self ) { var form = self.responseXML.getElementById('editform'); var text = form.wpTextbox1.value; 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, 'wpSummary': "Adding " + wgPageName + '.' + TwinkleConfig.summaryAd, 'wpTextbox1': text + "\{\{subst:rfd2|redirect="+ wgPageName + "|target=" + self.params.target + "|text=" + self.params.reason.toUpperCaseFirstChar +"\}\}" };			self.post( postData ); },		userNotification: function( self ) { var form = self.responseXML.getElementById( 'editform' ); var text = form.wpTextbox1.value; text += "\n==RfD nomination of " + wgPageName + "==\nI have nominated \{\{ln|" + namespaces[wgNamespaceNumber] + '|' + wgTitle + "\}\} for discussion. Your opinions on the matter are welcome; please participate in the discussion by adding your comments at 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, 'wpSummary': 'Notification: RFD posting of \[\[' + wgPageName + '\]\].' + TwinkleConfig.summaryAd, 'wpTextbox1': text };			self.post( postData ); }	} } twinklexfd.callback.evaluate = function(e) { wgPageName = 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( 'no action given' ); return; }	switch( type ) { case 'afd': // AFD var query = { 'action': 'query', 'list': 'allpages', 'apprefix': 'Articles for deletion/' + 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': 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': 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/' + 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': 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': 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': 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': 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': 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': 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': 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': 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': 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; } }