User:Xenocidic/autofill.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:Xenocidic/autofill. |
// restores "autofill" functionality that used to be available when deleting pages
// it was removed per [[Wikipedia:Village pump (proposals)/Archive 40#autofill]]
// portion of content gets pasted into deletion reason ("Content was..." and "only contributor was...")
// this was written by [[User:CharlotteWebb]], I take no credit whatsoever.
// *** REMEMBER TO REMOVE INAPPROPRIATE CONTENT WHERE APPROPRIATE, i.e. attack pages, etc. ***
s1 = "content was: '$1'"; s2 = "content before blanking was: '$1'";
s3 = " (and the only contributor was \"[[Special:Contributions/$2|$2]]\")";
function bytes(s){ return encodeURIComponent(s).replace(/\%[0-9A-F]{2}/gi, '_').length; }
function contentwas(){
if(mw.config.get('wgAction')!="delete" || !(field = document.getElementById("wpReason"))) return;
x = new XMLHttpRequest();
x.open("GET", mw.config.get('wgServer') + "/w/api.php?action=query&format=xml&prop=revisions&rvprop=user|content&rvlimit=25&titles=" + encodeURIComponent(mw.config.get('wgPageName')), true);
x.onreadystatechange = function() {
if(x.readyState != 4) return; z = new DOMParser().parseFromString(x.responseText,"text/xml");
rev = z.getElementsByTagName("rev"); content = "";
if(rev[0].childNodes.length) { content = rev[0].childNodes[0].nodeValue; s = s1; }
else { s = s2; for(i = 1; i < rev.length && !content.length; i++)
if(rev[i].childNodes.length) content = rev[i].childNodes[0].nodeValue; }
if(!content.length) { field.value = "page was blank"; return; }
content = content.replace(/\s+/, " ");
only = rev[0].getAttribute("user");
for(i = 1; i < rev.length; i++) if(rev[i].getAttribute("user") != only) { only = null; break; }
if(only && bytes(only) > 64) only = null;
if(only) s += s3.replace("$2", only, "g");
limit = 257-bytes(s); // SIC!
if(bytes(content) > limit){ content = content.substring(0, limit);
while(bytes(content) > limit - 3) content = content.substring(0, content.length-1);
content += "..."; }
field.value = s.replace("$1", content);
}
x.send("");
}
addOnloadHook(function(){ setTimeout("contentwas()", 1000); });