User:The Earwig/afc-helper.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
jquery not needed. is default on now. use importScript
jquery not needed. is default on now. use importScript
Line 27: Line 27:


function afc_helper() {
function afc_helper() {
jQuery.noConflict();
$.noConflict();
if (auto_mod()) { return; }
if (auto_mod()) { return; }
var requests = jQuery(".mw-headline").filter(function(){ return this.childNodes[0].nodeValue == "Redirect request: " && !/\/wiki\//.test(this.childNodes[1].href); });
var requests = $(".mw-headline").filter(function(){ return this.childNodes[0].nodeValue == "Redirect request: " && !/\/wiki\//.test(this.childNodes[1].href); });
requests.each(function(){
requests.each(function(){
var edit = jQuery(this).prev();
var edit = $(this).prev();
jQuery.each(afch_accepts, function(k, v){ edit.append('[<a href="#" style="background-color: #A0FFA0;" class="afch_accepts">' + k + '</a>]'); });
$.each(afch_accepts, function(k, v){ edit.append('[<a href="#" style="background-color: #A0FFA0;" class="afch_accepts">' + k + '</a>]'); });
jQuery.each(afch_declines, function(k, v){ edit.append('[<a href="#" style="background-color: #ffcece;" class="afch_declines">' + k + '</a>]'); });
$.each(afch_declines, function(k, v){ edit.append('[<a href="#" style="background-color: #ffcece;" class="afch_declines">' + k + '</a>]'); });
jQuery.each(afch_comments, function(k, v){ edit.append('[<a href="#" style="background-color: #ffec83;" class="afch_comments">' + k + '</a>]'); });
$.each(afch_comments, function(k, v){ edit.append('[<a href="#" style="background-color: #ffec83;" class="afch_comments">' + k + '</a>]'); });
});
});
jQuery(".afch_accepts").click(function(){
$(".afch_accepts").click(function(){
var that = this;
var that = this;
jQuery.terabox('<form id="afch_form">' +
$.terabox('<form id="afch_form">' +
'<b>Please select a redirect template to use:</b><br/>' +
'<b>Please select a redirect template to use:</b><br/>' +
'<input type="radio" name="afch_rg" value="%7B%7BR+from+alternate+name%7D%7D"> {{<a href="http://en.wikipedia.org/wiki/Template:R_from_alternative_name" target="_blank">R from alternative name</a>}}<br>' +
'<input type="radio" name="afch_rg" value="%7B%7BR+from+alternate+name%7D%7D"> {{<a href="http://en.wikipedia.org/wiki/Template:R_from_alternative_name" target="_blank">R from alternative name</a>}}<br>' +
Line 53: Line 53:
'<input type="submit" value="Submit">' +
'<input type="submit" value="Submit">' +
'</form>');
'</form>');
jQuery("#afch_form").submit(function(){
$("#afch_form").submit(function(){
var radio = jQuery(":radio:checked", this);
var radio = $(":radio:checked", this);
if (radio.val() == "other") {
if (radio.val() == "other") {
radio.val(jQuery(":text", this).val());
radio.val($(":text", this).val());
}
}
afc_vote(that.parentNode.nextSibling.nextSibling, that.innerHTML, afch_accepts[that.innerHTML], "accept", radio.val());
afc_vote(that.parentNode.nextSibling.nextSibling, that.innerHTML, afch_accepts[that.innerHTML], "accept", radio.val());
Line 63: Line 63:
return false;
return false;
});
});
jQuery(".afch_declines").click(function(){
$(".afch_declines").click(function(){
afc_vote(this.parentNode.nextSibling.nextSibling, this.innerHTML, "decline - " + afch_declines[this.innerHTML], "");
afc_vote(this.parentNode.nextSibling.nextSibling, this.innerHTML, "decline - " + afch_declines[this.innerHTML], "");
return false;
return false;
});
});
jQuery(".afch_comments").click(function(){
$(".afch_comments").click(function(){
afc_vote(this.parentNode.nextSibling.nextSibling, this.innerHTML, afch_comments[this.innerHTML], "comment");
afc_vote(this.parentNode.nextSibling.nextSibling, this.innerHTML, afch_comments[this.innerHTML], "comment");
return false;
return false;

Revision as of 08:42, 10 October 2011

// The Articles for Creation Helper
// v1.4
//
// Originally written by [[User:Henrik]] at http://en.wikipedia.org/wiki/User:Henrik/js/afc-helper.js
// Revised by [[User:The Earwig]] and [[User:MindstormsKid]].
// *** DOCUMENTATION: please read; includes installation instructions: *** http://en.wikipedia.org/wiki/User_talk:The_Earwig/afc-helper.js
// See http://en.wikipedia.org/wiki/Wikipedia:Articles_for_creation
//
// <pre><nowiki>
 
importScript("User:Henrik/js/automod.js");
importScript("User:MindstormsKid/terabox.js");

afch_accepts = {
	accept: "accepted",
	change: "accepted at with a different title or target",
	reason: "accepted with custom reason"
};
afch_declines = {
	exists: "already exists",
	blank: "blank request",
	notarget: "target article does not exist, or was not specified", 
	unlikely: "unlikely search term, or source needed",
	reason: "custom reason"
};
afch_comments = { comment: "adding a comment" };

function afc_helper() {
	$.noConflict();
	if (auto_mod()) { return; }
	
	var requests = $(".mw-headline").filter(function(){ return this.childNodes[0].nodeValue == "Redirect request: " && !/\/wiki\//.test(this.childNodes[1].href); });
	
	requests.each(function(){
		var edit = $(this).prev();
		$.each(afch_accepts, function(k, v){ edit.append('[<a href="#" style="background-color: #A0FFA0;" class="afch_accepts">' + k + '</a>]'); });
		$.each(afch_declines, function(k, v){ edit.append('[<a href="#" style="background-color: #ffcece;" class="afch_declines">' + k + '</a>]'); });
		$.each(afch_comments, function(k, v){ edit.append('[<a href="#" style="background-color: #ffec83;" class="afch_comments">' + k + '</a>]'); });
	});
	
	$(".afch_accepts").click(function(){
		var that = this;
	$.terabox('<form id="afch_form">' +
                        '<b>Please select a redirect template to use:</b><br/>' +
			'<input type="radio" name="afch_rg" value="%7B%7BR+from+alternate+name%7D%7D"> {{<a href="http://en.wikipedia.org/wiki/Template:R_from_alternative_name" target="_blank">R from alternative name</a>}}<br>' +
			'<input type="radio" name="afch_rg" value="%7B%7BR+from+alternative+language%7D%7D"> {{<a href="http://en.wikipedia.org/wiki/Template:R_from_alternative_language" target="_blank">R from alternative language</a>}}<br>' +
			'<input type="radio" name="afch_rg" value="%7B%7BR+from+alternative+spelling%7D%7D"> {{<a href="http://en.wikipedia.org/wiki/Template:R_from_alternative_spelling" target="_blank">R from alternative spelling</a>}}<br>' +
			'<input type="radio" name="afch_rg" value="%7B%7BR+to+section%7D%7D"> {{<a href="http://en.wikipedia.org/wiki/Template:R_to_section" target="_blank">R to section</a>}}<br>' +
			'<input type="radio" name="afch_rg" value="%7B%7BR+to+disambiguation+page%7D%7D"> {{<a href="http://en.wikipedia.org/wiki/Template:R_to_disambiguation_page" target="_blank">R to disambiguation page</a>}}<br>' +
			'<input type="radio" name="afch_rg" value="%7B%7BR+from+title+with+diacratics%7D%7D"> {{<a href="http://en.wikipedia.org/wiki/Template:R_from_title_with_diacratics" target="_blank">R from title with diacritics</a>}}<br>' +
			'<input type="radio" name="afch_rg" value="other"> Custom: <input type="text"><br>' +
			'<input type="radio" name="afch_rg" value="" checked> None<br>' +
			'<input type="submit" value="Submit">' +
		'</form>');
		$("#afch_form").submit(function(){
			var radio = $(":radio:checked", this);
			if (radio.val() == "other") {
				radio.val($(":text", this).val());
			}
			afc_vote(that.parentNode.nextSibling.nextSibling, that.innerHTML, afch_accepts[that.innerHTML], "accept", radio.val());
			return false;
		});
		return false;
	});
	$(".afch_declines").click(function(){
		afc_vote(this.parentNode.nextSibling.nextSibling, this.innerHTML, "decline - " + afch_declines[this.innerHTML], "");
		return false;
	});
	$(".afch_comments").click(function(){
		afc_vote(this.parentNode.nextSibling.nextSibling, this.innerHTML, afch_comments[this.innerHTML], "comment");
		return false;
	});
}

function afc_vote(title, type, reason, action, redirType) {
	var comments, type2 = type, edit_link = title.parentNode.childNodes[0].childNodes[1].href, topMethod, redirType;
	
	var redirOrigin = title.childNodes[1].innerHTML, redirTarget = title.parentNode.nextSibling.nextSibling.childNodes[1];
        if (redirTarget) { redirTarget = redirTarget.innerHTML; }
	
	if (type == "comment") { type2 = window.prompt("Comment:"); }
	
	if (type == "reason" && action == "accept") {
		comments = window.prompt("Reason for accepting:");
		type2 = "accept|" + comments;
	}
	
	if (type == "change") {
		type2 = window.prompt("Please specify the name of the redirect page.");
		redirOrigin = type2;
		redirTarget = window.prompt("Please specify the name of the page that the redirect points to.");
	}
	
	if (type == "accept") {
		type2 = "";
	}
	
	if (type == "reason" && action == "") {
		comments = window.prompt("Reason for declining:");
		type2 = "decline|" + comments;
	}
	
	if (action == "accept" && (!redirOrigin || !redirTarget)) { return; }
	if (action == "comment" && !type2) { return; }
	if (action == "" && type == "reason" && !comments) { return; }

	if (action == "accept") {
		topMethod = "a";
	} else if (action == "") {
		topMethod = "d";
	}
	
	if (action != "comment") {
		var url = edit_link
			+ '&amfind=' + escape("==(.*)==")
			+ '&amreplace=' + escape('$0\n{{AfC-c|' + topMethod + '}}')
			+ '&amlocal=1'
			+ '&amaddafter=' + escape("\n{{subst:afc redirect|" + type2 + "}} ~~" + "~~\n" + "{{subst:afc b}}")
			+ '&amsummary=' + escape(reason)
			+ '&amautosave=yes';
	} else {
		var url = edit_link
			+ '&amfind=' + escape("==(.*)==")
			+ '&amreplace=' + escape('$0')
			+ '&amlocal=1'
			+ '&amaddafter=' + escape("\n:{{afc comment|1=" + type2 + "}} ~~" + "~~")
			+ '&amsummary=' + escape(reason)
			+ '&amautosave=yes';
	}
	
	if (action == "accept") {
		var url2 = "http://en.wikipedia.org/w/index.php?title=" + escape(redirOrigin)
			+ "&action=edit&amsummary=Created+via+%5B%5BWP:AFC%7CArticles+for+Creation%5D%5D.+%5B%5BWP:AFC%2FR%7CYou+can+help%21%5D%5D&amfind=.*&amlocal=1&amreplace=%23REDIRECT+%5B%5B"
			+ escape(redirTarget) + "%5D%5D+" + redirType + "&amautosave=yes";
		var url3 = "http://en.wikipedia.org/w/index.php?title=Talk:" + escape(redirOrigin)
			+ "&action=edit&amsummary=%7B%7Bsubst%3AWPAFC%2Fredirect%7D%7D&amfind=.*&amlocal=1&amreplace=%7B%7Bsubst%3AWPAFC%2Fredirect%7D%7D&amautosave=yes";
		window.open(url2, "afd_helper_vote2");
		window.open(url3, "afd_helper_vote3");
	}
	
	window.location.href = url;
}

addOnloadHook(afc_helper);
 
// </nowiki></pre>