Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>
function goodarticleNominateButton() {
	if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) {
		return;
	}
	mw.util.addPortletLink('p-cactions', "javascript:goodarticleNominate()", "GAN", "ga-nominate", "Nominate for Good article status", "");
}
$(goodarticleNominateButton);

function goodarticleNominate() {
	function createOption( data ) {
		var option = document.createElement( 'option' );
		option.setAttribute( 'value', data.value );
		if( data.selected ) {
			option.setAttribute( 'selected', 'selected' );
		}
		option.setAttribute( 'label', data.label );
		option.appendChild( document.createTextNode( data.label ) );

		return option;
	}

	function createInput( data ) {
		var div = document.createElement( data.elem || 'span' );
		var input = document.createElement( 'input' );
		input.setAttribute( 'value', data.value );
		input.setAttribute( 'name', data.name );
		input.setAttribute( 'id', data.id );
		input.setAttribute( 'type', data.type );
		if( data.size ) {
			input.setAttribute( 'size', data.size );
		}
		if( data.checked ) {
			input.setAttribute( 'checked', 'checked' );
		}
		if( data.disabled ) {
			input.setAttribute( 'disabled', 'disabled' );
		}
		if( data.event && data.type == 'button' ){
			input.addEventListener( 'click', data.event, true );
		}
		if( data.type == 'button' || data.type == 'submit' || data.type == 'reset' ) {
			div.appendChild( input );
		} else {
			var label = document.createElement( 'label' );
			label.setAttribute( 'for', data.id );
			label.appendChild( document.createTextNode( data.text ) );
			if( [ 'radio', 'checkbox' ].indexOf( data.type ) != -1 ) {
				div.appendChild( input );
				div.appendChild( label );
			} else {
				div.appendChild( label );
				div.appendChild( input );
			}
		}

		return div;
	}

	goodarticleNominate.Window = new SimpleWindow( 600, 300 );
	goodarticleNominate.Window.setTitle( "Enter what kind of action is wanted" );
	goodarticleNominate.form = document.createElement( 'form' );
	goodarticleNominate.form.setAttribute( 'action', 'javascript:void(0);');
	goodarticleNominate.form.addEventListener( 'submit',goodarticleNominate.evaluate , true );
/*
	var main_choices = document.createElement( 'select' );
	main_choices.setAttribute('name', 'main_choices');
	main_choices.setAttribute('id', 'twNominateMainChoices');

	main_choices.appendChild( createOption( { label: 'Afd', selected: wgNamespaceNumber == 0, value: 'afd' } ) );
	main_choices.appendChild( createOption( { label: 'Tfd', selected: wgNamespaceNumber == 10, value: 'tfd' } ) );
	main_choices.appendChild( createOption( { label: 'Ifd', selected: wgNamespaceNumber == 6, value: 'ifd' } ) );
	main_choices.appendChild( createOption( { label: 'Cfd', selected: wgNamespaceNumber == 14, value: 'cfd' } ) );
	main_choices.appendChild( createOption( { label: 'UCfd', selected: false, value: 'ucfd' } ) );
	main_choices.appendChild( createOption( { label: 'Rfd', selected: false, value: 'rfd' } ) );
	main_choices.appendChild( createOption( { label: 'Sfd', selected: false, value: 'sfd' } ) );
	main_choices.appendChild( createOption( { label: 'Mfd', selected: [0, 10, 6, 14].indexOf(wgNamespaceNumber) == -1, value: 'mfd' } ) );

	goodarticleNominate.form.appendChild( main_choices );
	goodarticleNominate.form.appendChild( document.createElement( 'br' ) );
*/
	var choices = document.createElement( 'fieldset' );
	var choices_legend = document.createElement( 'legend' );
	choices_legend.appendChild( document.createTextNode( 'Choice type of action' ) );
	goodarticleNominate.form.appendChild( choices );

	var afdcat = document.createElement( 'select' );
	afdcat.setAttribute('name', 'afdcat');
	afdcat.setAttribute('id', 'twNominateMainChoices');

	choices.appendChild( choices_legend );
	choices.appendChild( afdcat );

	afdcat.appendChild( createOption( { label: 'Unknown', selected:true, value: '?' } ) );
	afdcat.appendChild( createOption( { label: 'Media and music', value: 'M' } ) );
	afdcat.appendChild( createOption( { label: 'Organisation, corporation, or product', value: 'O' } ) );
	afdcat.appendChild( createOption( { label: 'Biographical', value: 'B' } ) );
	afdcat.appendChild( createOption( { label: 'Society topics', value: 'S' } ) );
	afdcat.appendChild( createOption( { label: 'Web or internet', value: 'W' } ) );
	afdcat.appendChild( createOption( { label: 'Games or sports', value: 'T' } ) );
	afdcat.appendChild( createOption( { label: 'Science and technology', value: 'T' } ) );
	afdcat.appendChild( createOption( { label: 'Fiction and the arts', value: 'F' } ) );
	afdcat.appendChild( createOption( { label: 'Places and transportation', value: 'P' } ) );
	afdcat.appendChild( createOption( { label: 'Indiscernible or unclassifiable topic', value: 'I' } ) );
	afdcat.appendChild( createOption( { label: 'Debate not yet sorted', value: 'U' } ) );

	choices.appendChild( document.createElement( 'br' ) );

	
	choices.appendChild( createInput( {
		id:'twNominateReason',
		value:'',
		text:'Reason ',
		type:'text',
		name:'Nominatereason',
		size:80
	} ) );
	goodarticleNominate.form.appendChild( createInput( {
		id:'twNominateSubmit',
		value: 'Submit',
		name:'submit',
		type:'submit'
	} ) );
	goodarticleNominate.Window.setContent( goodarticleNominate.form );
	goodarticleNominate.Window.display();
}

