User:452/mwapi

//<!-- // Just fuck off. // People like you are why I don't help others anymore. // People like you make me regret EVER helping ANYONE. // So just FUCK OFF. //from http://pastebin.com/u/Monchoman45 var MWAPI = {};

MWAPI.request = function(method, params, success, failure) { var xhr = new XMLHttpRequest; xhr.open('POST', '/wikia.php?controller=WallExternal&method=' + method + '&format=json', true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onreadystatechange = function { if(this.readyState == 4) { this.onreadystatechange = null; if(this.status == 200) { var data = JSON.parse(this.responseText); if(data.status) { if(typeof success == 'function') {success.apply(data);} }				else if(typeof failure == 'function') {failure.apply(data, data.error);} }			else {throw new Error('method `' + method + '` returned HTTP ' + this.status);} }	}	var post = ''; for(var i in params) {post += '&' + i + '=' + encodeURIComponent(params[i]);} xhr.send(post.substring(1)); return xhr; }

MWAPI.new_thread = function(user, title, text, success, failure) { return MWAPI.request('postNewMessage', {		messagetitle: title,		body: text,		pagenamespace: mw.config.get('wgNamespaceIds')['message_wall'],		pagetitle: user,               token: window.mw.user.tokens.get('editToken'),		notifyeveryone: 0	}, success, failure); } /* MWAPI.reply = function(parent, text, success, failure) { return MWAPI.request('replyToMessage', {		body: text,		pagenamespace: mw.config.get('wgNamespaceIds')['thread'],		pagetitle: parent,		parent: parent	}, function(data) {		var dataid = data.message.indexOf('data-id="');		success.apply(data, data.message.substring(dataid + 'data-id="'.length, data.message.indexOf('"', dataid + 'data-id="'.length)) * 1);	}, failure); }

MWAPI.source = function(id, success, failure) { return MWAPI.request('editMessage', {		pagenamespace: mw.config.get('wgNamespaceIds')['thread'],		msgid: id,		pagetitle: id	}, function(data) {success.apply(data, data.htmlorwikitext);}, failure); }

MWAPI.edit_parent = function(id, title, text, success, failure) { return MWAPI.request('editMessageSave', {		newtitle: title,		newbody: text,		pagenamespace: mw.config.get('wgNamespaceIds')['thread'],		msgid: id,		pagetitle: id	}, success, failure); }

MWAPI.edit_reply = function(id, text, success, failure) { return MWAPI.request('editMessageSave', {		isreply: 1,		newbody: text,		pagenamespace: mw.config.get('wgNamespaceIds')['thread'],		msgid: id,		pagetitle: id	}, success, failure); } //FIXME: none of these return anything MWAPI.close = function(id, reason, success, failure) { return MWAPI.request('changeThreadStatus', {		msgid: id,		newState: 'close',		'formdata[0][name]': 'reason',		'formdata[0][value]': reason	}, success, failure); }

MWAPI.reopen = function(id, success, failure) { return MWAPI.request('changeThreadStatus', {		msgid: id,		newState: 'open'	}, success, failure); }

MWAPI.remove = function(id, reason, success, failure) { return MWAPI.request('deleteMessage', {		msgid: id,		mode: 'remove',		'formdata[0][name]': 'reason',		'formdata[0][value]': reason	}, success, failure); }

MWAPI.delete = function(id, reason, success, failure) { return MWAPI.request('deleteMessage', {		msgid: id,		mode: 'admin',		'formdata[0][name]': 'reason',		'formdata[0][value]': reason	}, success, failure); }

MWAPI.restore = function(id, success, failure) { return MWAPI.request('restoreMessage', {		msgid: id	}, success, failure); }