User:Equazcion/post-to-talk.js

$(function{	mw.loader.using( ['jquery.ui', 'mediawiki.api'], function {

var header = 'Header'; var body = 'Body'; var summary = 'an edit summary';

var wikitext = '\n\n==' + header + '==\n\n' + body;

$('.ui-button-text:first').click(function{			postToTalk(wikitext, summary);		});

//postToTalk(wikitext, summary);

function postToTalk( wikitext, summary ) {

var api = new mw.Api;

api.get( {				'action' : 'query',				'titles' : 'User:' + wgUserName,				'prop'  : 'revisions|info',				'intoken' : 'edit',				'rvprop' : 'content',				'indexpageids' : 1			}, {				'ok' : function(result) {					result = result.query;					var page = result.pages[result.pageids[0]];

api.post(						{							'action' : 'edit',							'titles' : 'User:' + wgUserName,							'appendtext' : wikitext,							'summary' : summary,							'token' : page.edittoken						},						{							'ok' : function {window.location.reload;}						}					); }			});		}	}) })