goodarticleNominate.evaluate = function(e) {

	goodarticleNominate.type =  'afd' //goodarticleNominate.form.main_choices.value;
	goodarticleNominate.reason = goodarticleNominate.form.Nominatereason.value;
	goodarticleNominate.afdcat = goodarticleNominate.form.afdcat.value;

	Status.init( goodarticleNominate.form );

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

	switch( goodarticleNominate.type ) {
		case 'afd':

		Status.status( 'Grabbing data of eventual previous nominations' );
		var query = {
			'title': 'Special:Prefixindex',
			'from': 'Articles for deletion/' + wgTitle,
			'namespace': 4
		};
		goodarticleNominate.xmlhttp = sajax_init_object();
		goodarticleNominate.xmlhttp.overrideMimeType('text/xml');
		goodarticleNominate.xmlhttp.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), true);
		goodarticleNominate.xmlhttp.onload = goodarticleNominate.evaluateafd;
		goodarticleNominate.xmlhttp.send( null );
	}
}

goodarticleNominate.evaluateafd = function() {
	var a_tags = goodarticleNominate.xmlhttp.responseXML.getElementsByTagName('a');
	var re = new RegExp( RegExp.escape( 'Articles for deletion/' + wgTitle ) );
	var number = 0;
	for( var i in a_tags ) {
		var title = a_tags[i].title;
		if( re.exec( title ) ) {
			var n = /\((?:\w|\s)*?(\d+)(?:\w|\s)*?\)\s*$/.exec( title );
			if( n && n[1] > number ) {
				number = n[1];
			} else if( number == 0 ) {
				number = 1;
			}
		}
	}

	if( number == 0 ) {
		number = '';
	} else {
		number = ' (' + (parseInt( number ) + 1) + ')';
	}
	Status.info( 'next in order is [[Wikipedia:Articles for deletion/' + wgTitle + number + ']]' );

	Status.status( 'Putting the deletion tag on the article...' );
	goodarticleNominate.query1 = {
		'title': wgTitle,
		'action': 'submit'
	};
	goodarticleNominate.xmlhttp1 = sajax_init_object();
	goodarticleNominate.xmlhttp1.overrideMimeType('text/xml');
	goodarticleNominate.xmlhttp1.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( goodarticleNominate.query1 ), true);
	goodarticleNominate.xmlhttp1.onload = function() {
		var form = goodarticleNominate.xmlhttp1.responseXML.getElementById('editform');
		var postData = {
			'wpMinoredit': form.wpMinoredit.checked,
			'wpWatchthis': form.wpWatchthis.checked,
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSummary': "Nominated for deletion; see [[Wikipedia:Articles for deletion/" + wgTitle + number + "]]" + goodarticleConfig.summaryAd,
			'wpTextbox1': "{{" + "subst:afd1}}\n" + form.wpTextbox1.value
		};
		goodarticleNominate.xmlhttp1 = sajax_init_object();
		goodarticleNominate.xmlhttp1.overrideMimeType('text/xml');
		goodarticleNominate.xmlhttp1.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( goodarticleNominate.query1 ), true);
		goodarticleNominate.xmlhttp1.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		goodarticleNominate.xmlhttp1.onload = function() { Status.info( 'Article tagged.' );}
		goodarticleNominate.xmlhttp1.send( QueryString.create( postData ) );
	}
	goodarticleNominate.xmlhttp1.send( null );

	Status.status( 'Creating the article\'s deletion discussion page...' );

	goodarticleNominate.query2 = {
		'title': 'Wikipedia:Articles for deletion/' + wgTitle + number,
		'action': 'submit'
	};

	goodarticleNominate.xmlhttp2 = sajax_init_object();
	goodarticleNominate.xmlhttp2.overrideMimeType('text/xml');
	goodarticleNominate.xmlhttp2.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( goodarticleNominate.query2 ), true);
	goodarticleNominate.xmlhttp2.onload = function() {
		var form = goodarticleNominate.xmlhttp2.responseXML.getElementById('editform');
		var postData = {
			'wpMinoredit': form.wpMinoredit.checked,
			'wpWatchthis': form.wpWatchthis.checked,
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSummary': "Creating deletion discussion page." + goodarticleConfig.summaryAd,
			'wpTextbox1': "{{" + "subst:afd2|pg=" + wgTitle + "|cat=" + goodarticleNominate.afdcat + "|reason=" + goodarticleNominate.reason + "}}\n"
		};
		goodarticleNominate.xmlhttp2 = sajax_init_object();
		goodarticleNominate.xmlhttp2.overrideMimeType('text/xml');
		goodarticleNominate.xmlhttp2.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( goodarticleNominate.query2 ), true);
		goodarticleNominate.xmlhttp2.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		goodarticleNominate.xmlhttp2.onload = function() { Status.info( 'Discussion page created.' );}
		goodarticleNominate.xmlhttp2.send( QueryString.create( postData ) );
	}
	goodarticleNominate.xmlhttp2.send( null );

	Status.status( 'Notifies users who monitor AfD discussion...' );

	var date = new Date();

	goodarticleNominate.query3 = {
		'title': 'Wikipedia:Articles for deletion/Log/' + date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate(),
		'action': 'submit'
	};
	goodarticleNominate.xmlhttp3 = sajax_init_object();
	goodarticleNominate.xmlhttp3.overrideMimeType('text/xml');
	goodarticleNominate.xmlhttp3.open( 'GET' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( goodarticleNominate.query3 ), true);
	goodarticleNominate.xmlhttp3.onload = function() {
		if( goodarticleNominate.xmlhttp3.readyState != 4 || goodarticleNominate.xmlhttp3.status != 200 ){return;} 
		var form = goodarticleNominate.xmlhttp3.responseXML.getElementById('editform');
		var postData = {
			'wpMinoredit': form.wpMinoredit.checked,
			'wpWatchthis': form.wpWatchthis.checked,
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSummary': "Adding nomination to list." + goodarticleConfig.summaryAd,
			'wpTextbox1': form.wpTextbox1.value + "\n {{" + "subst:afd3 | pg=" + wgTitle + number + "}}"
		};
		goodarticleNominate.xmlhttp3 = sajax_init_object();
		goodarticleNominate.xmlhttp3.overrideMimeType('text/xml');
		goodarticleNominate.xmlhttp3.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( goodarticleNominate.query3 ), true);
		goodarticleNominate.xmlhttp3.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		goodarticleNominate.xmlhttp3.onload = function() { Status.info( 'Notification complete.' );}
		goodarticleNominate.xmlhttp3.send( QueryString.create( postData ) );
	}
	goodarticleNominate.xmlhttp3.send( null );

//	window.location = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( goodarticleNominate.query2 );

}
// </nowiki>