Jump to content

User:Abelmoschus Esculentus/Article.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
$(document).ready(init);
function init()
{
	if(mw.config.get("wgCanonicalNamespace") == "User" || mw.config.get("wgCanonicalNamespace") == "User_talk")
	{
		mw.util.addPortletLink("p-cactions", "#", "Instructions", "ca-article", null, null);
		mw.util.addPortletLink("p-cactions", "#", "About RS", "ca-RS", null, null);
		$('#ca-article').click(post);
		$('#ca-RS').click(post2);
	}
}
function getURL()
{
	var url;
	var slashLocation = mw.config.get("wgTitle").indexOf("/");
	if(slashLocation > 0)
	{
		url = "User_talk:" + mw.config.get("wgTitle").substring(0, mw.config.get("wgTitle").indexOf("/"));
	}
	else
	{
		url = "User_talk:" + mw.config.get("wgTitle");
	}
	return url;
}
function post() 
{
	var message = "{{sub"+"st:User:Ian.thomson/Howto}}\n\n~~~~";
	var data = {
		format : 'json',
		action : 'edit',
		minor : false,
		title : getURL(),
		text : message,
		section : 'new',
		sectiontitle : 'How to write an article that will not be deleted or rejected',
		watchlist : 'nochange',
		token : mw.user.tokens.get('editToken')
	};
	$.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.href = "https://en.wikipedia.org/wiki/User_talk:" + mw.config.get("wgTitle");
			} 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 post2() 
{
	var message = "{{sub"+"st:User:Abelmoschus Esculentus/RS}}";
	var data = {
		format : 'json',
		action : 'edit',
		minor : false,
		title : getURL(),
		text : message,
		section : 'new',
		sectiontitle : 'About reliable sources',
		watchlist : 'nochange',
		token : mw.user.tokens.get('editToken')
	};
	$.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.href = "https://en.wikipedia.org/wiki/User_talk:" + mw.config.get("wgTitle");
			} 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");
		}
	});
}
//</nowiki>