User:Coffee/arkansas.js

function formatResponse(response) { //This bit was stolen from Gracenotes. Thanks, Gracenotes! try { response = response.query.pages; for (var property in response) return response[property]; } catch (e) { } } function zeroPad(str) { return ("0" + str).slice(-2); } function tagArticle(classType, importance, needsPhoto, needsInfobox, needsAttention, needsReferences, isSmall, isAuto, b1, b2, b3, b4, b5, b6, b1_c, b2_c, b3_c, b4_c, b5_c, b6_c) { var req = new sajax_init_object; var page = wgPageName; req.open("GET", wgScriptPath + "/api.php?action=query&prop=info|revisions&format=json&intoken=edit&rvprop=content|timestamp&titles=" + encodeURIComponent(page), false); req.send(null); var info = formatResponse(eval("(" + req.responseText + ")")); var date = new Date; var startTime = date.getUTCFullYear + zeroPad(date.getUTCMonth + 1) + zeroPad(date.getUTCDate) + zeroPad(date.getUTCHours) + zeroPad(date.getUTCMinutes) + zeroPad(date.getUTCSeconds); var editTime = (info.revisions[0] ? info.revisions[0].timestamp.replace(/[^0-9]/g, "") : startTime); var content = (info.revisions[0]["*"] ? info.revisions[0]["*"] : ""); var editToken = info.edittoken; content = content.replace(/\{\{\s*[Ww]ikiProject Arkansas.*?\}\}\s*$/m,"\{\{WikiProject Arkansas\|class=" + classType + "\|importance=" + importance + (needsPhoto == true ? "\|needs-photo=yes" : "") + (needsInfobox == true ? "\|needs-infobox=yes" : "") + (needsAttention == true ? "\|attention=yes" : "") + (needsReferences == true ? "\|needs-ref=yes" : "") + (isSmall == true ? "\|small=yes" : "") + (isAuto == true ? "\|auto=yes" : "") + (b1 == true ? "\|b1=yes" : (b1_c == true ? "\|b1=no" : "")) + (b2 == true ? "\|b2=yes" : (b2_c == true ? "\|b2=no" : "")) + (b3 == true ? "\|b3=yes" : (b3_c == true ? "\|b3=no" : "")) + (b4 == true ? "\|b4=yes" : (b4_c == true ? "\|b4=no" : "")) + (b5 == true ? "\|b5=yes" : (b5_c == true ? "\|b5=no" : "")) + (b6 == true ? "\|b6=yes" : (b6_c == true ? "\|b6=no" : "")) + "\}\}\n").replace(/\{\{\s*[Ww]PARKANSAS.*?\}\}\s*$/m,"\{\{WikiProject Arkansas\|class=" + classType + "\|importance=" + importance + (needsPhoto == true ? "\|needs-photo=yes" : "") + (needsInfobox == true ? "\|needs-infobox=yes" : "") + (needsAttention == true ? "\|attention=yes" : "") + (needsReferences == true ? "\|needs-ref=yes" : "") + (isSmall == true ? "\|small=yes" : "") + (isAuto == true ? "\|auto=yes" : "") + (b1 == true ? "\|b1=yes" : (b1_c == true ? "\|b1=no" : "")) + (b2 == true ? "\|b2=yes" : (b2_c == true ? "\|b2=no" : "")) + (b3 == true ? "\|b3=yes" : (b3_c == true ? "\|b3=no" : "")) + (b4 == true ? "\|b4=yes" : (b4_c == true ? "\|b4=no" : "")) + (b5 == true ? "\|b5=yes" : (b5_c == true ? "\|b5=no" : "")) + (b6 == true ? "\|b6=yes" : (b6_c == true ? "\|b6=no" : "")) + "\}\}\n"); //A *very* cheap hack. Works nonetheless. var postdata = "wpTextbox1=" + encodeURIComponent("" + content) + "&wpSummary=" + encodeURIComponent("Assessing for WikiProject Arkansas. You can help!") + "&wpSave=save" + "&wpEditToken=" + encodeURIComponent(editToken) + "&wpEdittime=" + editTime + "&wpStarttime=" + startTime; var req = sajax_init_object; req.open("POST", mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + encodeURIComponent(page) + "&action=submit", false); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-Length", postdata.length); req.send(postdata); return; }

function submitData { document.getElementById("submitData").disabled = true; document.getElementById("submitData").value = "Submitting..."; tagArticle(document.getElementById("classType").value, document.getElementById("importanceType").value, document.getElementById("needsPhoto").checked, document.getElementById("needsInfobox").checked, document.getElementById("needsAttention").checked, document.getElementById("needsReferences").checked, document.getElementById("isSmall").checked, document.getElementById("isAuto").checked, document.getElementById("b1").checked, document.getElementById("b2").checked, document.getElementById("b3").checked, document.getElementById("b4").checked, document.getElementById("b5").checked, document.getElementById("b6").checked, document.getElementById("b1_c").checked, document.getElementById("b2_c").checked, document.getElementById("b3_c").checked, document.getElementById("b4_c").checked, document.getElementById("b5_c").checked, document.getElementById("b6_c").checked); document.getElementById("submitData").value = "Submitting... done!"; }

function buildTagForm { jsMsg(''           + ' '                + 'WikiProject Arkansas'            + ' '            + ' '    + ' '); } $(function { if(wgNamespaceNumber == 1) mw.util.addPortletLink("p-cactions", "javascript:buildTagForm", "ark", "ca-ark"); });