MediaWiki:Gadget-DeletionHelper.js

/** * DeletionHelper.js  * uses jQuery & Ajax * helps sysops (and not) on FAMEData with DRs */ $(function{	if((mw.config.get( 'wgPageName' )!="FAMEData:Requests_for_deletions"&&mw.config.get( 'wgPageName' )!="FAMEData:Requests_for_deletions/all")||mw.config.get( 'wgAction' )=="view") return;	// the page is 'FAMEData:Request for deletions' in 'view' mode	$("h2 .mw-headline").not(":has(a.new)")// items not already deleted	.each(function(i,e){ var entityId=$(e).text; $.getJSON(			mw.util.wikiScript("api"),			{				format:"json",				action:"wbgetentities",				ids:$(e).text			},			function(data){				if(data.success&&data.entities[Object.keys(data.entities)[0]]){					var entity=data.entities[Object.keys(data.entities)[0]];					var length=0;					if(typeof(entity.sitelinks)=="object") length=Object.keys(entity.sitelinks).length;					if(length===0) $(e).children("a").first.css("color","teal");					$(" ")					.html(" ("+(length>0?length+" sitelink"+(length>1?"s":""):"empty")+")")					.css("font-size","50%")					.appendTo(e);				}			}		); $.getJSON(			mw.util.wikiScript("api"),			{				action:"query",				format:"json",				prop:"revisions",				titles:entityId,				rvprop:"content|user|ids",				rvlimit:"max"			},			function(data){				try {					var pages = data.query.pages;					pages = pages[Object.keys(pages)[0]].revisions;					pages.length;				} catch(e) {					// Give up silently					return;				}				var remL={};				$.each(pages,function(y,z){ var links=Object.keys(JSON.parse(z["*"]).links); if(y0){ var rl={revid:z.revid,parentid:z.parentid,links:removedLinks}; if(typeof(remL[z.user])!="undefined") remL[z.user].push(rl); else remL[z.user]=[rl]; }					}				});				var p=$(" ").css("color","#630");// change color, according to Reza1615				if(Object.keys(remL).length===0) p.append("No sitelinks were removed");				else $.each(remL,function(k,v){ p.append("Removed "); var abcd=false; $.each(v,function(o,j){						p.append( $("") .text(j.links.join(", ")) .attr("href",								mw.util.wikiScript+"?"+								$.param({ title:entityId, oldid:j.parentid, diff:j.revid })							)						);						if(o")						.text(k)						.attr("href",mw.util.getUrl("User:"+k))					); });				$(e).parent.next("p").find("span.plainlinks").first// (delete | history | links | log)				.after(p);			}		); });	$("li").not(":has(a.new)")// items not already deleted	.each(function(i,e){ if(/[Qq](\d*) \(delete \| history \| links \| log\)/.test($(e).text) === true){ var entityId=$(e).text.replace(/(.*) \(delete \| history \| links \| log\)/,"$1"); $.getJSON(				mw.util.wikiScript("api"),				{					format:"json",					action:"wbgetentities",					ids:entityId				},				function(data){					if(data.success&&data.entities[Object.keys(data.entities)[0]]){						var entity=data.entities[Object.keys(data.entities)[0]];						var length=0;						if(typeof(entity.sitelinks)=="object") length=Object.keys(entity.sitelinks).length;						if(length===0) $(e).children("a").first.css("color","teal");						$(" ")						.html(" ("+(length>0?length+" sitelink"+(length>1?"s":""):"empty")+")")						.css("font-size","70%")						.css("vertical-align","middle")						.appendTo(e);					}				}			); }	});	var work = [];	$("h2>span.mw-editsection").each(function(i,e){ var index=parseInt($(e).children("a").first.attr("href").replace(/^.+[\?&]section=(T\-)?([0-9]+)$/,"$2")); $(e).parent.attr("id","section"+index); work[index] = false; $.get(			mw.util.wikiScript,			{title:"FAMEData:Requests_for_deletions",action:"raw",section:index}		) .done(function(d){			if(/\{\{([Nn]ot )?[Dd](eleted|one)(\|admin=[^\{\}]+)?\}\}/.test(d)===false){				$("")				.html(" Yes ")				.attr("href", "javascript:;")				.attr("title","Mark as deleted")				.attr("style",'background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAWCAMAAAA2GAaYAAAAQlBMVEUpflI7tXYxl2MujVwqgFQ1omk2pWwoeU8vkF4sh1gwlGA5rnI7s3Uzm2U3qG4oe1A0n2c4q3AtilovfVUrg1Y6sXPiEyGEAAAAKElEQVR4XgXAhQ2AMAAAsM4Ft/9fJYLVZ3HZVcVpE01dchteGYfm+QEULwDomj1/qwAAAABJRU5ErkJggg==") repeat-x scroll 50% 100% #3365BA !important; color: white; float: right; font-size: 0.7em; padding: 1px; position: relative; bottom: 12px; border-radius: 0px 0px 0px 6px;border-bottom:1px solid black;border-left:1px solid black;text-decoration:none;')				.click(function(event){ location.hash = "#" + $(e).siblings(".mw-headline").first.attr("id"); event.preventDefault; send("FAMEData:Requests_for_deletions",index,e,d,"","d"); })				.insertAfter($(e).parent)				.tipsy({ gravity: 'ne', fade: true });				$("")				.html(" No ")				.attr("href", "javascript:;")				.attr("title","Mark as not deleted")				.attr("style",'Background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAWCAMAAAA2GAaYAAAAQlBMVEWUAACeAACIAADIAACQAACKAACaAADDAAC8AACxAACFAADFAADAAACuAACXAACqAACmAAC5AACiAACNAADKAAC1AAB6LXXpAAAAKElEQVR4XgXAhQ2AMAAAsM4Ft/9fJV7Joll1l8+wOZxuQbUjexTR/AEV+QDoUwTrkQAAAABJRU5ErkJggg==") repeat-x scroll 50% 100% #CB0000 !important; color: white; float: right; font-size: 0.7em; padding: 1px; position: relative; bottom: 12px;border-bottom:1px solid black;text-decoration:none;')				.click(function(event){ if(/^.*#.*$/.test(document.location) === false){ document.location = document.location + "#" + $(e).siblings(".mw-headline").first.attr("id");} location.hash = "#" + $(e).siblings(".mw-headline").first.attr("id"); event.preventDefault; send("FAMEData:Requests_for_deletions",index,e,d,"","n"); })				.insertAfter($(e).parent)				.tipsy({ gravity: 'ne', fade: true });				$("")				.html(" # ")				.attr("href", "javascript:;")				.attr("title","Write a comment")				.attr("style",'background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAWCAMAAAA2GAaYAAAAQlBMVEUuXKkmS4ozZbkkSIQtW6YiRHwrV58hQ3owYLAxY7UnTY0jRoEqVZsyZLcvXq0oT5EqU5gxYbMsWaMlSocjRX8pUZU8hDFrAAAAKElEQVR4XgXAhQ2AMAAAsM4Ft/9fJaLNcOl2ZLdqdfocpuCRLF5F+wETiQDocXjMfwAAAABJRU5ErkJggg==") repeat-x scroll 50% 100% #3365BA !important; color: white; float: right; font-size: 0.7em; padding: 1px; position: relative; bottom: 12px; border-radius: 0px 0px 6px 0px;border-bottom:1px solid black;border-right:1px solid black;text-decoration:none;')				.click(function(event){ if(/^.*#.*$/.test(document.location) === false){ document.location = document.location + "#" + $(e).siblings(".mw-headline").first.attr("id");} location.hash = "#" + $(e).siblings(".mw-headline").first.attr("id"); event.preventDefault; var c = prompt("Type the text to send to this request:\n\n* If you want to set a template\n  TEMPLATE|option1|option2#My Text\n\n* If you want to indent the text, add a colon at the beginning of the text\n   :TEMPLATE#My Text          :My Text\n\n* If you leave the template option blank, it will set the default template (deleted or not deleted)\n   #My Text                            :#My Text"); if(c)send("FAMEData:Requests_for_deletions",index,e,d,c,"c"); })				.insertAfter($(e).parent)				.tipsy({ gravity: 'ne', fade: true });			}else{				$("")				.html(" # ")				.attr("href", "javascript:;")				.attr("title","Write a comment")				.attr("style",'background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAWCAMAAAA2GAaYAAAAQlBMVEUuXKkmS4ozZbkkSIQtW6YiRHwrV58hQ3owYLAxY7UnTY0jRoEqVZsyZLcvXq0oT5EqU5gxYbMsWaMlSocjRX8pUZU8hDFrAAAAKElEQVR4XgXAhQ2AMAAAsM4Ft/9fJaLNcOl2ZLdqdfocpuCRLF5F+wETiQDocXjMfwAAAABJRU5ErkJggg==") repeat-x scroll 50% 100% #3365BA !important; color: white; float: right; font-size: 0.7em; padding: 1px; position: relative; bottom: 12px; border-radius: 0px 0px 6px 6px;border-bottom:1px solid black;border-right:1px solid black;border-left:1px solid black;text-decoration:none;')				.click(function(event){ if(/^.*#.*$/.test(document.location) === false){ document.location = document.location + "#" + $(e).siblings(".mw-headline").first.attr("id");} location.hash = "#" + $(e).siblings(".mw-headline").first.attr("id"); event.preventDefault; send("FAMEData:Requests_for_deletions",index,e,d,prompt("Type the text to send to this request:\n\n* If you want to set a template\n  TEMPLATE|option1|option2#My Text\n\n* If you want to indent the text, add a colon at the beginning of the text\n   :TEMPLATE#My Text          :My Text\n\n* If you leave the template option blank, it will set the default template (deleted or not deleted)\n   #My Text                            :#My Text"),"c"); })				.insertAfter($(e).parent)				.tipsy({ gravity: 'ne', fade: true });			}		});	});	function send(pageName,index,e,d,c,m){		//CREATE SPINNER		var spinner = ' '; var nextindex = index+1;		if(document.getElementById("section"+nextindex) == null){			$("#mw-content-text").append(spinner);		}else{			$("#section"+nextindex).before(spinner);		}		$.createSpinner( { size: 'small', id: 'rfdSpinner'+index } ).appendTo( "#rfdSpinner"+index );		//CREATE SPINNER		work[index] = true;		if( /==\s*\[\[(.*)\]\]\s*==/.test(d) === true ){			var title = d.match(/==.*==/)[0].replace(/^==\s*\[\[(.*)\]\]\s*==/,"$1");			if(m == "d"){var template = "Deleted";var resume = "deleted";}			if(m == "n"){var template = "Not deleted";var resume = "not deleted";}			$.ajax({ url: mw.util.wikiScript( 'api' ), async: false, type: 'GET', dataType: 'json', data: { action: 'query', format: 'json', list: 'logevents', leprop: 'type|user', letitle: title, lelimit: '1' },				success: function ( data ) { if(data.query.logevents.hasOwnProperty(0)){ if(data.query.logevents[0].action == "delete"){ if(m == "d"){ if(data.query.logevents[0].user != mw.config.get( 'wgUserName' )){ if(confirm("We have detected that this page has been deleted by :\n\n\t" + data.query.logevents[0].user + "\n\nIs it correct ?")){ template = "deleted|admin=" + data.query.logevents[0].user; resume = "deleted by " + data.query.logevents[0].user; }								}							}else if(m == "n"){ if(!confirm("This page has been deleted! Are you sure you want to mark this request as not deleted?")){ m="c";c=""; }							}else{ if(data.query.logevents[0].user == mw.config.get( 'wgUserName' )){ template = "deleted"; resume = "deleted"; }else{ if(confirm("We have detected that this page has been deleted by :\n\n\t" + data.query.logevents[0].user + "\n\nIs it correct ?")){ template = "deleted|admin=" + data.query.logevents[0].user; resume = "deleted by " + data.query.logevents[0].user; }else{ template = "deleted"; resume = "deleted"; }								}									}						}else{ if(m == "d"){ if(!confirm("This page has not been deleted! Are you sure you want to mark this request as deleted?")){ m="c";c=""; }							}else{ template = "not deleted"; resume = "not deleted"; }						}					}				}			});		}else{			if(m == "d"){var template = "Done";var resume = "done";}			if(m == "n"){var template = "Not done";var resume = "not done";}			if(m == "c"){var template = "Done";var resume = "done";}		}		if(c == null){c = "";}		if(m == "c" && c == ""){			$( "#mw-spinner-rfdSpinner"+index ).append('');			$("#rfdSpinner"+index).append(' Aborted ');			work[index] = false;			setTimeout(function{$("#rfdSpinner"+index).remove},3000);			return;		}		if( /:*(.*)#(.*)/.test(c) === true ){			if(c.replace(/^:*(.*)#(.*)$/,"$1") != ""){				var template = c.replace(/^:*(.*)#(.*)$/,"$1");				var resume = template;			}		}else if(c != ""){			template="User:Jitrixis/void";			resume = "commented";		}		point = c.replace(/^(:*).*$/,"$1")		c = c.replace(/^:*(.*#)?(.*)$/,"$2");		var n = d.match(/^:+/gm); if(point == "" && n != null){ point = n[n.length-1]; if(point.length >= 10){ var size = point.length - 1; point = ""; }		}		point = ":" + point; template = ""; if(template == ""){template = "";} //CREATE SPINNER var spinner = " " + point + " " + template + "  " + c + " --~" $("#rfdSpinner"+index).append(spinner); //CREATE SPINNER $.post(			mw.util.wikiScript("api"),			{				action:"edit",				appendtext: "\n" + point + " " + template + " " + c + " --~",				title:pageName,				section:index,				summary:"/* "+$(e).siblings(".mw-headline").first.attr("id")+" */ tagging as '" + resume + "' (DH)",				token:mw.user.tokens.get("csrfToken")			}		) .done(function(data){			if(/error/.test(data) === true){				$( "#mw-spinner-rfdSpinner"+index ).append('');				$("#rfdSpinner"+index).append(' Edit conflict detected ');			}else{				$("#rfdSpinner"+index).append(' Correctly sent ');				$( "#mw-spinner-rfdSpinner"+index ).append('');			}			work[index] = false;			setTimeout(function{rld;},2500);		}) .fail(function{			$( "#mw-spinner-rfdSpinner"+index ).append('');			$("#rfdSpinner"+index).append(' The ajax request failed. ');			work[index] = false;			setTimeout(function{rld;},2500);		}); }	function rld{ var reload = true; for(var nb in work){ if(work[nb] === true){ reload = false; }		}		if(reload === true){ document.location.reload(true); }	} }); /* */