میدیاویکی:Gadget-DiscussionCloser.js

تێبینی: دوای پاشەکەوتکردن، پێویستە کاشی وێبگەڕەکەت پاک بکەیتەوە تا گۆڕانکارییەکان ببینیت. بۆ گووگڵ کڕۆم، فایەرفۆکس، مایکرۆسۆفت ئێج و سافاری: پەنجە لەسەر دوگمەی ⇧ Shift ڕاگرە و کرتە لەسەر Reload بکە. بۆ وردەکاری و ڕێنمایییەکان لەسەر وێبگەڕەکانی تر، بڕوانە ئێرە.
//based on user:DannyS712/DiscussionCloser.js
//<nowiki>
//Credits to Equazcion, Evad37, and Abelmoschus Esculentus
//Date: 6 Mar 2019
//Forked from [[User:Abelmoschus Esculentus/DiscussionCloser.js]
//Maintained by DannyS712
function dc_init() {
	if ((($('#ca-addsection').length > 0) || (mw.config.get('wgPageName') == 'ویکیپیدیا:تەختەی ئاگاداریی بەڕێوەبەران/شەڕە دەستکاری') || (mw.config.get('wgPageName') == 'ویکیپیدیا:لە هەواڵەکاندا/کاندیدەکان')) && (mw.config.get('wgAction') == 'view')){
		$('span.mw-headline').each(function(index, value){
			var editSectionUrl = $(this).parent().find('.mw-editsection a:first').attr('href');
			var sectionReg = /&section=(.*)/;
			var sectionRaw = sectionReg.exec(editSectionUrl);
			if ((sectionRaw !== null) && (sectionRaw[1].indexOf('T') < 0)){
				var section = parseInt(sectionRaw[1]);
				if ($(this).parent().prop("tagName") == 'H2') {
					$(this).parent('h2').append(' <div style="font-size:.6em;font-weight:bold;float:left"> | <a id="' + section + 
						'" class="closeLink">' + 'داخستن' + '</a></div>');
					$(this).parent('h2').find('a.closeLink').click(function(){
						$('body').prepend('<div id="DC-modal">'+
					    '<div id="DC-interface">'+
					      '<h4 id="DC-interface-header"></h4>'+
					      '<hr>'+
					      '<div id="DC-interface-content"></div>'+
					      '<hr>'+
					      '<div id="DC-interface-footer"></div>'+
					    '</div>'+
					  '</div>');
					  $("#DC-modal").css({
					    "position": "fixed",
					    "z-index": "1",
					    "right": "0",
					    "top": "0",
					    "width": "100%",
					    "height": "100%",
					    "overflow": "hidden",
					    "background-color": "rgba(0,0,0,0.4)"
					  });
					  $("#DC-interface").css({
					    "background-color": "#d6d6d6",
					    "margin": "10% auto",
					    "padding": "2px 20px",
					    "border": "1px solid #888",
					    "width": "80%",
					    "max-width": "60em",
					    "font-size": "90%"
					  });
					  $("#DC-interface-content").css({
					    "min-height": "7em",
					    "width" : "875px",
					    "height" : "400px",
					    "overflow-y": "scroll"
					  });
					  $("#DC-interface-footor").css("min-height", "3em");
						$("#DC-interface-header, #DC-interface-content, #DC-interface-footer").empty();
						$("#DC-interface-header").text("داخەری وتووێژ");
						$("#DC-interface-content").append(
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').attr({'id':'DC-label'}).text('Options: '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio1','value':'atop','checked':'true','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (شین) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio2','value':'atopg','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (سەوز) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio3','value':'atopy','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (زەرد) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio4','value':'atopr','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (سوور) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'داواکردنی لێدوان','onchange':'dc_radio(2)'}),
						    $('<label>').text('داواکردنی لێدوان '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'hat','onchange':'dc_radio(2)'}),
						    $('<label>').text('ئەرشیڤی شاردراوە ')
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').text('حاڵەت (دڵخواز): '),
						    $('<input>').attr({'type':'text','name':'DC-e','id':'DC-e'})
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').text('لێدوانی داخستن:'),
						    $('<textarea>').css({'resize':'none'}).attr({'name':'DC-com','id':'DC-com','rows':'17','cols':'30'})
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
								$('<label>').text('کورتەی دەستکاری: '),
						    $('<input>').attr({'type':'text','name':'DC-es','id':'DC-es'})
							),
							$('<div>').css('margin-bottom','0.5em').attr('id','DC-prevt'),
							$('<div>').css('margin-bottom','0.5em').attr('id','DC-prevdiv'),
							$('<button>').attr('id', 'DC-closeprev').text('پێشبینین').hide()
						);
						$("#DC-interface-footer").append(
							$('<button>').attr({'name':'DC-done', 'id':'DC-done'}).text('بەستنی وتووێژ'),
							$('<button>').attr({'name':'DC-prev', 'id':'DC-prev'}).text('پێشبینین'),
							$('<button>').attr('id', 'DC-cancel').text('پاشگەزبوونەوە'),
							$('<label>').attr('id','DC-loading').text(' پێشبینین بار دەکرێت...').hide()
						);
						document.getElementById("DC-modal").addEventListener( "keydown", function ( key ) {
				        	if( key.ctrlKey && ( key.keyCode == 10 || key.keyCode == 13 ) ) {
				            	document.getElementById("DC-done").click();
				            }
				            else if ( key.keyCode == 27 ){
				            	document.getElementById("DC-cancel").click();
				            }
			        	});
						$('#DC-cancel').click(function() {
						  $('#DC-modal').remove();
						});
						$('#DC-prev').click(function() {
							$('#DC-loading').show();
							var template = $("input[name=DC-radio]:checked").val();
							var status = $('#DC-e').val();
							var comment = $('#DC-com').val();
							var request = {
								action:"query", 
								titles: mw.config.get('wgPageName'), 
								rvsection: section,
								prop: "revisions|info", 
								intoken: "edit", 
								rvprop: "content",
								indexpageids: 1,
								dataType: "xml",
								format: "xml"
							};
							var bottom;
							if (template === 'atop' || template === 'atopr' || template === 'atopy' || template === 'atopg') {
								bottom = "{{بنی ئەرشیڤ}}";
							  }
							  else if (template === 'hat') {
								bottom = "{{hab}}";
							  }
							  else {
								bottom = "{{closed rfc bottom}}";
							  }
								if (!Morebits.userIsInGroup('sysop')) {
									comment += ' {{nac}}';
								}
								$.get(mw.config.get("wgScriptPath")+"/api.php", request, function(response){
									if (template === 'rfc') {
										template = "closed rfc top";
									}
								var contentSection = '\r\r' + $(response).find('rev').text();
								var discussiontext = contentSection.substring(contentSection.substring(3,contentSection.length).indexOf('\n')+3, contentSection.length);
								var title = contentSection.substring(2, contentSection.length - discussiontext.length);
												var wikitext = title + '\n{{'+template+'\n| status = '+status+'\n| result = '+comment+'\n}}'+discussiontext+'\n'+bottom;
												var sectiontitle = title.replace('==', '').replace('==', '').replace('\n', '').replace('/r','').trim();
												var sectiontitle2 = sectiontitle.replace(/ /g, '_');
												if (template === "closed rfc top") {
													wikitext = wikitext.replace(/(\r|\n)?{{rfc[^\}]*}}/g, '').replace(/(\r|\n)?<!--\s\[\[User:DoNotArchiveUntil\]\][^->]*-->{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, '');
												}
								jQuery.ajax({
									url:mw.util.wikiScript('api'),
									dataType:'json',
									type:'POST',
									data:{
											format:'json',
											action:'parse',
											pst:1,
											text:wikitext,
											title:mw.config.get('wgPageName'),
											prop:'text'
									}
								}).done(function(r) {
									if(!r.parse || !r.parse.text || !r.parse.text['*']){
										alert('کێشە هەیە لە پێشبینیندا.');
									}
									$('#DC-loading').hide();
									$('#DC-prevt').html('<hr>پێشبینین:<br>');
									$('#DC-prevdiv').html(r.parse.text['*']+'<br />').css({'display':'block','background-color':'white'});
									$('#DC-closeprev').show();
									$('#DC-closeprev').click(function() {
										$('#DC-prevt').empty();
										$('#DC-prevdiv').empty().css({'display':'','background-color':'','border-color':'',"border-width":"", "border-style":""});
										$('#DC-closeprev').hide();
									});
								});
							});
						});
						$('#DC-done').click(function() {
							var template = $("input[name=DC-radio]:checked").val();
							var status = $('#DC-e').val();
							var editsummary = $('#DC-es').val();
							if (editsummary === "") {
								editsummary = "بەستنی وتووێژ";
							}
							var comment = $('#DC-com').val();
							$('#DC-done').remove();
							$('#DC-prev').remove();
							$('#DC-cancel').remove();
            				$('#DC-interface-content').empty();
            				$("#DC-interface-content").text('زانیاری بەدەست دەھێنرێت...');
							var request = {
								action:"query", 
								titles: mw.config.get('wgPageName'), 
								rvsection: section,
								prop: "revisions|info", 
								intoken: "edit", 
								rvprop: "content",
								indexpageids: 1,
								dataType: "xml",
								format: "xml"
              };
              $("#DC-interface-content").append('<b>کرا!</b><br>وتووێژ دەبەسترێ...');
              var bottom;
              if (template === 'atop' || template === 'atopr' || template === 'atopy' || template === 'atopg') {
                bottom = "{{بنی ئەرشیڤ}}";
              }
              else if (template === 'hat') {
                bottom = "{{hab}}";
              }
              else {
                bottom = "{{closed rfc bottom}}";
              }
            	if (!Morebits.userIsInGroup('sysop')) {
			    	comment += ' {{nac}}';
				}
				$.get(mw.config.get("wgScriptPath")+"/api.php", request, function(response){
					if (template === 'rfc') {
						template = "closed rfc top";
					}
                var contentSection = '\r\r' + $(response).find('rev').text();
                var discussiontext = contentSection.substring(contentSection.substring(3,contentSection.length).indexOf('\n')+3, contentSection.length);
                var title = contentSection.substring(2, contentSection.length - discussiontext.length);
								var wikitext = title + '\n{{'+template+'\n| status = '+status+'\n| result = '+comment+'\n}}'+discussiontext+'\n'+bottom;
								var sectiontitle = title.replace('==', '').replace('==', '').replace('\n', '').replace('/r','').trim();
								var sectiontitle2 = sectiontitle.replace(/ /g, '_');
								if (template === "closed rfc top") {
									wikitext = wikitext.replace(/(\r|\n)?{{rfc[^\}]*}}/g, '').replace(/(\r|\n)?<!--\s\[\[User:DoNotArchiveUntil\]\][^->]*-->{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, '');
								}
								var request2 = {
									action:"edit", 
									section: section, 
									title: mw.config.get('wgPageName'), 
									text: wikitext,
									summary: '/* '+sectiontitle+' */ '+editsummary+' (داخەری وتووێژ)',
									token: mw.user.tokens.get("csrfToken")
								};
								if (contentSection.includes('{{سەری ئەرشیڤ')||contentSection.includes('{{atopr')||contentSection.includes('{{atopg')||contentSection.includes('{{atopy')||contentSection.includes('{{hat')||contentSection.includes('{{بنی ئەرشیڤ')||contentSection.includes('{{ئەرشیڤ')||contentSection.includes('{{Rfctop')||contentSection.includes('{{rfctop')||contentSection.includes('{{سەری ئەرشیڤ')||contentSection.includes('{{Atopr')||contentSection.includes('{{Atopy')||contentSection.includes('{{Atopg')||contentSection.includes('{{بنی ئەرشیڤ')||contentSection.includes('{{Rfc bottom')||contentSection.includes('{{بنی ئەرشیڤ')||contentSection.includes('{{بنی ئەرشیڤ')||contentSection.includes('{{hidden archive bottom')||contentSection.includes('{{Hidden archive bottom')) {
									var cont = confirm('The discussion may have already been closed. Continue?');
									if (!cont) {
										$("#DC-interface-content").append('<b>Aborted by user</b><br><b>Finished!</b>');
										$('#DC-interface-footer').append(
											$('<button>').attr('id', 'DC-close').text('Close')
										);
										$('#DC-close').click(function() {
										$('#DC-modal').remove();
											window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
											window.location.reload();
										});
									}
									else {
									$.when(
					                  $.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response2){
					                    
					                  }).done(function() {
									 $("#DC-interface-content").append('<b>کرا!</b><br><b>سەرکەوتوو بوو.</b>');
									 $('#DC-interface-footer').append(
										$('<button>').attr('id', 'DC-close').text('داخستن')
									);
									$('#DC-close').click(function() {
										$('#DC-modal').remove();
										window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
										window.location.reload();
									});
								 }));
									}
								}
								else {
                $.when(
                  $.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response2){
                    
                  }).done(function() {
									 $("#DC-interface-content").append('<b>کرا!</b><br><b>سەرکەوتوو بوو!</b>');
									 $('#DC-interface-footer').append(
										$('<button>').attr('id', 'DC-close').text('داخستن')
									);
									$('#DC-close').click(function() {
										$('#DC-modal').remove();
										window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
										window.location.reload();
									});
								 }));
								}
							});
						});
					});
				}
				if ($(this).parent().prop("tagName") == 'H3') {
					$(this).parent('h3').append(' <div style="font-size:.6em;font-weight:bold;float:left"> | <a id="' + section + 
						'" class="closeLink">' + 'داخستن' + '</a></div>');
					$(this).parent('h3').find('a.closeLink').click(function(){
						$('body').prepend('<div id="DC-modal">'+
					    '<div id="DC-interface">'+
					      '<h4 id="DC-interface-header"></h4>'+
					      '<hr>'+
					      '<div id="DC-interface-content"></div>'+
					      '<hr>'+
					      '<div id="DC-interface-footer"></div>'+
					    '</div>'+
					  '</div>');
					  $("#DC-modal").css({
					    "position": "fixed",
					    "z-index": "1",
					    "right": "0",
					    "top": "0",
					    "width": "100%",
					    "height": "100%",
					    "overflow": "hidden",
					    "background-color": "rgba(0,0,0,0.4)"
					  });
					  $("#DC-interface").css({
					    "background-color": "#d6d6d6",
					    "margin": "10% auto",
					    "padding": "2px 20px",
					    "border": "1px solid #888",
					    "width": "80%",
					    "max-width": "60em",
					    "font-size": "90%"
					  });
					  $("#DC-interface-content").css({
					    "min-height": "7em",
					    "width" : "875px",
					    "height" : "400px",
					    "overflow-y": "scroll"
					  });
					  $("#DC-interface-footor").css("min-height", "3em");
						$("#DC-interface-header, #DC-interface-content, #DC-interface-footer").empty();
						$("#DC-interface-header").text("داخەری وتووێژ");
						$("#DC-interface-content").append(
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').attr({'id':'DC-label'}).text('Options: '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio1','value':'atop','checked':'true','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (شین) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio2','value':'atopg','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (سەوز) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio3','value':'atopy','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (زەرد) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio4','value':'atopr','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (سوور) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'rfc','onchange':'dc_radio(2)'}),
						    $('<label>').text('داواکردنی لێدوان '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'hat','onchange':'dc_radio(2)'}),
						    $('<label>').text('Hidden archive ')
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').text('Status (optional): '),
						    $('<input>').attr({'type':'text','name':'DC-e','id':'DC-e'})
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').text('لێدوانی داخستن:'),
						    $('<textarea>').css({'resize':'none'}).attr({'name':'DC-com','id':'DC-com','rows':'17','cols':'30'})
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
								$('<label>').text('کورتەی دەستکاری: '),
						    $('<input>').attr({'type':'text','name':'DC-es','id':'DC-es'})
							),
							$('<div>').css('margin-bottom','0.5em').attr('id','DC-prevt'),
							$('<div>').css('margin-bottom','0.5em').attr('id','DC-prevdiv'),
							$('<button>').attr('id', 'DC-closeprev').text('داخستنی پێشبینین').hide()
						);
						$("#DC-interface-footer").append(
							$('<button>').attr({'name':'DC-done', 'id':'DC-done'}).text('داخستنی وتووێژ'),
							$('<button>').attr({'name':'DC-prev', 'id':'DC-prev'}).text('پێشبنین'),
							$('<button>').attr('id', 'DC-cancel').text('پاشگەزبوونەوە'),
							$('<label>').attr('id','DC-loading').text(' پێشبینین بار دەکرێت').hide()
						);
						document.getElementById("DC-modal").addEventListener( "keydown", function ( key ) {
				        	if( key.ctrlKey && ( key.keyCode == 10 || key.keyCode == 13 ) ) {
				            	document.getElementById("DC-done").click();
				            }
				            else if ( key.keyCode == 27 ){
				            	document.getElementById("DC-cancel").click();
				            }
			        	});
						$('#DC-cancel').click(function() {
						  $('#DC-modal').remove();
						});
						$('#DC-prev').click(function() {
							$('#DC-loading').show();
							var template = $("input[name=DC-radio]:checked").val();
							var status = $('#DC-e').val();
							var comment = $('#DC-com').val();
							var request = {
								action:"query", 
								titles: mw.config.get('wgPageName'), 
								rvsection: section,
								prop: "revisions|info", 
								intoken: "edit", 
								rvprop: "content",
								indexpageids: 1,
								dataType: "xml",
								format: "xml"
							};
							var bottom;
							if (template === 'atop' || template === 'atopr' || template === 'atopy' || template === 'atopg') {
								bottom = "{{بنی ئەرشیڤ}}";
							  }
							  else if (template === 'hat') {
								bottom = "{{hab}}";
							  }
							  else {
								bottom = "{{closed rfc bottom}}";
							  }
								if (!Morebits.userIsInGroup('sysop')) {
									comment += ' {{nac}}';
								}
								$.get(mw.config.get("wgScriptPath")+"/api.php", request, function(response){
									if (template === 'rfc') {
										template = "closed rfc top";
									}
								var contentSection = '\r\r' + $(response).find('rev').text();
								var discussiontext = contentSection.substring(contentSection.substring(3,contentSection.length).indexOf('\n')+3, contentSection.length);
								var title = contentSection.substring(2, contentSection.length - discussiontext.length);
												var wikitext = title + '\n{{'+template+'\n| status = '+status+'\n| result = '+comment+'\n}}'+discussiontext+'\n'+bottom;
												var sectiontitle = title.replace('===', '').replace('===', '').replace('\n', '').replace('/r','').trim();
												var sectiontitle2 = sectiontitle.replace(/ /g, '_');
												if (template === "closed rfc top") {
													wikitext = wikitext.replace(/(\r|\n)?{{rfc[^\}]*}}/g, '').replace(/(\r|\n)?<!--\s\[\[User:DoNotArchiveUntil\]\][^->]*-->{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, '');
												}
								jQuery.ajax({
									url:mw.util.wikiScript('api'),
									dataType:'json',
									type:'POST',
									data:{
											format:'json',
											action:'parse',
											pst:1,
											text:wikitext,
											title:mw.config.get('wgPageName'),
											prop:'text'
									}
								}).done(function(r) {
									if(!r.parse || !r.parse.text || !r.parse.text['*']){
										alert('کێشە هەیە لە پێشبینین.');
									}
									$('#DC-loading').hide();
									$('#DC-prevt').html('<hr>پێشبینین:<br>');
									$('#DC-prevdiv').html(r.parse.text['*']+'<br />').css({'display':'block','background-color':'white'});
									$('#DC-closeprev').show();
									$('#DC-closeprev').click(function() {
										$('#DC-prevt').empty();
										$('#DC-prevdiv').empty().css({'display':'','background-color':'','border-color':'',"border-width":"", "border-style":""});
										$('#DC-closeprev').hide();
									});
								});
							});
						});
						$('#DC-done').click(function() {
							var template = $("input[name=DC-radio]:checked").val();
							var status = $('#DC-e').val();
							var editsummary = $('#DC-es').val();
							if (editsummary === "") {
								editsummary = "وتووێژ دادەخرێت";
							}
							var comment = $('#DC-com').val();
							$('#DC-done').remove();
							$('#DC-prev').remove();
							$('#DC-cancel').remove();
            				$('#DC-interface-content').empty();
            				$("#DC-interface-content").text('زانیاریی بەدەست دەهێندرێت...');
							var request = {
								action:"query", 
								titles: mw.config.get('wgPageName'), 
								rvsection: section,
								prop: "revisions|info", 
								intoken: "edit", 
								rvprop: "content",
								indexpageids: 1,
								dataType: "xml",
								format: "xml"
              };
              $("#DC-interface-content").append('<b>کرا!</b><br>وتووێژ دەبسرێت...');
              var bottom;
              if (template === 'atop' || template === 'atopr' || template === 'atopy' || template === 'atopg') {
                bottom = "{{بنی ئەرشیڤ}}";
              }
              else if (template === 'hat') {
                bottom = "{{hab}}";
              }
              else {
                bottom = "{{closed rfc bottom}}";
              }
            	if (!Morebits.userIsInGroup('sysop')) {
			    	comment += ' {{nac}}';
				}
				$.get(mw.config.get("wgScriptPath")+"/api.php", request, function(response){
					if (template === 'rfc') {
						template = "closed rfc top";
					}
                var contentSection = '\r\r' + $(response).find('rev').text();
                var discussiontext = contentSection.substring(contentSection.substring(3,contentSection.length).indexOf('\n')+3, contentSection.length);
                var title = contentSection.substring(2, contentSection.length - discussiontext.length);
								var wikitext = title + '\n{{'+template+'\n| status = '+status+'\n| result = '+comment+'\n}}'+discussiontext+'\n'+bottom;
								var sectiontitle = title.replace('===', '').replace('===', '').replace('\n', '').replace('/r','').trim();
								var sectiontitle2 = sectiontitle.replace(/ /g, '_');
								if (template === "closed rfc top") {
									wikitext = wikitext.replace(/(\r|\n)?{{rfc[^\}]*}}/g, '').replace(/(\r|\n)?<!--\s\[\[User:DoNotArchiveUntil\]\][^->]*-->{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, '');
								}
								var request2 = {
									action:"edit", 
									section: section, 
									title: mw.config.get('wgPageName'), 
									text: wikitext,
									summary: '/* '+sectiontitle+' */ '+editsummary+' (داخەری وتووێژ)',
									token: mw.user.tokens.get("csrfToken")
								};
								if (contentSection.includes('{{سەری ئەرشیڤ')||contentSection.includes('{{atopr')||contentSection.includes('{{atopg')||contentSection.includes('{{atopy')||contentSection.includes('{{hat')||contentSection.includes('{{بنی ئەرشیڤ')||contentSection.includes('{{archive')||contentSection.includes('{{Rfctop')||contentSection.includes('{{rfctop')||contentSection.includes('{{Atop')||contentSection.includes('{{Atopr')||contentSection.includes('{{Atopy')||contentSection.includes('{{Atopg')||contentSection.includes('{{بنی ئەرشیڤ')||contentSection.includes('{{Rfc bottom')||contentSection.includes('{{Archive bottom')||contentSection.includes('{{archive bottom')||contentSection.includes('{{hidden archive bottom')||contentSection.includes('{{Hidden archive bottom')) {
									var cont = confirm('لەوانەیە ئەم وتووێژە لەپێشدا بەسراو بێت. دەتەوێت بەردەوام بیت؟');
									if (!cont) {
										$("#DC-interface-content").append('<b>بەکارهێنەر پاشگەزبۆوە</b><br><b>سەرکەوتوو بوو!</b>');
										$('#DC-interface-footer').append(
											$('<button>').attr('id', 'DC-close').text('Close')
										);
										$('#DC-close').click(function() {
										$('#DC-modal').remove();
											window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
											window.location.reload();
										});
									}
									else {
									$.when(
					                  $.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response2){
					                    
					                  }).done(function() {
									 $("#DC-interface-content").append('<b>کرا!</b><br><b>سەرکەوتوو بوو!</b>');
									 $('#DC-interface-footer').append(
										$('<button>').attr('id', 'DC-close').text('Close')
									);
									$('#DC-close').click(function() {
										$('#DC-modal').remove();
										window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
										window.location.reload();
									});
								 }));
									}
								}
								else {
                $.when(
                  $.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response2){
                    
                  }).done(function() {
									 $("#DC-interface-content").append('<b>کرا!</b><br><b>سەرکەوتوو بوو!</b>');
									 $('#DC-interface-footer').append(
										$('<button>').attr('id', 'DC-close').text('Close')
									);
									$('#DC-close').click(function() {
										$('#DC-modal').remove();
										window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
										window.location.reload();
									});
								 }));
								}
							});
						});
					});
				}
				if ($(this).parent().prop("tagName") == 'H4') {
					$(this).parent('h4').append(' <div style="font-size:.6em;font-weight:bold;float:left"> | <a id="' + section + 
						'" class="closeLink">' + 'داخستن' + '</a></div>');
					$(this).parent('h4').find('a.closeLink').click(function(){
						$('body').prepend('<div id="DC-modal">'+
					    '<div id="DC-interface">'+
					      '<h4 id="DC-interface-header"></h4>'+
					      '<hr>'+
					      '<div id="DC-interface-content"></div>'+
					      '<hr>'+
					      '<div id="DC-interface-footer"></div>'+
					    '</div>'+
					  '</div>');
					  $("#DC-modal").css({
					    "position": "fixed",
					    "z-index": "1",
					    "right": "0",
					    "top": "0",
					    "width": "100%",
					    "height": "100%",
					    "overflow": "hidden",
					    "background-color": "rgba(0,0,0,0.4)"
					  });
					  $("#DC-interface").css({
					    "background-color": "#d6d6d6",
					    "margin": "10% auto",
					    "padding": "2px 20px",
					    "border": "1px solid #888",
					    "width": "80%",
					    "max-width": "60em",
					    "font-size": "90%"
					  });
					  $("#DC-interface-content").css({
					    "min-height": "7em",
					    "width" : "875px",
					    "height" : "400px",
					    "overflow-y": "scroll"
					  });
					  $("#DC-interface-footor").css("min-height", "3em");
						$("#DC-interface-header, #DC-interface-content, #DC-interface-footer").empty();
						$("#DC-interface-header").text("Discussion Closer");
						$("#DC-interface-content").append(
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').attr({'id':'DC-label'}).text('Options: '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio1','value':'atop','checked':'true','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (شین) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio2','value':'atopg','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (سەوز) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio3','value':'atopy','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (زەرد) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio4','value':'atopr','onchange':'dc_radio(1)'}),
						    $('<label>').text('سادە (سوور) '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'rfc','onchange':'dc_radio(2)'}),
						    $('<label>').text('داواکردنی لێدوان '),
						    $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'hat','onchange':'dc_radio(2)'}),
						    $('<label>').text('ئەرشیڤی شاردراوە ')
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').text('Status (optional): '),
						    $('<input>').attr({'type':'text','name':'DC-e','id':'DC-e'})
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
						    $('<label>').text('لێدوانی داخستن:'),
						    $('<textarea>').css({'resize':'none'}).attr({'name':'DC-com','id':'DC-com','rows':'17','cols':'30'})
						  ),
						  $('<div>').css('margin-bottom','0.5em').append(
								$('<label>').text('کورتەی دەستکاری: '),
						    $('<input>').attr({'type':'text','name':'DC-es','id':'DC-es'})
							),
							$('<div>').css('margin-bottom','0.5em').attr('id','DC-prevt'),
							$('<div>').css('margin-bottom','0.5em').attr('id','DC-prevdiv'),
							$('<button>').attr('id', 'DC-closeprev').text('داخستنی پێشبینین').hide()
						);
						$("#DC-interface-footer").append(
							$('<button>').attr({'name':'DC-done', 'id':'DC-done'}).text('داخستنی وتووێژ'),
							$('<button>').attr({'name':'DC-prev', 'id':'DC-prev'}).text('پێشبینین'),
							$('<button>').attr('id', 'DC-cancel').text('پاشگەزبوونەوە'),
							$('<label>').attr('id','DC-loading').text(' پێشبینین بار دەکرێت').hide()
						);
						document.getElementById("DC-modal").addEventListener( "keydown", function ( key ) {
				        	if( key.ctrlKey && ( key.keyCode == 10 || key.keyCode == 13 ) ) {
				            	document.getElementById("DC-done").click();
				            }
				            else if ( key.keyCode == 27 ){
				            	document.getElementById("DC-cancel").click();
				            }
			        	});
						$('#DC-cancel').click(function() {
						  $('#DC-modal').remove();
						});
						$('#DC-prev').click(function() {
							$('#DC-loading').show();
							var template = $("input[name=DC-radio]:checked").val();
							var status = $('#DC-e').val();
							var comment = $('#DC-com').val();
							var request = {
								action:"query", 
								titles: mw.config.get('wgPageName'), 
								rvsection: section,
								prop: "revisions|info", 
								intoken: "edit", 
								rvprop: "content",
								indexpageids: 1,
								dataType: "xml",
								format: "xml"
							};
							var bottom;
							if (template === 'atop' || template === 'atopr' || template === 'atopy' || template === 'atopg') {
								bottom = "{{بنی ئەرشیڤ}}";
							  }
							  else if (template === 'hat') {
								bottom = "{{hab}}";
							  }
							  else {
								bottom = "{{closed rfc bottom}}";
							  }
								if (!Morebits.userIsInGroup('sysop')) {
									comment += ' {{nac}}';
								}
								$.get(mw.config.get("wgScriptPath")+"/api.php", request, function(response){
									if (template === 'rfc') {
										template = "closed rfc top";
									}
								var contentSection = '\r\r' + $(response).find('rev').text();
								var discussiontext = contentSection.substring(contentSection.substring(3,contentSection.length).indexOf('\n')+3, contentSection.length);
								var title = contentSection.substring(2, contentSection.length - discussiontext.length);
												var wikitext = title + '\n{{'+template+'\n| status = '+status+'\n| result = '+comment+'\n}}'+discussiontext+'\n'+bottom;
												var sectiontitle = title.replace('====', '').replace('====', '').replace('\n', '').replace('/r','').trim();
												var sectiontitle2 = sectiontitle.replace(/ /g, '_');
												if (template === "closed rfc top") {
													wikitext = wikitext.replace(/(\r|\n)?{{rfc[^\}]*}}/g, '').replace(/(\r|\n)?<!--\s\[\[User:DoNotArchiveUntil\]\][^->]*-->{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, '');
												}
								jQuery.ajax({
									url:mw.util.wikiScript('api'),
									dataType:'json',
									type:'POST',
									data:{
											format:'json',
											action:'parse',
											pst:1,
											text:wikitext,
											title:mw.config.get('wgPageName'),
											prop:'text'
									}
								}).done(function(r) {
									if(!r.parse || !r.parse.text || !r.parse.text['*']){
										alert('کیشە هەیە لە پێشبینین.');
									}
									$('#DC-loading').hide();
									$('#DC-prevt').html('<hr>پێشبینین:<br>');
									$('#DC-prevdiv').html(r.parse.text['*']+'<br />').css({'display':'block','background-color':'white'});
									$('#DC-closeprev').show();
									$('#DC-closeprev').click(function() {
										$('#DC-prevt').empty();
										$('#DC-prevdiv').empty().css({'display':'','background-color':'','border-color':'',"border-width":"", "border-style":""});
										$('#DC-closeprev').hide();
									});
								});
							});
						});
						$('#DC-done').click(function() {
							var template = $("input[name=DC-radio]:checked").val();
							var status = $('#DC-e').val();
							var editsummary = $('#DC-es').val();
							if (editsummary === "") {
								editsummary = "Closing discussion";
							}
							var comment = $('#DC-com').val();
							$('#DC-done').remove();
							$('#DC-prev').remove();
							$('#DC-cancel').remove();
            				$('#DC-interface-content').empty();
            				$("#DC-interface-content").text('Retrieving information...');
							var request = {
								action:"query", 
								titles: mw.config.get('wgPageName'), 
								rvsection: section,
								prop: "revisions|info", 
								intoken: "edit", 
								rvprop: "content",
								indexpageids: 1,
								dataType: "xml",
								format: "xml"
              };
              $("#DC-interface-content").append('<b>کرا!</b><br>وتووێژ دەبەسرێت...');
              var bottom;
              if (template === 'atop' || template === 'atopr' || template === 'atopy' || template === 'atopg') {
                bottom = "{{بنی ئەرشیڤ}}";
              }
              else if (template === 'hat') {
                bottom = "{{hab}}";
              }
              else {
                bottom = "{{closed rfc bottom}}";
              }
            	if (!Morebits.userIsInGroup('sysop')) {
			    	comment += ' {{nac}}';
				}
				$.get(mw.config.get("wgScriptPath")+"/api.php", request, function(response){
					if (template === 'rfc') {
						template = "closed rfc top";
					}
                var contentSection = '\r\r' + $(response).find('rev').text();
                var discussiontext = contentSection.substring(contentSection.substring(3,contentSection.length).indexOf('\n')+3, contentSection.length);
                var title = contentSection.substring(2, contentSection.length - discussiontext.length);
								var wikitext = title + '\n{{'+template+'\n| status = '+status+'\n| result = '+comment+'\n}}'+discussiontext+'\n'+bottom;
								var sectiontitle = title.replace('====', '').replace('====', '').replace('\n', '').replace('/r','').trim();
								var sectiontitle2 = sectiontitle.replace(/ /g, '_');
								if (template === "closed rfc top") {
									wikitext = wikitext.replace(/(\r|\n)?{{rfc[^\}]*}}/g, '').replace(/(\r|\n)?<!--\s\[\[User:DoNotArchiveUntil\]\][^->]*-->{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, '');
								}
								var request2 = {
									action:"edit", 
									section: section, 
									title: mw.config.get('wgPageName'), 
									text: wikitext,
									summary: '/* '+sectiontitle+' */ '+editsummary+' (داخەری وتووێژ)',
									token: mw.user.tokens.get("csrfToken")
								};
								if (contentSection.includes('{{سەری ئەرشیڤ')||contentSection.includes('{{atopr')||contentSection.includes('{{atopg')||contentSection.includes('{{atopy')||contentSection.includes('{{hat')||contentSection.includes('{{بنی ئەرشیڤ')||contentSection.includes('{{archive')||contentSection.includes('{{Rfctop')||contentSection.includes('{{rfctop')||contentSection.includes('{{سەری ئەرشیڤ')||contentSection.includes('{{Atopr')||contentSection.includes('{{Atopy')||contentSection.includes('{{Atopg')||contentSection.includes('{{بنی ئەرشیڤ')||contentSection.includes('{{Rfc bottom')||contentSection.includes('{{Archive bottom')||contentSection.includes('{{archive bottom')||contentSection.includes('{{hidden archive bottom')||contentSection.includes('{{Hidden archive bottom')) {
									var cont = confirm('The discussion may have already been closed. Continue?');
									if (!cont) {
										$("#DC-interface-content").append('<b>Aborted by user</b><br><b>Finished!</b>');
										$('#DC-interface-footer').append(
											$('<button>').attr('id', 'DC-close').text('Close')
										);
										$('#DC-close').click(function() {
										$('#DC-modal').remove();
											window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
											window.location.reload();
										});
									}
									else {
									$.when(
					                  $.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response2){
					                    
					                  }).done(function() {
									 $("#DC-interface-content").append('<b>کرا!</b><br><b>سەرکەوتوو بوو!</b>');
									 $('#DC-interface-footer').append(
										$('<button>').attr('id', 'DC-close').text('Close')
									);
									$('#DC-close').click(function() {
										$('#DC-modal').remove();
										window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
										window.location.reload();
									});
								 }));
									}
								}
								else {
                $.when(
                  $.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response2){
                    
                  }).done(function() {
									 $("#DC-interface-content").append('<b>کرا!</b><br><b>سەرکەوتوو بوو!</b>');
									 $('#DC-interface-footer').append(
										$('<button>').attr('id', 'DC-close').text('داخستن')
									);
									$('#DC-close').click(function() {
										$('#DC-modal').remove();
										window.location.href = 'https://ckb.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
										window.location.reload();
									});
								 }));
								}
							});
						});
					});
				}
			}
	});
}
}
function dc_radio(i) {
	if (i == 1) {
		$('#DC-e').prop('disabled', false);
		$('#DC-e').val("");
	}
	if (i == 2) {
		$('#DC-e').prop('disabled', true);
		$('#DC-e').val('Not available');
	}
}
mw.loader.using(['ext.gadget.Twinkle', 'mediawiki.util', 'mediawiki.api', 'mediawiki.Title'], function() {
	dc_init();
});
//</nowiki>