User:Awesome Aasim/quickcreate.js

if (!quickCreate) {

if (typeof relAfterCreate == 'undefined') var relAfterCreate = true;

var quickCreate = function(page, index) {

var wikitext = prompt("Wiki text to add to " + page + ":");

if (wikitext == null || wikitext == undefined) {

return;

}

$.get(mw.config.get("wgScriptPath") + "/api.php", {

action: "query",

format: "json",

meta: "tokens",

type: "csrf"

}).then(function(result, status) {

if (status != 'success') {

alert("Connection failed.");

} else {

$.post(mw.config.get("wgScriptPath") + "/api.php", {

action: "edit",

format: "json",

createonly: 1,

title: page,

token: result.query.tokens.csrftoken,

text: wikitext,

summary: "Quick create " + page

}).then(function(result, status) {

if (status != 'success') {

alert("Connection failed.");

} else {

if (result.error) {

alert(result.error.info);

} else {

$("#quickcreate-" + index).remove();

if (relAfterCreate) location.reload();

}

}

})

}

});

};

$(document).ready(function() {

$(".new").each(function(i) {

try {

$(this).after('[QC]');

$("#quickcreate-" + i).find("a").click(function() {

quickCreate($(this).find(".quickcreate-text").text(), i);

});

} catch (Error) {

}

});

});

}