From Wikipedia, the free encyclopedia
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.

$(document).ready(function(){

	afcDialogButtonText = "Make a selection";

	if($("#afcSubmissionButton").length > 0)

	{

		$("#afcSubmissionButton").first().append('<div id="afcDialog" style="display:none;"><h2>Wait! Have you included <a href="/wiki/Wikipedia:CITE">citations</a> to independent, <a href="/wiki/Wikipedia:RS">reliable</a> sources in your article?</h2><input type="radio" id="afcOptionA" name="afcOptions"><b>A.</b> No, I forgot. I\'ll submit my page later.<br><input type="radio" id="afcOptionB" name="afcOptions"><b>B.</b> No. What are citations? How do I add them?<br><input type="radio" id="afcOptionC" name="afcOptions"><b>C.</b> No. There aren\'t any; I\'m writing about a subject that is new and/or not well known.<br><input type="radio" id="afcOptionD" name="afcOptions"><b>D.</b> No. I looked, but I am a new editor and need some help to find them.<br><input type="radio" id="afcOptionE" name="afcOptions"><b>E.</b> No, because this is a disambiguation page, template, or redirect, not an article.<br><input type="radio" id="afcOptionF" name="afcOptions"><b>F.</b> Yes, I have included citations to reliable sources in my article.<br></div>');



		$("#afcOptionA").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Never mind");afcDialogButtonText ="Never mind";});

		$("#afcOptionB").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Get help");afcDialogButtonText ="Get help";});

		$("#afcOptionC").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Get help");afcDialogButtonText ="Get help";});

		$("#afcOptionD").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Get help");afcDialogButtonText ="Get help";});

		$("#afcOptionE").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Submit");afcDialogButtonText ="Submit";});

		$("#afcOptionF").click(function(){$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first().text("Submit");afcDialogButtonText ="Submit";});



		$("#afcSubmissionButton, #afcSubmissionButton > a").click(function(){

			$( "#afcDialog" ).dialog(

				{ buttons:  

					{ text: afcDialogButtonText , click: function() { 

					var checkedInput = $('input[name=afcOptions]:checked');

					var apiPath = mw.config.get('wgScriptPath') + "/api.php";

					

						if(checkedInput.length > 0)

						{

							switch(checkedInput.attr("id"))

							{

								case "afcOptionB":

									var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"};

									$.post(apiPath, catData, function(response)

									{

										if(typeof response.query.pageswgArticleId].categories == "undefined")

										{

											var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "Article not submitted, automatically adding category", minor: "true", appendtext: "\n\n[[:Category:Articles not submitted at AfC]]", token: mw.user.tokens.get( 'csrfToken' )};

											$.post(apiPath, data, function(){window.open(mw.util.getUrl("WP:Referencing for beginners"), "_self");});

										}

										else

										{

											window.open(mw.util.getUrl("WP:Referencing for beginners"), "_self");

										}

									});

									break;

								case "afcOptionC": 

									var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"};

									$.post(apiPath, catData, function(response)

									{

										if(typeof response.query.pageswgArticleId].categories == "undefined")

										{

											var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "\nArticle not submitted, automatically adding category", minor: "true", appendtext: "\n\n[[:Category:Articles not submitted at AfC]]", token: mw.user.tokens.get( 'csrfToken' )};

											$.post(apiPath, data, function(){window.open(mw.util.getUrl("WP:42"), "_self");});

										}

										else

										{

											window.open(mw.util.getUrl("WP:42"), "_self");

										}

									});

									break;

								case "afcOptionD": 

									var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"};

									$.post(apiPath, catData, function(response)

									{

										if(typeof response.query.pageswgArticleId].categories == "undefined")

										{

											var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "\nArticle not submitted, automatically adding category", minor: "true", appendtext: "\n\n[[:Category:Articles not submitted at AfC]]", token: mw.user.tokens.get( 'csrfToken' )};

											$.post(apiPath, data, function(){window.open(mw.util.getUrl("WP:Teahouse/Questions"), "_self");});

										}

										else

										{

											window.open(mw.util.getUrl("WP:Teahouse/Questions"), "_self");

										}

									});

									break;

								case "afcOptionE": 

								case "afcOptionF": 

									window.open(mw.config.get("wgScript") + "?title="+ mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) +"&action=edit&section=new&preload=Template:AFC_submission/Subst&editintro=Template:AFC_submission/Subst/Editintro", "_self");

									break;

								case "afcOptionA":

								default:

									alert("Your article has not been submitted.");

									$( this ).dialog( "close" );

									break;

							}

						}

						return false;

					} },

					{ text: "Cancel", click: function() {

						$( this ).dialog( "close" ); 

						return false;

					} }

				], 

				minWidth:500

				}

			);

			return false;

			

		});

	}

});