मीडियाविकि:Gadget-afchelper.js/submissions.js

विकिपिडिया, एक स्वतन्त्र विश्वकोशबाट
सूचना: सम्पादनहरू प्रकाशित गरेपछि, परिवर्तनहरू हेर्नको लागि तपाईंले आफ्नो ब्राउजरको क्यासलाई बाइपास गर्नुपर्छ। गुगल क्रोम, फायरफक्स, माइक्रोसफ्ट एजसफारी: Shift कुञ्जी थिचिराखेर रिलोड उपकरणपट्टी बटनमा थिच्नुहोस्।
/* Uploaded from https://github.com/WPAFC/afch, commit: 6b2d22e1bc688680b303f742f3b41ef0adf6202b (master) */
//<nowiki>
// Script should be located at [[MediaWiki:Gadget-afchelper.js/submissions.js]]
var afcHelper_PageName = mw.config.get('wgPageName').replace(/_/g, ' ');
var afcHelper_AJAXnumber = 0;
var afcHelper_submissionTitle = mw.config.get('wgTitle').replace(/लेख सृजना\//g, '');
var afcHelper_cache = {};
var disambig_re = /Disambig|Mil-unit-dis|Hndis|Geodis|Numberdis/i;
var typetemplate_re = /\{\{\s*documentation\s*(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/gi;
var afcHelper_reasonhash = [{
	label: 'नक्कल लेखहरू',
	value: 'नक्कल लेखहरू',
	disabled: true
}, {
	label: 'exists - निवेदन मुख्यस्थानमा पहिल्यै अर्को लेखद्वारा नक्कल गरिएको छ',
	value: 'exists',
	reason: 'निवेदन पहिल्यै मुख्य स्थानमा अवस्थित छ'
}, {
	label: 'dup - निवेदन अर्को अवस्थित निवेदनको एक नक्कल हो',
	value: 'dup',
	reason: 'निवेदन अर्को अवस्थित निवेदनको एक नक्कल हो'
}, {
	label: 'परीक्षण सम्पादनहरू',
	value: 'परीक्षण सम्पादनहरू',
	disabled: true
}, {
	label: 'blank - निवेदन खाली छ',
	value: 'blank',
	reason: 'निवेदन खाली छ'
}, {
	label: 'test - निवेदन एक परीक्षण सम्पादन देखिन्छ (कृपया अस्वीकार गर्नु अघि यो एक उपकरणको परीक्षण होईन भनेर निश्चित गर्नुहोस्)',
	value: 'test',
	reason: 'निवेदन एक परीक्षण सम्पादन हो'
}, {
	label: 'जीमाजी/बर्बरता',
	value: 'जीमाजी/बर्बरता',
	disabled: true
}, {
	label: 'van - निवेदन बर्बरता, एक नकारात्मक स्रोतविहिन जीमाजी, वा एक आक्रमण पृष्ठ हो (कृपया पृष्ठ खाली गर्नुहोस् र मेटाउनको लागि यसलाई चिन्ह लगाउनुहोस्)',
	value: 'van',
	reason: 'निवेदन बर्बरता, एक नकारात्मक स्रोतविहिन जीमाजी, वा एक आक्रमण पृष्ठ हो'
}, {
	label: 'ilc - निवेदन एक जीमाजी हो जसले न्यूनतम इनलाइन उद्धरण आवश्यकताहरू पूरा गर्दैन',
	value: 'ilc',
	reason: 'निवेदनले न्यूनतम इनलाइन उद्धरण आवश्यकताहरू पूरा गर्दैन'
}, {
	label: 'blp - निवेदनले स्रोतविहिन, सम्भावित मानहानि दावीहरू जीमाजी उल्लङ्घन समावेश गर्दछ, तर स्रोतहरूको लागि प्रतीक्षा गर्नुहोस् (कृपया पृष्ठ खाली गर्नुहोस् तर शीमे नगर्नुहोस्)',
	value: 'blp',
	reason: 'निवेदन जीमाजी अनुरूप छैन'
}, {
	label: 'समायोजन गर्दै',
	value: 'समायोजन गर्दै',
	disabled: true
}, {
	label: 'mergeto - निवेदन अर्को लेखमा समायोजन गर्नुपर्नेछ (टिप्पणी बक्समा तल लेखमा सुत्रको साथ टिप्पणी टाइप गर्नुहोस्)',
	value: 'mergeto',
	reason: 'निवेदन एकदम छोटो छ तर समायोजन गर्न सकिन्छ'
}, {
	label: 'स्पष्ट [[वि:होइन]] उल्लङ्घन',
	value: 'स्पष्ट [[वि:होइन]] उल्लङ्घन',
	disabled: true
}, {
	label: 'joke - निवेदन एक ठट्टा वा छल जस्तो देखिन्छ',
	value: 'joke',
	reason: 'निवेदन एक ठट्टा जस्तो देखिन्छ'
}, {
	label: 'not - निवेदन [[विकिपिडिया:विकिपिडिया के होइन]] असफल',
	value: 'not',
	reason: 'निवेदन [[वि:होइन]] द्वारा कभर गरिएको छ'
}, {
	label: 'गद्य मुद्दाहरू',
	value: 'गद्य मुद्दाहरू',
	disabled: true
}, {
	label: 'lang - निवेदन नेपालीमा छैन',
	value: 'lang',
	reason: 'निवेदन नेपालीमा छैन'
}, {
	label: 'cv - निवेदन एक प्रतिलिपि अधिकार उल्लङ्घन हो (लेख खाली गर्नुहोस्, तलको बक्समा लिङ्कहरू हाल्नुहोस्, र मेटाउन चिह्नित गर्नुहोस्)',
	value: 'cv',
	reason: 'निवेदन एक प्रतिलिपि अधिकार उल्लङ्घन हो'
}, {
	label: 'redirect - निवेदन एक अनुप्रेषण अनुरोध हो',
	value: 'redirect',
	reason: 'निवेदन एक अनुप्रेषण अनुरोध हो'
}, {
	label: 'news - निवेदन एकल घटनाको समाचार कहानी जस्तो देखिन्छ',
	value: 'news',
	reason: 'निवेदन एकल घटनाको समाचार कहानी जस्तो देखिन्छ'
}, {
	label: 'dict - निवेदन एक शब्दकोष परिभाषा हो',
	value: 'dict',
	reason: 'निवेदन एक शब्दकोष परिभाषा हो'
}, {
	label: 'plot - निवेदनमा प्राय जसो एक प्लट सारांश छ',
	value: 'plot',
	reason: 'निवेदनमा एक प्लट सारांश छ'
}, {
	label: 'adv - निवेदन एक विज्ञापन जस्तै छ',
	value: 'adv',
	reason: 'निवेदन एक विज्ञापन जस्तै छ'
}, {
	label: 'context - निवेदनले अपर्याप्त प्रसङ्ग प्रदान गर्दछ',
	value: 'context',
	reason: 'निवेदनले अपर्याप्त प्रसङ्ग प्रदान गर्दछ'
}, {
	label: 'essay - निवेदन एक निबन्ध जस्तै छ',
	value: 'essay',
	reason: 'निवेदन एक निबन्ध जस्तै छ'
}, {
	label: 'npov - निवेदन औपचारिक, तटस्थ ज्ञानकोश दृष्टिकोणबाट लेखिएको छैन',
	value: 'npov',
	reason: 'निवेदन औपचारिक, तटस्थ दृष्टिकोणबाट लेखिएको छैन'
}, {
	label: 'उल्लेखनीयता',
	value: 'उल्लेखनीयता',
	disabled: true
}, {
	label: 'neo - निवेदन एक नवशब्दिकाको बारेमा हो जसले उल्लेखनीयता दिशानिर्देशहरू पूरा गर्दैन',
	value: 'neo',
	reason: 'निवेदन एक नवशब्दिका हो'
}, {
	label: 'web - निवेदन वेब सामग्रीको बारेमा हो जसले उल्लेखनीयता दिशानिर्देशहरू पूरा गर्दैन',
	value: 'web',
	reason: 'विषय गैर-उल्लेखनीय वेब सामग्री जस्तो देखिन्छ'
}, {
	label: 'prof - निवेदन प्राध्यापकको बारेमा हो जसले उल्लेखनीयता दिशानिर्देशहरू पूरा गर्दैन',
	value: 'prof',
	reason: 'विषय एक गैर-उल्लेखनीय शैक्षिक जस्तो देखिन्छ'
}, {
	label: 'athlete - निवेदन एक खेलाडीको बारेमा हो जसले उल्लेखनीयता दिशानिर्देशहरू पूरा गर्दैन',
	value: 'athlete',
	reason: 'विषय एक गैर-उल्लेखनीय खेलाडीको बारेमा जस्तो देखिन्छ'
}, {
	label: 'music - निवेदन एक सङ्गीतकार वा साङ्गीतिक कार्यको बारेमा हो जसले उल्लेखनीयता दिशानिर्देशहरू पूरा गर्दैन',
	value: 'music',
	reason: 'विषय एक गैर-उल्लेखनीय साङ्गीतिक कलाकार वा कार्य जस्तो देखिन्छ'
}, {
	label: 'film - निवेदन एक चलचित्रको बारेमा हो जसले उल्लेखनीयता दिशानिर्देशहरू पूरा गर्दैन',
	value: 'film',
	reason: 'विषय गैर-उल्लेखनीय फिल्म जस्तो देखिन्छ'
}, {
	label: 'corp - निवेदन एक कम्पनी वा संगठनको बारेमा हो जसले उल्लेखनीयता दिशानिर्देशहरू पूरा गर्दैन',
	value: 'corp',
	reason: 'विषय गैर-उल्लेखनीय कम्पनी वा संगठन जस्तो देखिन्छ'
}, {
	label: 'bio - निवेदन एक व्यक्तिको बारेमा हो जसले उल्लेखनीयता दिशानिर्देशहरू पूरा गर्दैन',
	value: 'bio',
	reason: 'विषय गैर-उल्लेखनीय व्यक्ति जस्तो देखिन्छ'
}, {
	label: 'nn - निवेदनले सामान्य उल्लेखनीयता दिशानिर्देश पूरा गर्दैन (सम्भव भएमा अधिक विशिष्ट कारण प्रयोग गर्नुहोस्)',
	value: 'nn',
	reason: 'विषय गैर-उल्लेखनीय देखिन्छ'
}, {
	label: 'स्रोत उल्लेख',
	value: 'स्रोत उल्लेख',
	disabled: true
}, {
	label: 'v - निवेदनमा अनुचित स्रोत छ',
	value: 'v',
	reason: 'निवेदन स्रोतविहिन छ वा केवल अविश्वसनीय स्रोतहरू समावेश गर्दछ'
}, {
	label: 'अन्य',
	value: 'अन्य',
	disabled: true
}, {
	label: 'अनुकूलन - तलको बक्समा अस्वीकार गर्ने कारण प्रविष्ट गर्नुहोस्, प्रासङ्गिक नीतिहरूमा सुत्रित गरेर',
	value: 'reason',
	reason: ''
}, {
	label: 'अस्वीकार गर्ने एक कारण चयन गर्नुहोस्',
	selected: true,
	value: 'reason',
	disabled: true,
	reason: ''
}];

function afcHelper_init() {
	displayMessage('<div id="afcHelper_loadingmsg">लेख सृजना सहायक स्क्रिप्टको लागि लोड गर्दै...</div>');

	if (!wfSupportsAjax()) {
		displayMessage('<span class="afch-notice">ओहो! माफ गर्नुहोस्, तपाईँको ब्राउजर यस स्क्रिप्ट ह्यान्डल गर्न धेरै पुरानो देखिन्छ वा AJAX समर्थन गर्दैन। उत्तम परिणामका लागि कृपया मोजिला फायरफक्स, एप्पल सफारी, गुगल क्रोम, वा ओपेराको नयाँ संस्करण प्रयोग गर्नुहोस्।</span>');
		return;
	}

	form = '<div id="afcHelper_initialform">';
	form += afcHelper_setup();
	form += '<h3>Reviewing ' + afcHelper_PageName + '</h3>';

	if (BETA) form += '<div id="afcHelper_betanotice">लेख सृजना सहायक स्क्रिप्टको लागि तपाईँ हाल एक <b>बेटा संस्करण</b> चलाइरहनु भएको छ। केहि सुविधाहरूले ईच्छा अनुसार काम नगर्न सक्छ; कृपया त्रुटि रिपोर्ट <a href="https://ne.wikipedia.org/wiki/विकिपिडिया_वार्ता:विकिपरियोजना_लेख_सृजना/सहायक_लिपि" target="_blank">यहाँ</a>गर्नुहोस्।</div>';

	var template_status_re = /\{\{\s*afc submission\s*\|\s*(\S|\s*)\s*\|/gi;
	var temp_statuses = new Array();
	var match;
	while (match = template_status_re.exec(pagetext)) {
		temp_statuses.push(match[1]);
	}
	var template_statuses = new Array();
	for (var i = 0; i < temp_statuses.length; i++) {
		status = temp_statuses[i];
		if (status === "|") status = "";
		template_statuses[i] = status.toLowerCase();
	}
	if (template_statuses.length == 0) template_statuses = false; // if there is no template on page

	if ($.inArray("", template_statuses) != -1 || $.inArray("r", template_statuses) != -1) {
		form += '<button class="afcHelper_button" type="button" id="afcHelper_accept_button" onclick="afcHelper_prompt(\'accept\')">स्वीकार्नुहोस्</button>';
		form += '<button class="afcHelper_button" type="button" id="afcHelper_decline_button" onclick="afcHelper_prompt(\'decline\')">अस्वीकार्नुहोस्</button>';
	}

	if ($.inArray("", template_statuses) != -1 || $.inArray("r", template_statuses) != -1 || $.inArray("d", template_statuses) != -1) form += '<button class="afcHelper_button" type="button" id="afcHelper_comment_button" onclick="afcHelper_prompt(\'comment\')">टिप्पणी</button>';

	if (template_statuses === false || $.inArray("t", template_statuses) != -1 || (($.inArray("d", template_statuses) != -1) && ($.inArray("", template_statuses) == -1))) form += '<button class="afcHelper_button" type="button" id="afcHelper_submit_button" onclick="afcHelper_prompt(\'submit\')">पेशगर्नुहोस्</button>';

	if (template_statuses === false) form += '<button class="afcHelper_button" type="button" id="afcHelper_draft_button" onclick="afcHelper_prompt(\'draft\')">मस्यौदा निवेदन चिह्नित गर्नुहोस्</button>';

	if ($.inArray("r", template_statuses) != -1) {
		form += '<button class="afcHelper_button" type="button" id="afcHelper_unmark_button" onclick="afcHelper_act(\'unmark\')">समीक्षाको चिन्ह हटाउनुहोस्</button>';
	} else if ($.inArray("", template_statuses) != -1) {
		form += '<button class="afcHelper_button" type="button" id="afcHelper_mark_button" onclick="afcHelper_prompt(\'mark\')">समीक्षाको चिन्ह लगाउनुहोस्</button>';
	}

	if (template_statuses === false || $.inArray("", template_statuses) != -1 || $.inArray("r", template_statuses) != -1 || $.inArray("d", template_statuses) != -1 || $.inArray("t", template_statuses) != -1) form += '<button class="afcHelper_button" type="button" id="afcHelper_cleanup_button" onclick="afcHelper_act(\'cleanup\')">निवेदन सफा गर्नुहोस्</button>';

	if (afcHelper_g13_eligible(afcHelper_PageName)) form += '<button class="afcHelper_button" type="button" id="afcHelper_g13_button" onclick="afcHelper_act(\'g13\')">सा१३ शीघ्र हटाउन निवेदनलाई चिनो लगाउनुहोस्</button> <button class="afcHelper_button" type="button" id="afcHelper_postpone_g13_button" onclick="afcHelper_prompt(\'postpone_g13\')">सा१३ मेटाउन स्थगित गर्नुहोस्</button>';

	form += '<div id="afcHelper_extra"></div>';

	displayMessage(form);
}

function afcHelper_prompt(type) {
	if (type === 'accept') {
		var afcHelper_assessment = [{
			label: 'बी-वर्ग',
			value: 'बी'
		}, {
			label: 'सी-वर्ग',
			value: 'सी'
		}, {
			label: 'छोटो-वर्ग',
			value: 'छोटो'
		}, {
			label: 'अपूर्ण-वर्ग',
			value: 'अपूर्ण'
		}, {
			label: 'सूची-वर्ग',
			value: 'सूची'
		}];
		// checking for ANY submission template (doesn't matter if declined) for the type parameter
		// TODO: use boolean variables and add the disambiguation check to the accept stuff deeper
		var afcdab_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\|\s*type\s*=\s*dab\s*(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
		var afctemplate_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\|\s*type\s*=\s*template\s*(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
		if ((afcdab_re.test(pagetext)) || (disambig_re.test(pagetext))) {
			afcHelper_assessment.push(
				{
				label: 'अस्पष्ट-वर्ग',
				value: 'अस्पष्ट',
				selected: true
				});
		}else{
			afcHelper_assessment.push(
				{
				label: 'अस्पष्ट-वर्ग',
				value: 'अस्पष्ट'
				});
		}
		if ((afctemplate_re.test(pagetext)) || (typetemplate_re.test(pagetext))) {
			afcHelper_assessment.push(
				{
				label: 'ढाँचा-वर्ग',
				value: 'ढाँचा',
				selected: true
				});
		}else{
			afcHelper_assessment.push(
				{
				label: 'ढाँचा-वर्ग',
				value: 'ढाँचा'
				});
		}
		afcHelper_assessment.push(
			{
				label: 'अनुप्रेषण-वर्ग',
				value: 'अनुप्रेषण'
			}, {
				label: 'पोर्टल-वर्ग',
				value: 'पोर्टल'
			}, {
				label: 'परियोजना-वर्ग',
				value: 'परियोजना'
			}, {
				label: 'ढाँचा-वर्ग',
				value: 'ढाँचा'
			}, {
				label: 'उपलब्ध नभएको-वर्ग',
				value: 'na'
			});
		if ((afctemplate_re.test(pagetext)) || (disambig_re.test(pagetext)) || (afcdab_re.test(pagetext)) || (typetemplate_re.test(pagetext))){
			afcHelper_assessment.push(
			{
				label: 'कुनै पनि होईन',
				value: ''
			});
		}else{
			afcHelper_assessment.push(
			{
				label: 'कुनै पनि होईन',
				selected: true,
				value: ''
			});
		}
		var text = '<h3>स्वीकार गर्दै ' + afcHelper_PageName + '</h3>' +
		'<label for="afcHelper_movetarget">निवेदनलाई सार्नुहोस्: </label><input type="text" id="afcHelper_movetarget" value="' + afcHelper_escapeHtmlChars(afcHelper_submissionTitle) + '" />' +
		'<br /><label for="afcHelper_assessment">मूल्याङ्कन (वैकल्पिक): </label>';
		var assessmentSelect = afcHelper_generateSelect("afcHelper_assessment", afcHelper_assessment, null);
		text += assessmentSelect;

		// First load the list of wikiprojects and store it to afcHelper_wikiprojectindex
		$.ajax({
			url: "//ne.wikipedia.org/w/index.php?title=User:Pitambar_Bhattarai/afchwikiproject.js&action=raw&ctype=text/javascript",
			dataType: "json",
			success: function (data) { afcHelper_wikiprojectindex = data; },
			async: false
		});
		// Then generate a dynamic menu for them
		var wikiprojectSelect = afcHelper_generateChzn("afcHelper_wikiproject_selection",'Start typing to filter the list of WikiProjects...',afcHelper_wikiprojectindex);
		text += '<br /><label for="afcHelper_wikiproject_selection">Choose associated WikiProjects to be automatically be added to the talk page: </label><br>' + wikiprojectSelect;
		text += '<br /><label for="afcHelper_pagePrepend">Prepend wikicode to page (optional, e.g. maintenance boxes): </label><br><textarea class="afcHelper_expand" rows="1" cols="60" id="afcHelper_pagePrepend" spellcheck="true"></textarea>' +
		'<br /><label for="afcHelper_pageAppend">Append wikicode to page (optional, e.g. categories or stub templates): </label><br><textarea class="afcHelper_expand" rows="1" cols="60" id="afcHelper_pageAppend" spellcheck="true"></textarea>' +
		'<br /><label for="afcHelper_talkAppend">Append wikicode to talk page (optional, e.g. WikiProject templates): </label><br><textarea class="afcHelper_expand" rows="1" cols="60" id="afcHelper_talkAppend" spellcheck="true"></textarea>' +
		'<br /><label for="afcHelper_reqphoto">के लेखलाई फोटो/छवि चाहिन्छ? (वार्ता पृष्ठमा &#123;&#123;<a href="'+ mw.config.get('wgArticlePath').replace("$1", 'Template:Reqphoto') + '" title="Template:Reqphoto" target="_blank">reqphoto</a>&#125;&#125; थप्नेछ) </label><input type="checkbox" id="afcHelper_reqphoto"/>' +
		'<br /><label for="afcHelper_reqinfobox">के लेखलाई इन्फोबक्स चाहिन्छ? (वार्ता पृष्ठमा &#123;&#123;<a href="'+ mw.config.get('wgArticlePath').replace("$1", 'Template:Reqinfobox') + '" title="Template:Reqinfobox" target="_blank">reqinfobox</a>&#125;&#125; थप्नेछ) </label><input type="checkbox" id="afcHelper_reqinfobox"/>' +
		'<br /><label for="afcHelper_biography">के लेख जीवनी हो? </label><input type="checkbox" id="afcHelper_biography" onchange=afcHelper_trigger(\'afcHelper_biography_blp\') />' +
		'<div id="afcHelper_biography_blp" style="display:none"><label for="afcHelper_dateofbirth">महिना र जन्म दिन (यदि ज्ञात भएमा/दिईएमा, उदाहरणका लागि <i>नोभेम्बर २</i>): </label><input type="text" id="afcHelper_dateofbirth" spellcheck="true"/>' +
		'<br /><label for="afcHelper_yearofbirth">जन्म वर्ष (यदि ज्ञात भएमा/दिईएमा, उदाहरणका लागि <i>१९०१</i>): </label><input type="text" id="afcHelper_yearofbirth" />' +
		'<br /><label for="afcHelper_listas">थर, नाम (यदि ज्ञात भएमा/दिईएमा <a href="' + mw.config.get('wgArticlePath').replace("$1", 'विकिपिडिया:जीमाजीसूची') + '" title="विकिपिडिया:जीमाजीसूची" target="_blank">जीमाजीसूची</a> &ndash; उदाहरणका लागि <i>म्याग्लानेस, फर्नान्डो</i>): </label><input type="text" id="afcHelper_listas" />' +
		'<br /><label for="afcHelper_shortdescription">व्यक्तिको बारेमा धेरै छोटो वर्णन (उदाहरणका लागि <i>समुद्र अन्वेषक</i> &ndash; <a href="' + mw.config.get('wgArticlePath').replace("$1", 'विकिपिडिया:व्यक्तिगत तथ्याङ्क#छोटो_वर्णन') + '" title="विकिपिडिया:व्यक्तिगत तथ्याङ्क#छोटो_वर्णन" target="_blank">थप विवरण</a>): </label><input type="text" id="afcHelper_shortdescription" spellcheck="true"/>' +
		'<br /><label for="afcHelper_alternativesname">वैकल्पिक नामहरू (उदाहरणका लागि <i>म्याग्लानेस, फर्नान्डो डे</i>): </label><input type="text" id="afcHelper_alternativesname" />' +
		'<br /><label for="afcHelper_placeofbirth">जन्मस्थान (यदि ज्ञात भएमा/दिईएमा): </label><input type="text" id="afcHelper_placeofbirth" spellcheck="true"/>' +
		'<br /><label for="afcHelper_biography_status">के लेख एक जीवित व्यक्तिको बारेमा हो? </label>' + afcHelper_generateSelect('afcHelper_biography_status', [{
			label: 'जीवित',
			value: 'जिउँदो'
		}, {
			label: 'मृत',
			value: 'मरेको'
		}, {
			label: 'अज्ञात',
			selected: true,
			value: 'अज्ञात'
		}], "afcHelper_trigger(\'afcHelper_biography_status_box\')") + '<div id="afcHelper_biography_status_box" style="display:none"><label for="afcHelper_placeofdeath">मृत्युको स्थान (यदि ज्ञात भएमा/दिईएमा): </label><input type="text" id="afcHelper_placeofdeath" spellcheck="true"/>' +
		'<br /><label for="afcHelper_dateofdeath">मृत्युको महिना र दिन (यदि ज्ञात भएमा/दिईएमा, उदाहरणका लागि <i>सेप्टेम्बर ३</i>): </label><input type="text" id="afcHelper_dateofdeath" spellcheck="true"/>' +
		'<br /><label for="afcHelper_yearofdeath">मृत्युको वर्ष (यदि ज्ञात भएमा/दिईएमा): </label><input type="text" id="afcHelper_yearofdeath" />' +
		'</div></div><div id="afcHelper_extra_inline"></div>' +
		'<button class="afcHelper_button" type="button" id="afcHelper_accept_button" onclick="afcHelper_act(\'accept\')">स्वीकार्नुहोस् र मुख्यस्थानमा प्रकाशित गर्नुहोस्</button>';
		$("#afcHelper_extra").html(text);
		// Set up chosen wikiproject menu
		$("#afcHelper_wikiproject_selection").chosen({no_results_text: "ओहो, तपाईँको इनपुटसँग मिल्दो कुनै विकिपरियोजनाहरू फेला पार्न सकेन!"}); 
		// Expand textareas on click so they don't take up space, and then...
		$('textarea.afcHelper_expand').focus(function () {
			$(this).animate({ height: "4em" }, 500);
		});
		// ...shrink them back on blur if they have no content
		$('textarea.afcHelper_expand').blur(function () {
			if (!this.value) $(this).animate({ height: "1em" }, 500);
		});
	} else if (type === 'decline') {
		var text = '<h3>अस्वीकार गर्दै ' + afcHelper_PageName + '</h3>' + '<label for="afcHelper_reason">कारण ' + type + ': </label>';
		var reasonSelect = afcHelper_generateSelect("afcHelper_reason", afcHelper_reasonhash, "afcHelper_onChange(this)");
		text += reasonSelect;
		text += '<div id="afcHelper_extra_inline"></div>'; 
		text += '<label for="afcHelper_comments">थप टिप्पणीहरू (वैकल्पिक, हस्ताक्षर स्वचालित थपिन्छ): </label><textarea rows="3" cols="60" id="afcHelper_comments" spellcheck="true"></textarea>' +
		'<label for="afcHelper_blank">निवेदन खाली गर्नुहोस् (सामग्री बदल्नुहोस् {{<a href="' + mw.config.get('wgArticlePath').replace("$1", 'Template:Afc_cleared') + '" title="Template:Afc cleared" target="_blank">afc cleared</a>}}):</label><input type="checkbox" id="afcHelper_blank" onchange=afcHelper_trigger(\'afcHelper_afcccleared\') /><br/>' +
		'<div id="afcHelper_extra_afccleared" style="display:none"><label for="afcHelper_afccleared">Trigger the \'csd\' parameter and nominate the submission for speedy deletion?</label> <input type="checkbox" id="afcHelper_blank_csd"/><br/></div>' +
		'<label for="afcHelper_notify">लेखकलाई सूचित गर्नुहोस्:</label><input type="checkbox" onchange=afcHelper_trigger(\'afcHelper_notify_Teahouse\') id="afcHelper_notify" checked="checked" /><br/>' +
		'<div id="afcHelper_notify_Teahouse"><label for="afcHelper_notify_Teahouse">यसका बारे लेखकलाई सूचित गर्नुहोस् <a href="' + mw.config.get('wgArticlePath').replace("$1", 'विकिपिडिया:चियाघर') + '" title="विकिपिडिया:चियाघर" target="_blank">विकिपिडिया:चियाघर</a>:</label><input type="checkbox" id="afcHelper_Teahouse" /><br/></div><button type="button" class="afcHelper_button decline" id="afcHelper_prompt_button" onclick="afcHelper_act(\'decline\')">अस्वीकार गर्नुहोस्</button>';
		$("#afcHelper_extra").html(text);
	} else if (type === 'submit') {
		// !todo have "first" be pre-selected if submission template includes "t", else have "last" pre-selected
		var text = '<h3>एक निवेदन ढाँचा राख्नुहोस् ' + afcHelper_PageName + '</h3>';
		text += '<input type="radio" name="afcHelper_submit" id="afcHelper_submit1" value="first" /> <label for="afcHelper_submit1">मूल निवेदक सहित पेश गर्नुहोस्</label><br>' +
		'<input type="radio" name="afcHelper_submit" id="afcHelper_submit2" value="last" /> <label for="afcHelper_submit2">अन्तिम नन-बोट सम्पादक सहित पेश गर्नुहोस्</label><br>' +
		'<input type="radio" name="afcHelper_submit" id="afcHelper_submit3" value="creator" checked /> <label for="afcHelper_submit3">पृष्ठ निर्माता नै निवेदकको रूपमा पेश गर्नुहोस्</label><br>' +
		'<input type="radio" name="afcHelper_submit" id="afcHelper_submit4" value="self" checked /> <label for="afcHelper_submit3">आफू नै निवेदनकर्ताको रूपमा पेश गर्नुहोस्</label><br>' +
		'<input type="radio" name="afcHelper_submit" id="afcHelper_submit5" value="custom" /> <label for="afcHelper_submit4">अनुकूल पेशकर्तासँग पेश गर्नुहोस्:</label> <input type="text" id="afcHelper_custom_submitter" /><br>' +
		'<button class="afcHelper_button" type="button" id="afcHelper_submit_button" onclick="afcHelper_act(\'submit\')">निवेदन पेश ढाँचा राख्नुहोस्</button>';
		$("#afcHelper_extra").html(text);
	} else if (type === 'draft') {
		var text = '<h3>मस्यौदा निवेदन ढाँचा यसमा राख्नुहोस् ' + afcHelper_PageName + '</h3>';
		text += '<input type="radio" name="afcHelper_draft" id="afcHelper_draft1" value="self" checked /> <label for="afcHelper_submit1">आफूलाई प्रस्तुतकर्ताको रूपमा ट्याग गर्नुहोस्</label><br>' +
		'<input type="radio" name="afcHelper_draft" id="afcHelper_draft2" value="last" /> <label for="afcHelper_submit2">अन्तिम नन-बोट सम्पादकको रूपमा ट्याग गर्नुहोस्</label><br>' +
		'<input type="radio" name="afcHelper_draft" id="afcHelper_draft3" value="creator" checked /> <label for="afcHelper_submit3">पृष्ठ निर्माता नै निवेदकको रूपमा ट्याग गर्नुहोस्</label><br>' +
		'<input type="radio" name="afcHelper_draft" id="afcHelper_draft4" value="custom" /> <label for="afcHelper_submit4">अनुकूल पेशकर्तासँग ट्याग गर्नुहोस्:</label> <input type="text" id="afcHelper_draft_submitter" /><br>' +
		'<button class="afcHelper_button" type="button" id="afcHelper_draft_button" onclick="afcHelper_act(\'draft\')">ढाँचा {{AFC draft}} राख्नुहोस्</button>';
		$("#afcHelper_extra").html(text);
	} else if (type === 'mark') {
		var text = '<h3>निवेदन समीक्षा ' + afcHelper_PageName + ' चिह्नित गर्दै</h3>' +
		'<label for="afcHelper_comments">थप टिप्पणी (हस्ताक्षर स्वचालित थपिन्छ): </label><textarea rows="3" cols="60" id="afcHelper_comments" spellcheck="true"></textarea><br/><button type="button" class="afcHelper_button mark" id="afcHelper_prompt_button" onclick="afcHelper_act(\'mark\')">Place under review</button>';
		$("#afcHelper_extra").html(text);
	} else if (type === 'comment') {
		var text = '<h3>टिप्पणी गर्दै ' + afcHelper_PageName + ' </h3>' +
		'<label for="afcHelper_comments">टिप्पणी (हस्ताक्षर स्वचालित थपिन्छ): </label><textarea rows="3" cols="60" id="afcHelper_comments" spellcheck="true"></textarea><br/><button type="button" class="afcHelper_button comment" id="afcHelper_prompt_button" onclick="afcHelper_act(\'comment\')">टिप्पणी थप्नुहोस्</button>';
		$("#afcHelper_extra").html(text);
	} else if (type === 'postpone_g13') {
		var text = '<h3>शीघ्र मेटाउन स्थगित गर्दा अतिरिक्त टिप्पणी</h3>' +
		'<label for="afcHelper_comments">टिप्पणी (हस्ताक्षर स्वचालित थपिन्छ): </label><textarea rows="3" cols="60" id="afcHelper_comments" spellcheck="true"></textarea><br/><button type="button" class="afcHelper_button" id="afcHelper_prompt_button" onclick="afcHelper_act(\'postpone_g13\')">सा१३ शीघ्र हटाउन स्थगित</button>';
		$("#afcHelper_extra").html(text);
	}
}

function afcHelper_act(action) {
	if (action === 'draft') {
		var typeofsubmit = $("input[name=afcHelper_draft]:checked").val();
		var customuser = $("#afcHelper_draft_submitter").val();
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');
		if (typeofsubmit == "last") {
			user = afcHelper_last_nonbot(afcHelper_PageName)['user'];
			var submit = "{{subst:AFC draft|" + user + "}}\n";
		} else if (typeofsubmit == 'self') {
			var submit = "{{subst:AFC draft}}\n";
		} else if (typeofsubmit == 'creator') {
			var submit = "{{subst:AFC draft|"+afcHelper_page_creator(afcHelper_PageName)+"}}\n";
		} else if (typeofsubmit == 'custom' && customuser != null && customuser != "") {
			var submit = "{{subst:AFC draft|" + customuser + "}}\n";
		} else {
			alert("कुनै मान्य निवेदक हालिएको छैन, रद्द गर्दै...");
			return;
		}
		newtext = submit + pagetext;
		newtext = afcHelper_cleanup(newtext);
		afcHelper_editPage(afcHelper_PageName, newtext, "मस्यौदा [[विकिपिडिया:लेख सृजना]] ट्याग गर्दै", false);
	} else if (action === 'postpone_g13') {
		var comment = $("#afcHelper_comments").val();
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');
		var containComment = 0;
		if (comment !== '') {
			var newComment = "\{\{afc comment|1=" + comment + " \~\~\~\~\}\}";
			var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r|d](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
			if (!afc_re.test(pagetext)) {
				alert("लेख सृजना निवेदन ढाँछा पत्ता लगाउन असमर्थ, रद्द गर्दै...");
				return;
			}
			var afctemplate = afc_re.exec(pagetext)[0];
			var endindex = pagetext.indexOf(afctemplate) + afctemplate.length;
			pagetext = pagetext.substring(0, endindex) + '\n' + newComment + '\n----\n' + pagetext.substring(endindex);
		}
		postpone_re = /\{\{AfC postpone G13\s*(?:\|\s*(\d*)\s*)?\}\}/ig;
		var match = postpone_re.exec(pagetext);
		if (match) {
			if (match[1] != undefined) {
				addition = "{{AfC postpone G13|"+(parseInt(match[1])+1)+"}}";
			} else {
				addition = "{{AfC postpone G13|2}}";
			}
			newtext = pagetext.replace(match[0],addition);
		} else {
			newtext = pagetext+"\n{{AfC postpone G13|1}}";
		}
		afcHelper_editPage(afcHelper_PageName, newtext, "[[वि:सा१३|सा१३]] शीघ्र मेटाउन स्थगित गर्दै", false);
	} else if (action === 'g13') {
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');
		timestamp = afcHelper_cache.afcHelper_lastedited;
		newtext = "{{Db-g13|ts=" + timestamp + "}}\n" + pagetext;

		afcHelper_editPage(afcHelper_PageName, newtext, "त्यागिएका [[विकिपिडिया:लेख सृजना]] मस्यौदा [[वि:सा१३|सा१३]] अन्तर्गत शीघ्र मेटाउन चिनो लगाउँदै", false);
		// notify users
		var users = new Array();
		var templates = pagetext.match(/\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/gi);
		var author_re = /\|\s*u=\s*[^\|]*\|/i;
		if (templates) {
			for (var i = 0; i < templates.length; i++) {
				if (author_re.test(templates[i])) {
					user = author_re.exec(templates[i])[0];
					username = user.split(/=/)[1];
					username = username.replace(/\|/g, '');
					users.push(username);
				}
			}
		}
		users.push(afcHelper_page_creator(afcHelper_PageName)); // page creator 
		var uniqueUsers = [];
		$.each(users, function(i, l) {
			if ($.inArray(l, uniqueUsers) === -1) uniqueUsers.push(l);
		});
		for (var i = 0; i < uniqueUsers.length; i++) {
			username = uniqueUsers[i]
			usertalkpage = "User talk:" + username;
			var usertext = afcHelper_getPageText(usertalkpage, true, true);
			usertext += "\n{{subst:Db-afc-notice|" + afcHelper_PageName + "}} ~~~~";
			afcHelper_editPage(usertalkpage, usertext, 'सूचना: [[वि:सा१३|सा१३]] शीघ्र मेटाउने नामाङ्कन [[' + afcHelper_PageName + ']]', false);
		}
		afcHelper_logcsd(afcHelper_PageName,"[[वि:सा१३]] ({{tl|db-afc}})",uniqueUsers);
	} else if (action === 'submit') {
		var typeofsubmit = $("input[name=afcHelper_submit]:checked").val();
		var customuser = $("#afcHelper_custom_submitter").val();
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');

		// First we handle "last", since this uses a different method than the others
		if (typeofsubmit == 'last') {
			// Get the last non-bot editor to the page
			var submitinfo = afcHelper_last_nonbot(afcHelper_PageName);
			if (submitinfo) {
				dt = new Date(submitinfo['timestamp']);
				// output the date in the correct format
				date = dt.getUTCFullYear() + ('0' + (dt.getUTCMonth() + 1)).slice(-2) + ('0' + dt.getUTCDate()).slice(-2) + ('0' + dt.getUTCHours()).slice(-2) + ('0' + dt.getUTCMinutes()).slice(-2) + ('0' + dt.getUTCSeconds()).slice(-2);
				var submit = "{{AFC submission|||ts=" + date + "|u=" + submitinfo['user'] + "|ns={{subst:NAMESPACENUMBER}}}}\n";
				newtext = submit + pagetext;
				newtext = afcHelper_cleanup(newtext);
				afcHelper_editPage(afcHelper_PageName, newtext, "निवेदन [[विकिपिडिया:लेख सृजना]] बुझाउँदै", false);
			} else {
				alert("नन-बोट सम्पादक फेला पार्न असक्षम; कृपया पृष्ठ ईतिहास जाँच गर्नुहोस्।");
			}
		} else {
			if (typeofsubmit == 'first') {
				var afc_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
				if (afc_re.test(pagetext)) {
					var afctemplate = afc_re.exec(pagetext)[0];
					var author_re = /\|\s*u=\s*[^\|]*\|/i;
					if (author_re.test(afctemplate)) {
						var user = author_re.exec(afctemplate)[0];
						username = user.split(/=/)[1];
						submitter = username.replace(/\|/g, '');
					} else {
						alert("मूल पेशकर्ता फेला पार्न असफल, रद्द गर्दै...");
						return;
					}
				} else {
					alert("एक लेख सृजना निवेदन ढाँचा फेला पार्न सकेन, रद्द गर्दै...");
					return;
				}
				var submit = "{{subst:submit|user=" + submitter + "}}\n";
			} else if (typeofsubmit == 'self') {
				var submit = "{{subst:submit}}\n";
			} else if (typeofsubmit == 'custom' && customuser != null && customuser != "") {
				var submit = "{{subst:submit|user=" + customuser + "}}\n";
			} else if (typeofsubmit == 'creator') {
				var submit = "{{subst:submit|user="+afcHelper_page_creator(afcHelper_PageName)+"}}\n";
			} else {
				alert("कुनै मान्य सबमिटर निर्दिष्ट गरिएको थिएन, रद्द गर्दै...");
				return;
			}
			newtext = submit + pagetext;
			newtext = afcHelper_cleanup(newtext);
			afcHelper_editPage(afcHelper_PageName, newtext, "निवेदन [[विकिपिडिया:लेख सृजना]] बुझाउँदै", false);
		}
	} else if (action === 'accept') {
		var newtitle = $("#afcHelper_movetarget").val();
		var assessment = $("#afcHelper_assessment").val();
		var pagePrepend = $("#afcHelper_pagePrepend").val();
		var pageAppend = $("#afcHelper_pageAppend").val();
		var talkAppend = $("#afcHelper_talkAppend").val();
		var biography = $("#afcHelper_biography").prop("checked");
		var reqinfobox = $("#afcHelper_reqinfobox").prop("checked");
		var reqphoto = $("#afcHelper_reqphoto").prop("checked");

		var selectedwikiprojects = new Array();
		$("#afcHelper_wikiproject_selection option:selected").each(function() {
			selectedwikiprojects.push($(this).val());
		});

		if (biography) {
			var living = $("#afcHelper_biography_status").val(); //dropdown menu
			var yearofbirth = $("#afcHelper_yearofbirth").val();
			var dateofbirth = $("#afcHelper_dateofbirth").val();
			var listas = $("#afcHelper_listas").val();
			var shortdescription = $("#afcHelper_shortdescription").val();
			var alternativesname = $("#afcHelper_alternativesname").val();
			var placeofbirth = $("#afcHelper_placeofbirth").val();
			var placeofdeath = '';
			var yearofdeath = '';
			var dateofdeath = '';
			if (living === 'dead') {
				yearofdeath = $("#afcHelper_yearofdeath").val()
				dateofdeath = $("#afcHelper_dateofdeath").val();
				placeofdeath = $("#afcHelper_placeofdeath").val();
			}
		}
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');
		var callback = function() {
			var username = '';
			// clean up page
			var afc_re = /\{\{\s*afc submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
			if (afc_re.test(pagetext)) {
				var afctemplate = afc_re.exec(pagetext)[0];
				var author_re = /\|\s*u=\s*[^\|]*\|/i;
				if (author_re.test(afctemplate)) {
					var user = author_re.exec(afctemplate)[0];
					username = user.split(/=/)[1];
					username = username.replace(/\|/g, '');
					usertalkpage = "User talk:" + username;
					var usertext = afcHelper_getPageText(usertalkpage, true, true);
					usertext += "\n== तपाईँको लेख सृजना निवेदन \[\[" + mw.config.get('wgPageName') + "|" + newtitle + "\]\] स्वीकार गरियो ==";
					usertext += "\n\{\{subst:afc talk|1=" + newtitle + "|class=" + assessment + "|sig=yes\}\}";
					afcHelper_editPage(usertalkpage, usertext, 'तपाईँको निवेदन \[\[वि:लेसृ|लेख सृजना\]\]', false);
				}
			}
			var recenttext = afcHelper_getPageText("विकिपिडिया:लेख सृजना/भर्खरको", true, false);
			var newentry = "\{\{afc contrib|" + assessment + "|" + newtitle + "|" + username + "\}\}\n";
			var lastentry = recenttext.toLowerCase().lastIndexOf("\{\{afc contrib");
			var firstentry = recenttext.toLowerCase().indexOf("\{\{afc contrib");
			recenttext = recenttext.substring(0, lastentry);
			recenttext = recenttext.substring(0, firstentry) + newentry + recenttext.substring(firstentry);
			afcHelper_editPage("विकिपिडिया:लेख सृजना/भर्खरको", recenttext, 'भर्खरको लेख सृजनाहरू अपडेट गर्दै', false);

			var talktext = "";
			if (biography) {
				talktext += "\{\{विकिपरियोजना जीवनी|living=";
				if (जीवित === 'जिउँदो') talktext += "yes";
				else if (जीवित === 'मृत') talktext += "no";
				talktext += "|class=" + assessment + "|listas=" + listas;
				if (reqphoto) talktext += "|needs-photo=yes";
				if (reqinfobox) talktext += "|needs-infobox=yes";
				talktext += "\}\}\n";
			}

			talktext += "\{\{subst:WPAFC/article|class=" + assessment + "\}\}\n";

			// For each selected WikiProject, append it to the talk page
			for (var i = 0; i < selectedwikiprojects.length; i++) {
				var project = selectedwikiprojects[i];
				talktext += "{{"+project+"|class="+assessment+"}}\n";
			};

			if (talkAppend) talktext += talkAppend + "\n"; 
			if (assessment === 'disambig') {
				talktext += '\{\{विकिपरियोजना अस्पष्टता\}\}\n';
			}
			if (reqinfobox && !biography) talktext += "\{\{Infobox requested\}\}\n";
			if (reqphoto && !biography) talktext += "\{\{Image requested\}\}\n";

			var newtalktitle = newtitle.replace(/(Template|Category|Wikipedia|Portal):/,"$1 talk:");
			if (newtalktitle == newtitle) newtalktitle = 'Talk:' + newtitle;

			afcHelper_editPage(newtalktitle, talktext, '[[विकिपिडिया:लेख सृजना]] परियोजना ब्यानर राख्दै', false);

			pagetext = pagetext.replace(/\{\{\s*afc\s*submission\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/gim, "");
			pagetext = pagetext.replace(/\{\{\s*afc\s*comment\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/gim, "");

			// first clean up the page
			pagetext = afcHelper_cleanup(pagetext);

			// Uncomment cats (after the cleanup commented them)
			pagetext = pagetext.replace(/\[\[:Category/gi, "\[\[Category");
			pagetext = pagetext.replace(/\{\{:?DEFAULTSORT:/gi, "\{\{DEFAULTSORT:"); //fixes upper and lowercase problems!
			// Remove Doncram's category on accept per issue #39
			pagetext = pagetext.replace(/\[\[:?श्रेणी:पिद्वारा पेश निवेदन समीक्षाको लागि तयार\]\]/gi, "");

			// [[Template:L]]
			var templatel = '\n';
			if (biography) {
				templatel = '\n\{\{Persondata\n| NAME              =' + listas + '\n| ALTERNATIVE NAMES = ' + alternativesname + '\n| SHORT DESCRIPTION = ' + shortdescription + '\n| DATE OF BIRTH     = ' + dateofbirth + ', ' + yearofbirth + '\n| PLACE OF BIRTH    = ' + placeofbirth;
				if (living === 'dead') {
					templatel += '\n| DATE OF DEATH     = ' + dateofdeath + ', ' + yearofdeath + '\n| PLACE OF DEATH    = ' + placeofdeath + '\n\}\}';
				} else {
					templatel += '\n| DATE OF DEATH     = ' + '\n| PLACE OF DEATH    = \n\}\}';
				}
				templatel += '\n\{\{subst:L|';
				if (yearofbirth === '') templatel += 'MISSING|';
				else templatel += yearofbirth + '|';
				if (living === 'dead') {
					if (yearofdeath === '') templatel += 'MISSING|';
					else templatel += yearofdeath + '|';
				} else {
					templatel += 'LIVING|';
				}
				templatel += '|' + listas + '\}\}\n';
			}
			pagetext = pagePrepend + '\n' + pagetext + templatel + pageAppend;
			// test if the submission contains any category and if not, add {{uncategorized}}
			cat_re = /\[\[Category/gi;
			if (!cat_re.test(pagetext) && (assessment !== 'disambig') && (assessment !== 'redirect') && (assessment !== 'project') && (assessment !== 'portal') && (assessment !== 'template')) {
				if (biography) {
					pagetext += '\{\{subst:dated|श्रेणी थप्नुहोस्\}\}';
				} else {
					pagetext += '\{\{subst:dated|श्रेणीविहीन\}\}';
				}
			}
			var stub_re = /stub\}\}/gi;
			if ((assessment === 'stub') && (!stub_re.test(pagetext))) {
				if (biography) {
					pagetext += '\n\{\{bio-stub\}\}';
				} else {
					pagetext += '\n\{\{stub\}\}';
				}
			}
			// disambig check
			if ((assessment === 'disambig') && (!disambig_re.test(pagetext))) {
				pagetext += '\n\{\{disambig\}\}';
			}

			// Template uncommenting -- covert {{tl}}'d templates to the real thing
			pagetext = pagetext.replace(/\{\{(tl|tlx|tlg)\|(.*?)\}\}/ig, "\{\{$2\}\}");

			// automatic tagging of linkrot
			// TODO: Use non-regex for html
			var linkrotre = /((<\s*ref\s*(name\s*=|group\s*=)*\s*.*[\/]{1}>)|(<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*>))+(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])+(\<\/ref\>)+/gi;
			if(linkrotre.test(pagetext)){	
				pagetext = "{{subst:dated|Cleanup-bare URLs}}" + pagetext;
			}
			//check if page is orphaned (mainspace) and tag it!
			if ((assessment !== 'disambig') && (assessment !== 'redirect') && (assessment !== 'project') && (assessment !== 'portal') && (assessment !== 'template')) {
				afcHelper_displaymessagehelper('status','orphan');
				var request = {
					'action': 'query',
					'list': 'backlinks',
					'format': 'json',
					'blnamespace': 0,
					'bllimit': 10,
					'bltitle' : newtitle
				};
				var response = JSON.parse(
					$.ajax({
						url: mw.util.wikiScript('api'),
						data: request,
						async: false
					})
					.responseText
				);
				var isorphaned = response['query']['backlinks'].length;
				if (isorphaned) {
					$("#afcHelper_orphan").html("अनाथ चेक: सबै ठिक छ। कुनै चिनो आवश्यक छैन।");
				} else {
					pagetext = '\{\{subst:dated|Orphan\}\}' + pagetext;
					$("#afcHelper_orphan").html("पृष्ठ अनाथ छ, चिनो थप्दै।");
				}
			}
			afcHelper_editPage(newtitle, pagetext, "[[विकिपिडिया:लेख सृजना]] सफाइ गर्दै", false);
		};
		afcHelper_movePage(afcHelper_PageName, newtitle, 'यो \[\[वि:लेसृ|लेख सृजना\]\] मार्फत सृजित (\[\[विकिपिडिया:विकिपरियोजना लेख सृजना|तपाईँ पनि मद्दत गर्न सक्नुहुन्छ!\]\])', callback, true);
	} else if (action === 'decline') {
		var code = $("#afcHelper_reason").val();
		for (i = 0; i < (afcHelper_reasonhash.length + 1); i++) {
			if ((typeof(afcHelper_reasonhash[i]) !== 'undefined') && (afcHelper_reasonhash[i].value === code)) var reasontext = afcHelper_reasonhash[i].reason;
		}
		var customreason = $("#afcHelper_comments").val();
		var append = false;
		var keep = false;
		var blank = $("#afcHelper_blank").prop("checked");
		var blank_csd = $("#afcHelper_blank_csd").prop("checked");
		var notify = $("#afcHelper_notify").prop("checked");
		var teahouse = $("#afcHelper_Teahouse").prop("checked");
		var extra = '';
		if (code === 'cv' || code === 'dup' || code === 'mergeto' || code === 'exists' || code === 'lang' || code === 'plot') {
			extra = $("#afcHelper_extra_inlinebox").val();
		}
		if (extra === null) {
			return;
		}

		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');
		// Find the first pending submission or marked as review on the page.
		var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;

		if (!afc_re.test(pagetext)) {
			alert("लेख सृजना निवेदन ढाँचा पत्ता लगाउन असमर्थ, रद्द गर्दै...");
			return;
		}
		//TODO: removing after cleanup works
		var afctemplate = afc_re.exec(pagetext)[0];
		//moving the first hit to the top
		pagetext = pagetext.replace(afctemplate, '');
		pagetext = afctemplate + pagetext;
		//todo END: removing after cleanup works
		var notifytemplate = "afc decline";
		if (code === 'reason' && customreason === '') {
			alert("You must enter a reason!");
			return;
		}

		var startindex = pagetext.indexOf(afctemplate);
		var endindex = startindex + afctemplate.length;
		//data is always between the first pipe and the one before the timestamp.
		var firstpipe = afctemplate.indexOf('|');
		var endpipe = afctemplate.indexOf('|ts');
		var newtemplate = afctemplate.substring(0, firstpipe);
		var summary = '';
		var newcomment = '';
		// overwrite any reason that was there.
		newtemplate += '|d|' + (code || 'reason');
		if (code === 'reason' || code === null) {
			newtemplate += '|3=' + customreason;
		} else if (extra !== '') {
			newtemplate += '|3=' + extra;
		}
		newtemplate += '|declinets=\{\{subst:CURRENTTIMESTAMP\}\}|decliner=\{\{subst:REVISIONUSER\}\}' + afctemplate.substring(endpipe);
		//correcting namespace number after page moves mostly from userspace
		newtemplate = newtemplate.replace(/\s*\|\s*ns\s*=\s*[0-9]{0,2}\s*/gi, '\|ns=\{\{subst:NAMESPACENUMBER\}\}');
		if (code !== null && code !== 'reason' && customreason !== '') {
			newcomment = "*\{\{afc comment|1=" + customreason + " \~\~\~\~\}\}";
		}

		summary = "Declining submission";
		if (code === 'reason' || code === null) {
			summarycustom = customreason.match(/[^\s]+/g).slice(0,5).join(" "); // Get the first five words of the custom decline rationale
			if (summarycustom != customreason) summarycustom += "..."; // Add an ellipsis if the rationale if >5 words
			summary += ': ' + summarycustom;
		} else {
			summary += ': ' + reasontext;
		}

		// Stores the author of the submission to afcHelper_authorusername
		var author_re = /\|\s*u\s*=\s*(.*?)\|/i;
		if (author_re.test(afctemplate)) {
			var username = author_re.exec(afctemplate)[1];
			if (username !== 'उदाहरण') {
				afcHelper_authorusername = username;
			} else {
				afcHelper_authorusername = afcHelper_page_creator(afcHelper_PageName);
			}
		} else {
			afcHelper_authorusername = afcHelper_page_creator(afcHelper_PageName);
		}


		if (notify) {
			usertalkpage = "User talk:" + afcHelper_authorusername;
			var usertext = afcHelper_getPageText(usertalkpage, true, true);
			var reason = 'तपाईँको \[\[विकिपिडिया:लेख सृजना|लेख सृजना\]\] निवेदनन';
			var SubmissionName = afcHelper_PageName.replace(/(Wikipedia( talk)*:लेख सृजना\/)+/i, '');
			usertext += "\n== तपाईँको \[\[विकिपिडिया:लेख सृजना|लेख सृजना\]\] निवेदनन: \[\[" + afcHelper_PageName + "|" + SubmissionName + "\]\] ({{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}) ==";
			var newnewnewtitle = afcHelper_submissionTitle.replace(" ", "{{subst:Sp}}");
			usertext += "\n\{\{subst:" + notifytemplate + "|1=" + newnewnewtitle;
			if (code === 'cv') usertext += "|cv=yes";
			usertext += "|sig=yes\}\}";

			if (teahouse) {
				document.getElementById('afcHelper_status').innerHTML += '<div id="afcHelper_get_teahouse"></div>';
				$("#afcHelper_get_teahouse").html('<li id="afcHelper_get_teahouse">अवस्थित चियाघर आमन्त्रणको लागि जाँच गर्दै <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI('User_talk:' + username)) + '" title="User talk:' + username + '">User talk:' + username + '</a></li>');
				var request = {
					'action': 'query',
					'prop': 'categories',
					'format': 'json',
					'indexpageids': true,
					'redirects': true,
					'titles' : usertalkpage
				};
				var response = JSON.parse(
					$.ajax({
						url: mw.util.wikiScript('api'),
						data: request,
						async: false
					})
					.responseText
				);
				var pageid = response['query']['pageids'][0];
				var foundTH = 0;
				if (pageid !== "-1") {
					if (response['query']['redirects']) { /* If there is no redirect, this stops here from getting an error */
						var oldusername = response['query']['redirects'][0]['from'];
						var newusername = response['query']['redirects'][0]['to'];
						if ((typeof(oldusername) !== 'undefined') && (typeof(newusername) !== 'undefined') && (oldusername != newusername)) {
							document.getElementById('afcHelper_get_teahouse').innerHTML += '<li id="afcHelper_get_teahouse2">User talk page is redirect to <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI('User_talk:' + newusername)) + '" title="User talk:' + newusername + '">User talk:' + newusername + '</a> - checking there for TeaHouse invitations.</li>';
							params = "action=query&prop=categories&format=json&indexpageids=1&titles=User_talk:" + encodeURIComponent(newusername);
							req.send(params);
							response = eval('(' + req.responseText + ')');
							pageid = response['query']['pageids'][0];
						}
					}
					if (pageid !== "-1") {
						var pagecats = new Array();
						pagecats = response['query']['pages'][pageid]['categories'];
					}
					if ((typeof pagecats !== 'undefined') && (pageid !== "-1")) {
						for (var i = 0; i < pagecats.length; i++) {
							if ((pagecats[i].title === ("श्रेणी:चिया घरमा आमन्त्रण प्राप्त गर्ने विकिपिडियनहरू")) || (pagecats[i].title === ("श्रेणी:लेख सृजना मार्फत चिया घरमा आमन्त्रण प्राप्त गर्ने विकिपिडियनहरू"))) {
								foundTH = 1;
								break;
							}
						}
					}
				}
				if (foundTH === 0) {
					$("#afcHelper_get_teahouse").html('<li id="afcHelper_get_teahouse">Sent <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI('User talk:' + username)) + '" title="User talk:' + username + '">User talk:' + username + '</a> an invitation.</li>');
					usertext += "\n\n\n\{\{subst:विकिपिडिया:चियाघर/लेसृ_निमन्त्रणा\}\}";
					reason += '; निमन्त्रणा थप्दै \[\[विकिपिडिया:चियाघर|चियाघर\]\]!';
				} else {
					$("#afcHelper_get_teahouse").html('<a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI('User talk:' + username)) + '" title="User talk:' + username + '">' + username + '</a> पहिले नै एक आमन्त्रित छ।');
				}
			} //end TH stuff
			afcHelper_editPage(usertalkpage, usertext, reason, false);
		}
		if (!blank) {
			var containComment = 0;
			containComment = pagetext.indexOf('----');
			if (newcomment !== '') {
				if (containComment !== 0) {
					pagetext = pagetext.substring(0, startindex) + newtemplate + '\n' + newcomment + '\n----\n' + pagetext.substring(endindex);
				} else {
					pagetext = pagetext.substring(0, startindex) + newtemplate + pagetext.substring(endindex);
					var idx = pagetext.indexOf('----');
					pagetext = pagetext.substring(0, idx) + '\n' + newcomment + '\n' + pagetext.substring(idx);
				}
			} else pagetext = pagetext.substring(0, startindex) + newtemplate + pagetext.substring(endindex);
		} else {
			if (blank_csd) {
				if (code === 'cv') {
					// If article is a copyvio add db-g12 to the top
					if (extra != "http://" || extra != "") {
						pagetext = "\{\{Db-g12|url=" + extra + "\}\}\n" + newtemplate + '\n' + newcomment + '\n\{\{afc cleared\}\}';
					} else {
						pagetext = "\{\{Db-g12\}\}\n" + newtemplate + '\n' + newcomment + '\n\{\{afc cleared\}\}';
					}
					// And for good measure log the CSD nomination
					afcHelper_logcsd(afcHelper_PageName,"[[शीमै:सा१२]] ({{tl|db-copyvio}})",[afcHelper_authorusername]);
				} else {
					pagetext = newtemplate + '\n' + newcomment + '\n\{\{afc cleared|csd\}\}';
					afcHelper_logcsd(afcHelper_PageName,"{{tl|db-reason}} ([[वि:लेसृ|लेख सृजना]])",[afcHelper_authorusername]);
				}
			} else {
				// If we just need to blank the submission, *just blank it*
				pagetext = newtemplate + '\n' + newcomment + '\n\{\{afc cleared\}\}';
			}
		}

		//first remove the multiple pending templates, otherwise one isn't recognized
		pagetext = pagetext.replace(/\{\{\s*afc submission\s*\|\s*[||h|r](?:\{\{[^{}]*\}\}|[^}{])*\}\}/i, "");
		pagetext = afcHelper_cleanup(pagetext);
		afcHelper_editPage(afcHelper_PageName, pagetext, summary, false);
	} else if (action === 'comment') {
		var comment = $("#afcHelper_comments").val();
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');
		var containComment = 0;
		containComment = pagetext.indexOf('----');
		if (containComment === -1) containComment = 0;

		var newComment = "\{\{afc comment|1=" + comment + " \~\~\~\~\}\}";
		if (comment !== '') {
			if (!containComment) {
				var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r|d](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
				if (!afc_re.test(pagetext)) {
					alert("लेख सृजना निवेदन ढाँचा पत्ता लगाउन असमर्थ, रद्द गर्दै....");
					return;
				}
				var afctemplate = afc_re.exec(pagetext)[0];
				var endindex = pagetext.indexOf(afctemplate) + afctemplate.length;
				pagetext = pagetext.substring(0, endindex) + '\n' + newComment + '\n----\n' + pagetext.substring(endindex);
			} else {
				var idx = pagetext.indexOf('----');
				if (idx !== -1) pagetext = pagetext.substring(0, idx) + newComment + '\n' + pagetext.substring(idx);
				else {
					var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r|d](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
					if (!afc_re.test(pagetext)) {
						alert("Unable to locate AFC submission template, aborting...");
						return;
					}
					var afctemplate = afc_re.exec(pagetext)[0];
					var endindex = pagetext.indexOf(afctemplate) + afctemplate.length;
					pagetext = pagetext.substring(0, endindex) + '\n' + newComment + '\n----\n' + pagetext.substring(endindex);
				}
			}
			afcHelper_editPage(afcHelper_PageName, pagetext, "निवेदन [[विकिपिडिया:लेख सृजना]]मा टिप्पणी गर्दै", false);
		}
	} else if (action === 'mark') {
		var comment = $("#afcHelper_comments").val();
		if (comment == undefined) comment = window.overwrite_comment; // This handles the overwrite_redirect scenario
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');
		var containComment = (pagetext.indexOf('----') !== -1);
		var newComment = "\{\{afc comment|1=" + comment + " \~\~\~\~\}\}";
		if (comment !== '') {
			var afc_re = /\{\{\s*afc submission\s*\|\s*[\| ](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
			if (!containComment) {
				if (!afc_re.test(pagetext)) {
					alert("लेख सृजना निवेदन ढाँचा पत्ता लगाउन असमर्थ, रद्द गर्दै...");
					return;
				}
				var afctemplate = afc_re.exec(pagetext)[0];
				var endindex = pagetext.indexOf(afctemplate) + afctemplate.length;
				pagetext = pagetext.substring(0, endindex) + '\n' + newComment + '\n----\n' + pagetext.substring(endindex);
			} else {
				var idx = pagetext.indexOf('----');
				pagetext = pagetext.substring(0, idx) + newComment + '\n' + pagetext.substring(idx);
			}
		}
		var afc_re = /(\{\{\s*afc submission\s*\|)(\s*[\| ]\s*)((?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\})/i;
		if (!afc_re.test(pagetext)) {
			alert("लेख सृजना निवेदन ढाँचा पत्ता लगाउन असमर्थ, रद्द गर्दै...");
			return;
		}
		pagetext = pagetext.replace(afc_re, "$1r\|$3");
		afcHelper_editPage(afcHelper_PageName, pagetext, "निवेदन [[विकिपिडिया:लेख सृजना]]लाई समीक्षा गरिएको चिह्नित गर्दै", false);
	} else if (action === 'unmark') {
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		afcHelper_displaymessagehelper('done','standard');
		var afc_re = /\{\{\s*afc submission\s*\|\s*r\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/gi;
		if (!afc_re.test(pagetext)) {
			alert("लेख सृजना निवेदन ढाँचा पत्ता लगाउन असमर्थ वा पृष्ठ समीक्षा गरिएकोको रूपमा चिन्ह लगाइएको छैन, रद्द गर्दै...");
			return;
		}
		pagetext = pagetext.replace(/\{\{\s*afc submission\s*\|\s*r\s*\|\s*/gi, "{{AFC submission||");
		afcHelper_editPage(afcHelper_PageName, pagetext, "निवेदन [[विकिपिडिया:लेख सृजना]]लाई समीक्षा गरिएको अचिह्नित गर्दै", false);
	} else if (action === 'cleanup') {
		displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
		var text = afcHelper_getPageText(afcHelper_PageName, true, false);
		if (text === pagetext) {
			afcHelper_displaymessagehelper('done','cleanednochange');
		} else {
			afcHelper_editPage(afcHelper_PageName, pagetext, "निवेदन [[विकिपिडिया:लेख सृजना]] सफा गर्दै", false);
			afcHelper_displaymessagehelper('done','standard');
		}
	}

	// Display the "Done" text only after all ajax requests are completed
	$(document).ajaxStop(function () {
		$("#afcHelper_finished_main").css("display", "");
	});
}

function afcHelper_movePage(oldtitle, newtitle, summary, callback, overwrite_redirect) {
	var token = mw.user.tokens.get('csrfToken');
	$("#afcHelper_finished_wrapper").html('<span id="afcHelper_AJAX_finished_' + afcHelper_AJAXnumber + '" style="display:none">' + $("#afcHelper_finished_wrapper").html() + '</span>');
	var func_id = afcHelper_AJAXnumber;
	afcHelper_AJAXnumber++;
	document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_move' + escape(oldtitle) + '">सार्दै <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a> मा <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(newtitle)) + '" title="' + newtitle + '">' + newtitle + '</a></li>';
	var request = {
				'action': 'move',
				'from': oldtitle,
				'to': newtitle,
				'reason': summary + afcHelper_advert,
				'format': 'json',
				'token': token
			};
	var response = JSON.parse(
		$.ajax({
			type: "POST",
			url: mw.util.wikiScript('api'),
			data: request,
			async: false
		})
		.responseText
	);
	error = true;
	try {
		if (typeof(response['move']) !== "undefined") {
			document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = 'सारियो <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a>';
			error = false;
		} else {
			if (overwrite_redirect) {
				if (response['error']['code'] == "articleexists") {
					text = afcHelper_getPageText(newtitle);
					if (text.search(/#redirect\s*\[\[/gi) != -1) { // Should probably use &redirects= to check if it's a redirect, rather than this hack...but this seemed simpler and more concise, rather than yet another API call
						if ($.inArray('sysop', mw.config.get('wgUserGroups')) !== -1) {
							del = confirm("लक्ष्य शीर्षक, " + newtitle + ", एक अनुप्रेषण हो। के तपाईं स्वचालित रूपमा यसलाई {{db-move}} अन्तर्गत मेटाउन चाहनुहुन्छ र यसलाई स्वीकारेर निवेदनलाई सार्न चाहनुहुन्छ?");
							if (del) {
								document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = '<div id="afcHelper_delete' + escape(oldtitle)+'"></div>'; // to allow for messages from the editor
								deleted = afcHelper_deletePage(newtitle, "[[शीमे:सा६]]: स्वीकृत [[विकिपिडिया:लेख सृजना]] निवेदन सार्न अनुप्रेषित")
								if (deleted) {
									afcHelper_movePage(oldtitle, newtitle, summary, callback, overwrite_redirect); // Then just move the page again as if nothing happened
									return; // So we don't run callback() twice
								} else {
									document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = '<div style="color:red"><b>स्वत: मेटाउन असक्षम <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></div>';
								}
							} else {
								document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = '<div style="color:red"><b>सार्न असफल <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></div>। त्रुटि जानकारी: प्रयोगकर्ताले स्वचालित रूपमा अवरोध हटाउने अनुप्रेषण हटाउँदा रद्द भयो';
							}
						} else {
							del = confirm("लक्ष्य शीर्षक, "+newtitle+", एक अनुप्रेषण हो। के तपाईं स्वचालित रूपमा यसलाई {{db-move}} अन्तर्गत मेटाउन चाहनुहुन्छ र यसलाई स्वीकारेर निवेदनलाई सार्न चाहनुहुन्छ?");
							if (del) {
								rat = "{{db-move|1="+oldtitle+"|2=स्वीकृत [[वि:लेसृ|लेख निवेदन]] रोक्नको लागि अनुप्रेषित।}}\n";
								afcHelper_editPage(newtitle, rat+text, "{{[[Template:Db-move|db-move]]}} अन्तर्गत मेटाउनका लागि [[विकिपिडिया:लेख सृजना]] बुझाउने तरीकामा अनुप्रेषणलाई चिनो लगाउँदै");
								window.overwrite_comment = 'यो लेख सबमिशन अनुमोदन भएको छ, तर एक [[वि:अनुप्रेषण|अनुप्रेषण]]ले यसलाई लेख स्थानमा सारिनबाट रोकिरहेको छ। प्रशासकले अनुप्रेषण हटाउनुपर्नेछ र लेखलाई केहि दिन भित्र सार्नुपर्नेछ। तपाईँको धैर्यताको लागि धन्यवाद!';
								document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = '<div id="afcHelper_edit' + escape(oldtitle)+'"></div>'; // to allow for messages from the editor
								afcHelper_act('mark'); // We mark the submission as "under review"
								document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML += '<div><b>अनुप्रेषित पृष्ठलाई सफलतापूर्वक <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(newtitle)) + '" title="' + newtitle + '">' + newtitle + '</a> मेटाउनका लागि</b> {{db-move}} अन्तर्गत ट्याग गरियो। लेख प्रशासकद्वारा सारिनु पर्छ जसले अनुप्रेषण हटाउँछ।</div>';
							} else {
								document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = '<div style="color:red"><b>सार्न असफल <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></div>। त्रुटि जानकारी: प्रयोगकर्ताले मेटाउनका लागि लक्ष्यलाई स्वचालित रूपमा ट्याग गर्न रद्द गर्नुभयो';
							}
						}
					} else {
						document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = '<div style="color:red"><b>सार्न असफल <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></div> त्रुटि जानकारी: <b>' + response['error']['code'] + '</b>: ' + response['error']['info'];
					}
				}
			} else {
				document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = '<div style="color:red"><b>सार्न असफल <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></div>। त्रुटि जानकारी:' + response['error']['code'] + ' : ' + response['error']['info'];
			}
		}
	} catch (err) {
		document.getElementById('afcHelper_move' + escape(oldtitle)).innerHTML = '<div style="color:red"><b>सार्न असफल <a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(oldtitle)) + '" title="' + oldtitle + '">' + oldtitle + '</a></b></div>';
	}
	if (!error) {
		if (callback !== null) callback();
	}
	$("#afcHelper_AJAX_finished_" + func_id).css("display", '');
}

function afcHelper_onChange(select) {
	var value = select.options[select.selectedIndex].value;
	if (value === 'cv') $("#afcHelper_extra_inline").html('<label for="afcHelper_extra">Please enter the URL if available: </label><input type="text" id="afcHelper_extra_inlinebox" value="http://" size="100%"/>');
	else if (value === 'dup') $("#afcHelper_extra_inline").html('<label for="afcHelper_extra_inline">Please enter the title of the duplicate submission, if possible. Do not enter the prefix (e.g., John Doe): </label><input type="text" id="afcHelper_extra_inlinebox" value="" />');
	else if (value === 'mergeto') $("#afcHelper_extra_inline").html('<label for="afcHelper_extra_inline">Please enter the title of the article to merge to, if possible: </label><input type="text" id="afcHelper_extra_inlinebox" value="" />');
	else if (value === 'lang') $("#afcHelper_extra_inline").html('<label for="afcHelper_extra_inline">Please enter the language the article is written in, if possible/known (e.g. German): </label><input type="text" id="afcHelper_extra_inlinebox" value="" spellcheck="true"/>');
	else if (value === 'exists') $("#afcHelper_extra_inline").html('<label for="afcHelper_extra_inline">Please enter the title of the existing article, if possible: </label><input type="text" id="afcHelper_extra_inlinebox" value="" />');
	else if (value === 'plot') $("#afcHelper_extra_inline").html('<label for="afcHelper_extra_inline">Please enter the title of the existing article on the fiction, if there is one: </label><input type="text" id="afcHelper_extra_inlinebox" value="" />');
	else $("#afcHelper_extra_inline").html("");

	if (value === 'cv' || value === 'van') {
		// If it is a copyvio or vandalism, display the blank and csd options
		$("#afcHelper_blank").prop("checked", true);
		$("#afcHelper_blank").attr("data-typeof", "cv_van");
		afcHelper_turnvisible("afcHelper_extra_afccleared", true);
		afcHelper_turnvisible("afcHelper_afccleared", true);
		$("#afcHelper_blank_csd").prop("checked", true); // check the checkbox automagically
	} else if (value === 'blp') {
		// If it is just a BLP violation only display the blank option; do NOT csd
		$("#afcHelper_blank").prop("checked", true);
		$("#afcHelper_blank").attr("data-typeof", "blp");
		afcHelper_turnvisible("afcHelper_afccleared", true);
		afcHelper_turnvisible("afcHelper_extra_afccleared", false);
		$("#afcHelper_blank_csd").prop("checked", false); // so (!blank_csd) works correctly
	} else {
		// Otherwise leave these empty
		$("#afcHelper_blank").prop("checked", false);
		$("#afcHelper_blank").attr("data-typeof", "other");
		afcHelper_turnvisible("afcHelper_extra_afccleared", false);
		afcHelper_turnvisible("afcHelper_afccleared", false);
		$("#afcHelper_blank_csd").prop("checked", false); // so (!blank_csd) works correctly
	}
}

function afcHelper_cleanup(text) {
	// Remove html comments (<!--) that surround categories
	text = text.replace(/\<!--\s*((\[\[:{0,1}(Category:.*?)\]\]\s*)+)--\>/gi, "$1");

	// Comment out categories
	text = text.replace(/\[\[Category:/gi, "\[\[:Category:");

	// Fix {{afc comment}} when possible (takes rest of text on line and converts to a template parameter)
	text = text.replace(/\{\{afc comment(?!\s*\|\s*1\s*=)\s*\}\}\s*(.*?)\s*[\r\n]/ig, "\{\{afc comment\|1=$1\}\}\n");

	//Wikilink correction
	text = text.replace(/(\[){2}(?:https?:)?\/\/(ne.wikipedia.org\/wiki|newp.org)\/([^\s\|]+)(\s|\|)?((?:\[\[[^\[\]]*\]\]|[^\]\[])*)(\]){2}/gi, "\[\[$3$4$5\]\]");
	text = text.replace(/(\[){1}(?:https?:)?\/\/(ne.wikipedia.org\/wiki|newp.org)\/([^\s\|]+)(\s|\|)?((?:\[\[[^\[\]]*\]\]|[^\]\[])*)(\]){1}/gi, "\[\[$3$4$5\]\]");
	//KISS: for the case at the end of the url is a <ref> it detects all < symbols and stops there
	text = text.replace(/https?:\/\/(en.wikipedia.org\/wiki|enwp.org)\/([^\s\<]+)/gi, "\[\[$2\]\]");
	//remove boldings and big-tags from headlines; ignore level 1 headlines for not breaking URLs and other stuff!
	text = text.replace(/[\s\n]*(={2,})\s*(?:\s*<big>|\s*''')*\s*(.*?)\s*(?:\s*<\/big>|\s*''')*\s*?(={2,})[\n\s]*/gi, "\n\n$1 $2 $1\n\n");

	// Run AutoEd automatically
	var AutoEd_baseurl = '//ne.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=Wikipedia:AutoEd/';
	mw.loader.load(AutoEd_baseurl + 'unicodify.js', function() {
		text = autoEdUnicodify(text);
	});
	mw.loader.load(AutoEd_baseurl + 'isbn.js', function() {
		text = autoEdISBN(text);
	});
	mw.loader.load(AutoEd_baseurl + 'whitespace.js', function() {
		text = autoEdWhitespace(text);
	});
	mw.loader.load(AutoEd_baseurl + 'wikilinks.js', function() {
		text = autoEdWikilinks(text);
	});
	mw.loader.load(AutoEd_baseurl + 'htmltowikitext.js', function() {
		text = autoEdHTMLtoWikitext(text);
	});
	mw.loader.load(AutoEd_baseurl + 'headlines.js', function() {
		text = autoEdHeadlines(text);
	});
	mw.loader.load(AutoEd_baseurl + 'unicodecontrolchars.js', function() {
		text = autoEdUnicodeControlChars(text);
	});
	mw.loader.load(AutoEd_baseurl + 'unicodehex.js', function() {
		text = autoEdUnicodeHex(text);
	});
	mw.loader.load(AutoEd_baseurl + 'templates.js', function() {
		text = autoEdTemplates(text);
	});
	mw.loader.load(AutoEd_baseurl + 'tablestowikitext.js', function() {
		text = autoEdTablestoWikitext(text);
	});
	mw.loader.load(AutoEd_baseurl + 'extrabreaks.js', function() {
		text = autoEdExtraBreaks(text);
	});
	mw.loader.load(AutoEd_baseurl + 'links.js', function() {
		text = autoEdLinks(text);
	});

	// Run formatgeneral.js automatically
	mw.loader.load(mw.config.get('wgServer') + '/w/index.php?action=raw&ctype=text/javascript&title=User:Ohconfucius/test/formatgeneral.js/core.js', function() {
		function regex(search,replace,repeat) {
			// regex() function stolen from [[meta:User:Pathoschild/Scripts/Regex_menu_framework.js]]
			if(!repeat || repeat<0)	var repeat = 1;
			for(var i=0; i<repeat; i++) {
				text = text.replace(search,replace);
			}
		}
		ohc_change_type();
		Ohc_football_retrain();
		ohc_protect_fmt();
		Ohc_formats();
		ohc_unprotect_fmt();
		ohc_downcase_CEO();
		Ohc_final_cleanup();
	});

	//Ref tag correction part #1: remove whitespaces and commas between the ref tags and whitespaces before ref tags
	text = text.replace(/\s*(\<\/\s*ref\s*\>)\s*[,]*\s*(<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*>)\s*$/gim, "$1$2");
	text = text.replace(/\s*(<\s*ref\s*(name\s*=|group\s*=)*\s*.*[^\/]+>)\s*$/gim, "$1");
	//Ref tag correction part #2: move :;.,!? before ref tags
	text = text.replace(/\s*((<\s*ref\s*(name\s*=|group\s*=)*\s*.*[\/]{1}>)|(<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*>(?:\\<[^\<\>]*\>|[^><])*\<\/\s*ref\s*\>))\s*([.!?,;:])+$/gim, "$6$1");

	// Remove all unneeded HTML comments and wizards stuff
	text = text.replace("\* \[http\:\/\/www.example.com\/ example.com\]", "");
	text = text.replace(/'''Subject of my article''' is.../ig, "");
	text = text.replace(/\<\!--- Carry on from here, and delete this comment. ---\>/ig, "");
	text = text.replace(/\<\!--- Enter template purpose and instructions here. ---\>/ig, "");
	text = text.replace(/\<\!--- Enter the content and\/or code of the template here. ---\>/ig, "");
	text = text.replace(/\<\!-- EDIT BELOW THIS LINE --\>/ig, "");
	text = text.replace(/\<\!-- This will add a notice to the bottom of the page and won't blank it! The new template which says that your draft is waiting for a review will appear at the bottom; simply ignore the old \(grey\) drafted templates and the old \(red\) decline templates. A bot will update your article submission. Until then, please don't change anything in this text box\s*(and|.\s*Just)+ press "Save page". --\>/ig, "");
	text = text.replace(/\<\!--Do not include any categories - these don't need to be added until the article is accepted; They will just get removed by a bot!--\>/ig, "");
	text = text.replace(/\<\!--- Categories ---\>/gi, '');
	text = text.replace(/\<\!--- After listing your sources please cite them using inline citations and place them after the information they cite. Please see \[\[Wikipedia:REFB\]\] for instructions on how to add citations. ---\>/ig, "");
	text = text.replace(/\<\!-- Be sure to cite all of your sources in \<ref\>...\<\/ref\> tags and they will automatically display when you hit save. The more reliable sources added the better! See \[\[Wikipedia:REFB\]\] for more information--\>/ig, "");
	text = text.replace(/\<\!--- See \[\[Wikipedia:Footnotes\]\] on how to create references using \<ref\>\<\/ref\> tags which will then appear here automatically --\>/ig, "");
	text = text.replace(/\<\!--Please don't change anything and press save --\>/ig, "");
	text = text.replace(/\<\!-- Please leave this line alone! --\>/ig, "");
	text = text.replace(/\<\!-- Do not include any categories - these don't need to be added until the article is accepted; They will just get removed by a bot! --\>/ig, "");
	text = text.replace(/\<\!-{1,3}\s*Important, do not remove this line before (template|article) has been created.\s*-{1,3}\>/ig, "");
	text = text.replace(/\<\!-- Just press the \"Save page\" button below without changing anything! Doing so will submit your article submission for review. Once you have saved this page you will find a new yellow 'Review waiting' box at the bottom of your submission page. If you have submitted your page previously, the old pink 'Submission declined' template or the old grey 'Draft' template will still appear at the top of your submission page, but you should ignore them. Again, please don't change anything in this text box. Just press the \"Save page\" button below. --\>/ig, "");
	text = text.replace(/== Request review at \[\[WP:AFC\]\] ==\n/ig, "");
	text = text.replace(/(?:<\s*references\s*>([\S\s]*)<\/references>|<\s*references\s*\/\s*>)/gi, "\n{{reflist|refs=$1}}");
	text = text.replace("{{reflist|refs=}}", "{{reflist}}"); // hack to make sure we don't leave an unneeded |refs=
	text = text.replace(/\{\{(userspacedraft|userspace draft|user sandbox)(?:\{\{[^{}]*\}\}|[^}{])*\}\}/ig, "");
	text = text.replace(/<!--\s*-->/ig, ""); // Remove empty HTML comments
	text = text.replace(/^----+$/igm, ""); // Removes horizontal rules
	text = text.replace(/\[\[:श्रेणी:लेख विजार्ड मार्फत सृजना गरिएका लेखहरू\]\]/gi, "[[श्रेणी:लेख विजार्ड मार्फत सृजना गरिएका लेखहरू]]");
	text = text.replace(/\[\[:?श्रेणी:लेखसृजना(_|\s*)+निवेदनहरू(_|\s*)+जुन(_|\s*)+ढाँचा(_|\s*)+AfC(_|\s*)+हराइरहेका\]\]/gi, ""); // Remove "AfC submission with missing AfC template" maintenace category

	var afc_re = /\{\{\s*afc submission\s*\|\s*[||h|r](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
	var afc_alt = /\{\{\s*afc submission\s*\|\s*[^t](?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
	var afc_all = /\{\{\s*afc submission\s*\|\s*(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
	var afc_comment = /\{\{\s*afc comment(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;

	// Remove all draft templates
	if (afc_alt.test(text)) text = text.replace(/\{\{\s*afc submission\s*\|\s*t(?:\{\{[^{}]*\}\}|[^}{])*\}\}/ig, "");
	// Find the first pending submission or marked as review on the page.
	var temp = text;
	//Remove any duplicate open review requests before saving the page (only affects open requests)
	//find the first pending template and remove it, if one was removed too much, revert the last removal
	while (afc_re.test(text)) {
		temp = text;
		text = text.replace(/\{\{\s*afc submission\s*\|\s*[||h|r](?:\{\{[^{}]*\}\}|[^}{])*\}\}/i, "");
		if (!afc_re.test(text)) {
			text = temp;
			break;
		}
	}
	//create an array, strip the submission templates, then AFC comments and then add them back to the page
	var submissiontemplates = new Array();
	var commentstemplates = new Array();
	while (afc_all.test(text)) {
		submissiontemplates.push(afc_all.exec(text));
		text = text.replace(afc_all.exec(text), "");
	}
	while (afc_comment.test(text)) {
		commentstemplates.push(afc_comment.exec(text));
		text = text.replace(afc_comment.exec(text), "");
	}
	// Remove empty HTML comments
	text = text.replace(/<!--\s*-->/ig, "");

	// Remove empty list elements and empty headers
	text = text.replace(/^\s*[\*#:;]\s*$/igm, "");

	//adding back the submission templates and comment templates
	if (commentstemplates.length > 0) {
		text = '----\n' + text;
		for ((i = commentstemplates.length - 1); i >= 0; i--)
		text = commentstemplates[i] + '\n\n' + text;
	}
	if (submissiontemplates.length > 0) {
		var find_shrinked = /\|\s*small\s*=\s*yes/gi;
		for ((i = submissiontemplates.length - 1); i >= 0; i--) {
			if (i === (submissiontemplates.length - 1)) {
				var temp = submissiontemplates[i].toString();
				if (find_shrinked.test(submissiontemplates[i])) {
					temp = temp.replace(find_shrinked, "");
				}
				text = temp + '\n' + text;
			} else if (i >= 0) {
				if (find_shrinked.test(submissiontemplates[i])) {
					text = submissiontemplates[i] + text;
				} else {
					var temp = submissiontemplates[i].toString();
					temp = temp.slice(0, temp.length - 2);
					text = temp + '\|small=yes\}\}' + text;
				}
			}
		}
	}

	// Remove excess newlines
	text = text.replace(/(?:[\t ]*(?:\r?\n|\r)){3,}/ig,'\n\n');

	return text;
}

function afcHelper_setup() {
	/* Gets the pagetext, does some cleanup, lists previous deletions,
	and displays warnings about long comments and bad reference styles */
	textdata = afcHelper_getPageText(afcHelper_PageName, false, false, true); // get page text AND timestamp to save API calls
	pagetext = textdata.pagetext;
	afcHelper_cache.afcHelper_lastedited = textdata.timestamp; // Store the last edited date to the cache

	// Fix utterly invalid templates so cleanup doesn't mangle them
	pagetext = pagetext.replace(/\{\{AFC submission(\s*\|){0,}ts\s*=\s*/gi, "{{AFC submission|||ts=");
	pagetext = pagetext.replace(/\{\{AFC submission\s*\}\}/gi, "{{AFC submission|||ts={{subst:LOCALTIMESTAMP}}|u=|ns={{subst:AFC submission/namespace number}}}}");
	pagetext = afcHelper_cleanup(pagetext);

	warnings = afcHelper_warnings(pagetext); // Warn about problems with given pagetext

	return warnings; // Prepends the warnings
}

function afcHelper_warnings(pagetext) {
	//longer than 30 characters, but commonly added to the source code
	texttest = pagetext.replace(/\<\!--  Bot generated title --\>/gi, "");
	texttest = texttest.replace(/\<\!-- See Wikipedia\:WikiProject Musicians --\>/gi, "");
	texttest = texttest.replace(/\<\!-- Only for images narrower than 220 pixels --\>/gi, "");
	texttest = texttest.replace(/\<\!-- Metadata\: see \[\[Wikipedia\:Persondata\]\]. --\>/gi, "");
	// Bad workaround to fix the error message; will be removed later in cleanup()
	texttest = texttest.replace(/\<\!-- Be sure to cite all of your sources in \<ref\>...\<\/ref\> tags and they will automatically display when you hit save. The more reliable sources added the better! See \[\[Wikipedia:REFB\]\] for more information--\>/ig, "");
	var errormsg = '';

	// test if there are 30+ character html comments in the page text
	var recomment = /\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-]){30,})(--[ \r\n\t]*\>|$)/gi;
	var matched;
	while (matched = recomment.exec(texttest)) {
		if (errormsg == '') errormsg += '<h3><div class="afch-notice">Please check the source code! This page contains one or more long (30+ characters) HTML comments! <em>(please report false positives)</em></div></h3>';
		errormsg += 'The hidden text is: <i>' + matched[1] + '</i><br/>';
	}

	//Check the deletion log and list it!
	var request = {
				'action': 'query',
				'list': 'logevents',
				'format': 'json',
				'leprop': 'user|timestamp|comment',
				'leaction': 'delete/delete',
				'letype': 'delete',
				'lelimit': 10,
				'leprop': 'user|timestamp|comment',
				'letitle': afcHelper_submissionTitle
			};
	var response = JSON.parse(
		$.ajax({
			url: mw.util.wikiScript('api'),
			data: request,
			async: false
		})
		.responseText
	);
	var deletionlog = response['query']['logevents'];
	if (deletionlog.length) {
		errormsg += ('<h3><div class="afch-notice">पृष्ठ ' + afcHelper_escapeHtmlChars(afcHelper_submissionTitle) + ' हटाइएको थियो ' + deletionlog.length + ' time' + ((deletionlog.length != 1) ? "s" : "") + '। यहाँ ' + ((deletionlog.length != 1) ? "छन" : "छ") + ' सम्पादन सारांश' + ((deletionlog.length != 1) ? "हरू" : "y") + ' बाट <a href="' + mw.config.get('wgScript') + '?title=Special%3ALog&type=delete&page=' + afcHelper_submissionTitle + '" target="_blank">मेटाएको लग</a>:</div></h3><table class="wikitable"><tr><td><b>Timestamp</b></td><td><b>User</b></td><td><b>कारण</b></td></tr>');
		for (var i = 0; i < deletionlog.length; i++) {
			var deletioncomment = deletionlog[i].comment;
			var deletioncomment1_re = /\[\[([^\[\]]*?[^\]\|]*?)(\|([^\[\]]*?))\]\]/gi;
			var deletioncomment2_re = /\[\[((?:\[\[[^\[\]]*\]\]|[^\]\[[])*)\]\]/gi;
			//first handle wikilinks with piped links
			while (dlmatch = deletioncomment1_re.exec(deletioncomment)) {
				deletioncomment = deletioncomment.replace(dlmatch[0], "<a href=\"" + mw.config.get('wgArticlePath').replace("$1", encodeURIComponent(dlmatch[1])) + "\" target=\"_blank\" title=\"" + dlmatch[1] + "\"></a>");
				deletioncomment = deletioncomment.replace("\"></a>", "\">" + dlmatch[3] + "</a>");
				deletioncomment = deletioncomment.replace("</a>|" + dlmatch[3], "</a>");
			}
			//now the rest
			while (dlmatch = deletioncomment2_re.exec(deletioncomment)) {
				deletioncomment = deletioncomment.replace(dlmatch[0], "<a href=\"" + mw.config.get('wgArticlePath').replace("$1", encodeURIComponent(dlmatch[1])) + "\" target=\"_blank\" title=\"" + dlmatch[1] + "\">" + dlmatch[1] + "</a>");
			}
			errormsg += '<tr><td>' + deletionlog[i].timestamp + '</td><td><a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURIComponent("User:" + deletionlog[i].user)) + '" target="_blank" title="User:' + deletionlog[i].user + '">' + deletionlog[i].user + '</a> (<a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURIComponent("User talk:" + deletionlog[i].user)) + '" target="_blank" title="User talk:' + deletionlog[i].user + '">talk</a>)</td><td>' + deletioncomment + '</td></tr>';
		}
		errormsg += '</table>';
	}

	// count <ref> and </ref> and check if it fits
	var rerefbegin = /\<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*>/ig;
	var rerefend = /\<\/\s*ref\s*\>/ig;
	var reflistre = /(\{\{reflist(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\})|(\<\s*references\s*\/\s*\>)/i;
	refbegin = texttest.match(rerefbegin);
	refend = texttest.match(rerefend);
	if (refbegin) { //Firefox workaround!
		if (refend) { //Firefox workaround!
			if (refbegin.length !== refend.length) {
				errormsg += '<h3><div class="afch-notice">कृपया स्रोत कोड जाँच गर्नुहोस्! यस पृष्ठमा बन्द नगरिएको &lt;ref&gt; ट्यागहरू छन्!</div></h3>';
			}
		} else {
			errormsg += '<h3><div class="afch-notice">कृपया स्रोत कोड जाँच गर्नुहोस्! यस पृष्ठमा असन्तुलित &lt;ref&gt; र &lt;/ref&gt; ट्यागहरू छन्!</div></h3>';
		}
	}
	//test if ref tags are used, but no reflist available
	if ((!reflistre.test(pagetext)) && refbegin) {
		errormsg += '<h3><div class="afch-notice">सावधान रहनुहोस्, त्यहाँ &lt;ref&gt; ट्याग प्रयोग गरियो, तर कुनै सन्दर्भ सूची छैन (reflist)! तपाईले सबै सन्दर्भहरू देख्न सक्नुहुन्न।</div></h3>';
	}

	// test if <ref> foo <ref> on the page and place the markup on the box
	var rerefdouble = /\<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*\>?(\<\s*[^\/]*\s*ref\s*(name\s*=|group\s*=)*)/ig;
	var refdouble = texttest.match(rerefdouble);
	if (refdouble) {
		errormsg += 'स्क्रिप्टले निम्न विकृत सन्दर्भ भेट्टायो:<br/><i>';
		for (i = 0; i < refdouble.length; i++)
		errormsg += afcHelper_escapeHtmlChars(refdouble[i].toString()) + '&gt;<br/>';
		errormsg += '</i>';
	}
	// test if there are ref tags after reflist
	var temppagetext = pagetext;
	var n = temppagetext.search(reflistre);
	var o = temppagetext.match(reflistre);
	if (o) {
		temppagetext = temppagetext.slice(n + o[0].length);
		if ((temppagetext.search(rerefbegin)) > -1) {
			errormsg += '<h3><div class="afch-notice">सावधान रहनुहोस्, त्यहाँ &lt;ref&gt; सन्दर्भ सूची पछि एक ट्याग छ! तपाईले सबै सन्दर्भहरू देख्न सक्नुहुन्न।</div></h3>';
		}
	}
	return errormsg;
}

function afcHelper_trigger(type) {
	var e = document.getElementById(type);
	if (type === "afcHelper_biography_status_box") {
		var f = document.getElementById("afcHelper_biography_status");
		if (f.value === "dead") {
			e.style.display = 'block';
		} else {
			e.style.display = 'none';
		}
	} else if (type === "afcHelper_afcccleared") {
		if ($("#afcHelper_blank").attr("data-typeof") == "cv_van" && $('#afcHelper_blank').prop("checked")) {
			var f = document.getElementById("afcHelper_extra_afccleared");
			f.style.display = 'block';
		} else if (!$('#afcHelper_blank').prop("checked")) {
			var f = document.getElementById("afcHelper_extra_afccleared");
			f.style.display = 'none';
		}
	} else {
		e.style.display = ((e.style.display !== 'none') ? 'none' : 'block');
	}
}

function afcHelper_displaymessagehelper(type,detail) {
	// type == "done" for messages that should be displayed when ajax is completely finished
	// type == "status" for messages that should be displayed as they occur
	if (type === "done") {
		if (detail === "standard") {
			document.getElementById('afcHelper_finish').innerHTML += '<span id="afcHelper_finished_wrapper"><span id="afcHelper_finished_main" style="display:none"><li id="afcHelper_done"><b>सम्पन्न (<a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(afcHelper_PageName)) + '?action=purge" title="' + afcHelper_PageName + '">पृष्ठ पुन: लोड गर्नुहोस्</a>)</b></li></span></span>';
		} else if (detail === "cleanednochange") {
			document.getElementById('afcHelper_finish').innerHTML += '<span id="afcHelper_finished_wrapper"><span id="afcHelper_finished_main"><span id="afcHelper_done"><li id="afcHelper_done"><b>यो निवेदन पहिल्यै सफा भइसकेको छ। केहि परिवर्तन भएको छैन। (<a href="' + mw.config.get('wgArticlePath').replace("$1", encodeURI(afcHelper_PageName)) + '?action=purge" title="' + afcHelper_PageName + '">पृष्ठ पुन: लोड गर्नुहोस्</a>)</b></li></span></span>';
		}
	} else if (type === "status") {
		if (detail === "orphan") {
			document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_orphan">लेख अनाथ हो कि होइन भनेर जाँच गर्दै...</li>';
		}
	} else {
		// Unrecognized
		return false;
	}
}

function afcHelper_last_nonbot(title) {
	var request = {
				'action': 'query',
				'prop': 'revisions',
				'format': 'json',
				'rvprop': 'user%7Ctimestamp',
				'rvlimit': 1,
				'rvdir': 'older',
				'rvexcludeuser': 'ArticlesForCreationBot',
				'indexpageids': true,
				'titles' : title
			};

	var response = JSON.parse(
		$.ajax({
			url: mw.util.wikiScript('api'),
			data: request,
			async: false
		})
		.responseText
	);
	pageid = response['query']['pageids'][0];
	revisions = response['query']['pages'][pageid]['revisions'];
	return response['query']['pages'][pageid]['revisions'][0];
}

function afcHelper_logcsd(title,reason,usersnotified) {
	// Update the user's Twinkle CSD log if they have one
	var speedyLogPageName = "User:" + mw.config.get('wgUserName') + "/" + (Twinkle.getPref('speedyLogPageName') || "शीमे लग");
	CSDlogtext = afcHelper_getPageText(speedyLogPageName);
	if (CSDlogtext) { // Only update the log if it exists
		var appendText = "";
		// Add header for new month if necessary (this `date` bit is directly from the Twinkle source code)
		var date = new Date();
		var headerRe = new RegExp("^==+\\s*" + date.getUTCMonthName() + "\\s+" + date.getUTCFullYear() + "\\s*==+", "m");
		if (!headerRe.exec(CSDlogtext)) {
			appendText += "\n\n=== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ===";
		}
		appendText += "\n# [[:" + title + "]]: " + reason;
		if (usersnotified) appendText += "; notified ";
		$.each(usersnotified, function(index, user) {
			if (index > 0) appendText += ", ";
			appendText += "{{user|1=" + user + "}}";
		});
		appendText += " ~~~~~\n";
		afcHelper_editPage(speedyLogPageName,CSDlogtext + appendText,"शीघ्र मेटाउन नामाङ्कन गर्दै [[" + title + "]]")
	}
}

function afcHelper_g13_eligible(title) {
	var timeNow = new Date();
	var timeNowMonth = timeNow.getMonth();
	var sixMonthsAgo = new Date();
	sixMonthsAgo.setMonth(timeNowMonth - 6);
	var lastEdited = new Date(afcHelper_cache.afcHelper_lastedited);
	if ((timeNow.getTime() - lastEdited.getTime()) > (timeNow.getTime() - sixMonthsAgo.getTime())){
		return true;
	} else {
		return false;
	}
}

function afcHelper_page_creator(title) {
	if (afcHelper_cache[title]) return afcHelper_cache[title];
	var request = {
				'action': 'query',
				'prop': 'revisions',
				'rvprop': 'user',
				'format': 'json',
				'rvdir': 'newer',
				'rvlimit': 1,
				'indexpageids': true,
				'titles' : title
			};
	var response = JSON.parse(
		$.ajax({
			url: mw.util.wikiScript('api'),
			data: request,
			async: false
		})
		.responseText
	);
	pageid = response['query']['pageids'][0];
	user = response['query']['pages'][pageid]['revisions'][0]['user'];
	afcHelper_cache[title] = user;
	return user;
}

function afcHelper_turnvisible(id, visible) {
	if (visible) $("#" + id).css("display", "block");
	else $("#" + id).css("display", "none");
}

// Finally display the Review link
var afcportletLink = mw.util.addPortletLink('p-cactions', '#', 'समीक्षा गर्नुहोस्', 'ca-afcHelper', 'समीक्षा गर्नुहोस्', 'a');
$(afcportletLink).click(function(e) {
	e.preventDefault();
	afcHelper_init();
});

//</nowiki>