User:JamieS93/biography.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:JamieS93/biography. |
function formatResponse(response) { //This entire set of code was stolen from Coffee's arkansas script.
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, isLiving, isSmall, isAuto) {
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(/\{\{WikiProject Biography.*?\}\}\n/i, "").replace(/\{\{WPBiography.*?\}\}\n/i, ""); //A *very* cheap hack. Works nonetheless.
var postdata = "wpTextbox1=" + encodeURIComponent("\{\{WPBiography\|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" : "") + "\}\}\n" + content)
+ "&wpSummary=" + encodeURIComponent("Assessing for WikiProject Biography. [[WP:BIOGRAPHY|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('<fieldset style="font-size:10pt">'
+ '<legend>'
+ 'WikiProject Biography'
+ '</legend>'
+ '<table style="background-color:transparent;color:#000000;font-size:10pt"><br />'
+ '<tr><td>Class <small>(see <a href="http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Biography/Assessment#Class_parameter">here</a> for a list of available options)</small>: </td><td><input type="text" name="classType" id="classType" /></td></tr>'
+ '<tr><td>Importance <small>(see <a href="http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Biography/Assessment#Priority_parameter">here</a> for a list of available options)</small>: </td><td><input type="text" name="importanceType" id="importanceType" /></td></tr>'
+ '<tr><td><a href="http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Biography/Arts_and_entertainment">Arts and entertainment</a> work group </td><td><input type="checkbox" name="ae" id="ae" /> <label for="ae">ae</label> |'
+ '<tr><td><a href="http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Actors_and_Filmmakers">WikiProject Actors and Filmmakers</a> </td><td><input type="checkbox" name="af" id="af" /> <label for="af">af</label> |'
+ '<tr><td></td><td><input type="checkbox" name="needsPhoto" id="needsPhoto" /> <label for="needsPhoto">Needs photo?</label></td></tr>'
+ '<tr><td></td><td><input type="checkbox" name="needsInfobox" id="needsInfobox" /> <label for="needsInfobox">Needs infobox?</label></td></tr>'
+ '<tr><td></td><td><input type="checkbox" name="needsAttention" id="needsAttention" /> <label for="needsAttention">Needs attention?</label></td></tr>'
+ '<tr><td></td><td><input type="checkbox" name="needsReferences" id="needsReferences" /> <label for="needsReferences">Needs references?</label></td></tr>'
+ '<tr><td></td><td><input type="checkbox" name="isSmall" id="isSmall" /> <label for="isSmall">Make it small?</label></td></tr>'
+ '<tr><td></td><td><input type="checkbox" name="isAuto" id="isAuto" /> <label for="isAuto">Auto?</label></td></tr>'
+ '<tr><td><input type="submit" id="submitData" onclick="submitData()" value="Submit" /></td></tr>'
+ '</table>'
+ '</fieldset>');
}
$(function() {
if(wgNamespaceNumber == 1) mw.util.addPortletLink("p-cactions", "javascript:buildTagForm()", "bio", "ca-bio");
});