User:SilverplateDelta/common.js

// /*	This script adds entries for posting Teahouse talkbacks and invites into the page action menu (and adds the page action menu itself, if it's not present) */ //standard onloadhook $(document).ready(teahouseMenu); //add menu if it's not there; populate it with new buttons function teahouseMenu {	if(wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk")//Only if we're on a user or user talk page {		var inviteLink = mw.util.addPortletLink("p-cactions", "#", "THInvite", "th-invite", "Add a Teahouse invite template", null, "#ca-move"); var afcLink = mw.util.addPortletLink("p-cactions", "#", "THInvite (AfC)", "th-afc", "Add a Teahouse invite template", null, "#ca-move"); var talkbackLink = mw.util.addPortletLink("p-cactions", "#", "THTalkback", "th-talkback", "Add a Teahouse talkback template", null, "#ca-move"); $(inviteLink).click(postTHInvite); $(afcLink).click(postTHafc); $(talkbackLink).click(postTHTalkback); } } function getURL {	var url; var slashLocation = wgTitle.indexOf("/"); if(slashLocation > 0) {		url = "User_talk:" + wgTitle.substring(0, wgTitle.indexOf("/")); }	else {		url = "User_talk:" + wgTitle; }	return url; } function postTHInvite {	   invitationBody = ""; //If you want to change what the invitation section is titled, edit the words below within the doublequote (but don't take out the doublequote!) invitationSectionTitle = "Welcome to Wikipedia: check out the Teahouse!"; var linkArray = document.getElementById("mw-content-text").getElementsByTagName("a"); var i;	for(i = 0; i < linkArray.length; i++) {		if(linkArray[i].href.search("Wikipedia:Teahouse") > -1) {			if(confirm("Someone may have already invited this person to the Teahouse!\n\nAre you sure you want to continue?")) {				break; }			else return; }	}

var data = { format : 'json', action : 'edit', minor : false, title : getURL, text : invitationBody, section : 'new', summary : invitationSectionTitle, token : mw.user.tokens.get('csrfToken') };	$.ajax({		url : mw.util.wikiScript('api'),		type : 'POST',		dataType : 'json',		data : data,		success : function(data) {			if(data && data.edit && data.edit.result && data.edit.result === 'Success') {				//window.location = mw.util.wikiGetlink(page);                               alert("Invitation posted!");			} else {				$("#"+id).attr("title", 'There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info).tipsy("show");			}		},		error : function {			$("#"+id).attr("title", 'There was an error using AJAX to edit the page.').tipsy("show");		}	}); }

function postTHafc {	   invitationBody = ""; //If you want to change what the invitation section is titled, edit the words below within the doublequote (but don't take out the doublequote!) invitationSectionTitle = "Welcome to Wikipedia! Need a hand?"; var linkArray = document.getElementById("mw-content-text").getElementsByTagName("a"); var i;	for(i = 0; i < linkArray.length; i++) {		if(linkArray[i].href.search("Wikipedia:Teahouse") > -1) {			if(confirm("Someone may have already invited this person to the Teahouse!\n\nAre you sure you want to continue?")) {				break; }			else return; }	}	var data = { format : 'json', action : 'edit', minor : false, title : getURL, text : invitationBody, section : 'new', summary : invitationSectionTitle, token : mw.user.tokens.get('csrfToken') };	$.ajax({		url : mw.util.wikiScript('api'),		type : 'POST',		dataType : 'json',		data : data,		success : function(data) {			if(data && data.edit && data.edit.result && data.edit.result === 'Success') {				//window.location = mw.util.wikiGetlink(page);                               alert("Invitation posted!");			} else {				$("#"+id).attr("title", 'There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info).tipsy("show");			}		},		error : function {			$("#"+id).attr("title", 'There was an error using AJAX to edit the page.').tipsy("show");		}	}); } function postTHTalkback {	var questionTitle = prompt("Please enter the title of the question you're replying to (or just leave it blank):","");	var sectionTitle = "{{Wikipedia:Teahouse/Teahouse talkback|WP:Teahouse/Questions|";	if(questionTitle == null)	{		return;	}	else if(questionTitle == "")	{		sectionTitle +=	"ts="+"}}";	}	else	{		sectionTitle += questionTitle +"|ts="+"}}";	}	var data = {		format : 'json',		action : 'edit',		minor : false,		title : getURL,		text : sectionTitle,		section : 'new',		summary : "Teahouse talkback: you've got messages!",		token : mw.user.tokens.get('csrfToken')	};	$.ajax({		url : mw.util.wikiScript('api'),		type : 'POST',		dataType : 'json',		data : data,		success : function(data) { if(data && data.edit && data.edit.result && data.edit.result === 'Success') { //window.location = mw.util.wikiGetlink(page); alert("Talkback posted!"); } else { $("#"+id).attr("title", 'There was an error requesting the page edit. Code: ' + data.error.code + '": ' + data.error.info).tipsy("show");			}		},		error : function {			$("#"+id).attr("title", 'There was an error using AJAX to edit the page.').tipsy("show");		}	}); }

mw.loader.using("mediawiki.util", function {   mw.util.addPortletLink( "p-tb", "https://tools.wmflabs.org/copyvios/?lang=" + mw.config.get("wgContentLanguage") + "&project=" + mw.config.get("wgSiteName").toLowerCase + "&title=" + encodeURIComponent(mw.config.get("wgPageName")), "Copyvio check", "t-copyvio-check", "Check this page for copyright violations" ); });

importScript('User:Lourdes/PageCuration.js'); // Linkback: User:Lourdes/PageCuration.js //