User:AFigureOfBlue/dazzle/lab.js

// //Initiate user-definable variables if( typeof( DazzleConfig ) == 'undefined' ) { DazzleConfig = {}; } if( typeof( DazzleConfig.edit_summary ) == 'undefined' ) { DazzleConfig.edit_summary = ") (Dazzle!"; } if( typeof( DazzleConfig.watch_prods ) == 'undefined' ) { DazzleConfig.watch_prods = true; } //Add the portlet link on page load addOnloadHook(function{ if((wgNamespaceNumber == 0 && wgIsArticle == true)){  addDazzleLink("javascript:dazzle_prod_start;", "PROD", "dz-prod", "Initiate, contest, or second a proposed deletion"); } }); function dazzle_prod_start{ var floatbox = new Floatbox("Proposed deletion", "FireBrick"); set_status("Loading...", "Black"); var pagecontent = query("action=query&prop=revisions&titles=" + enc(wgPageName) + "&rvprop=content&format=xml"); var pagecreator = query("action=query&prop=revisions&titles=" + enc(wgPageName) + "&rvlimit=1&rvprop=user&rvdir=newer&format=xml"); pagecontent.oncomplete(function{ add_note("dazzle_prod_pagecontent", pagecontent.results("ContentOf", "rev", 0));  if (has_note("dazzle_prod_pagecreator")) {   dazzle_prod_run;  } }); pagecreator.oncomplete(function{ add_note("dazzle_prod_pagecreator", pagecreator.results("TagAttr", "rev", "user"));  if (has_note("dazzle_prod_pagecontent")) {   dazzle_prod_run;  } }); function dazzle_prod_run{ pagecontent = get_note("dazzle_prod_pagecontent"); pagecreator = get_note("dazzle_prod_pagecreator"); var floatform = floatbox.create_form; if(pagecontent.match(/\{\{dated prod/i)){ floatbox.form_append("p", "This article is already proposed for deletion. If you want, you can contest or second the deletion."); var radiocontest = floatbox.form_input("radio", "dazzle_prod_action"); radiocontest.id = "dazzle_prod_contest"; var radiocontestlabel = floatbox.form_append("label", "Contest"); var radiosecond = floatbox.form_input("radio", "dazzle_prod_action"); radiosecond.id = "dazzle_prod_second"; var radiosecondlabel = floatbox.form_append("label", "Second"); var radiobr = floatbox.form_append("br"); var presubmit = floatbox.form_append("div"); radiocontest.onclick = function{ radiocontest.style.display = "none"; radiosecond.style.display= "none"; radiocontestlabel.style.display = "none"; radiosecondlabel.style.display= "none"; radiobr.style.display= "none"; add_child(presubmit, "label", "Edit summary for removal (maximum 150 characters)"); add_child(presubmit, "br"); var reason = add_input(presubmit, "text", "reason"); reason.id = "dazzle_prod_reason"; reason.maxLength = 150; reason.style.width = "99%"; };  radiosecond.onclick = function{ radiocontest.style.display = "none"; radiosecond.style.display= "none"; radiocontestlabel.style.display = "none"; radiosecondlabel.style.display= "none"; radiobr.style.display= "none"; add_child(presubmit, "label", "Reason for seconding nomination (leave blank if there is no reason beyond the original)"); add_child(presubmit, "br"); var reason = add_input(presubmit, "text", "reason"); reason.id = "dazzle_prod_reason"; reason.style.width = "99%"; }; } else { var notifybutton = floatbox.form_input("checkbox", "notifybutton"); notifybutton.checked = true; notifybutton.id = "dazzle_prod_notify"; floatbox.form_append("label", "Notify page creator (" + pagecreator + ") of tagging."); floatbox.form_append("br"); floatbox.form_append("label", "Reason for deletion nomination"); floatbox.form_append("br"); var reason = floatbox.form_input("text", "reason"); reason.id = "dazzle_prod_reason"; reason.style.width = "99%"; } var watchbutton = floatbox.form_input("checkbox", "watchbutton"); watchbutton.checked = DazzleConfig.watch_prods; watchbutton.id = "dazzle_prod_watch"; floatbox.form_append("label", "Add page to watchlist"); floatbox.form_append("br"); var submitbutton = floatbox.form_input("button", "submit"); submitbutton.value = "Submit"; set_status("Awaiting input..."); submitbutton.onclick = function{ set_status("Editing..."); var reason = id("dazzle_prod_reason").value; //Must be before form removal! if (id("dazzle_prod_second")) { var seconding = id("dazzle_prod_second").checked; //Ditto } else { var seconding = false; }  if (notifybutton) { var notify = id("dazzle_prod_notify").checked; //Ditto if (notify) { add_note("dazzle_prod_notify_checked"); }  }   var watch = id("dazzle_prod_watch").checked; //Ditto floatbox.mainbox.removeChild(floatform); add_child(floatbox.mainbox, "p", "Editing pages... please wait. The page will reload once editing is complete."); if (watch) { var do_watch = "&watchlist=watch"; } else { var do_watch = "&watchlist=preferences"; }  if(pagecontent.match(/\{\{dated prod/i)){ if(seconding){ var token = query("action=query&prop=info&intoken=edit&titles=" + enc(wgPageName) + "&format=xml"); token.oncomplete(function{     var edittoken = token.results("TagAttr", "page", "edittoken");      var txt = pagecontent.replace("|reason\" -->", "|reason\" -->\n");      var edit = query("action=edit&notminor=notminor&token=" + enc(edittoken) + "&title=" + enc(wgPageName) + "&summary=" + enc("Seconding proposed deletion" + DazzleConfig.edit_summary) + do_watch + "&text=" + enc(txt) + "&format=xml");      edit.oncomplete(function{ if (edit.results("Error")) { alert("An error occurred and the edit was not made: " + edit.results("Error", "info") + "."); }      dazzle_prod_complete; });    });    } else { var txt = pagecontent.replace(/\{\{dated prod[^\n]*\n/i, "").replace("\n", "").replace(/\{\{prod\-2\|[^\n]*\n/gi, ""); var token = query("action=query&prop=info&intoken=edit&titles=" + enc(wgPageName) + "|Wikipedia:Sandbox&format=xml"); token.oncomplete(function{     var token1 = token.results("TagAttr", "page", "edittoken", 0);      var edit_page = query("action=edit&notminor=notminor&token=" + enc(token1) + "&title=" + enc(wgPageName) + "&summary=" + enc("PROD contested because: " + reason + DazzleConfig.edit_summary) + do_watch + "&text=" + enc(txt) + "&format=xml");      edit_page.oncomplete(function{ if (edit_page.results("Error")) { alert("An error occurred and the PROD could not be contested: " + edit_page.results("Error", "info") + "."); }      add_note("dazzle_prod_contesting_edit_done"); if (has_note("dazzle_prod_contestingtalk_edit_done")) { dazzle_prod_complete; }     });      var token2 = token.results("TagAttr", "page", "edittoken", 1);      var banner = "";      var edit_talk = query("action=edit&notminor=notminor&token=" + enc(token2) + "&title=Talk:" + enc(wgPageName) + "&summary=" + enc("Adding  notice to page" + DazzleConfig.edit_summary) + do_watch + "&prependtext=" + enc(banner) + "&format=xml");      edit_talk.oncomplete(function{ if (edit_talk.results("Error")) { alert("An error occurred and the article talk page was not tagged: " + edit_talk.results("Error", "info") + "."); }      add_note("dazzle_prod_contestingtalk_edit_done"); if (has_note("dazzle_prod_contesting_edit_done")) { dazzle_prod_complete; }     });     });    }   } else { var token = query("action=query&prop=info&intoken=edit&titles=" + enc(wgPageName) + "|Wikipedia:Sandbox&format=xml"); token.oncomplete(function{    var token1 = token.results("TagAttr", "page", "edittoken", 0);     var edit_page = query("action=edit&notminor=notminor&token=" + enc(token1) + "&title=" + enc(wgPageName) + "&summary=" + enc("Proposing article for deletion" + DazzleConfig.edit_summary) + do_watch + "&prependtext=" + enc("" + reason + "\n") + "&format=xml");     edit_page.oncomplete(function{ if (edit_page.results("Error")) { alert("An error occurred and the article could not be proposed for deletion: " + edit_page.results("Error", "info") + "."); }     if (notify) { add_note("dazzle_prod_main_edit_done"); if (has_note("dazzle_prod_usertalk_edit_done")) { dazzle_prod_complete; }     } else { dazzle_prod_complete; }    });     if (notify) {      var token2 = token.results("TagAttr", "page", "edittoken", 1);      var edit_usertalk = query("action=edit&notminor=notminor&token=" + enc(token2) + "&title=" + enc("User talk:" + pagecreator) + "&summary=" + enc("Notice: Proposed deletion of " + wgPageName + "" + DazzleConfig.edit_summary) + do_watch + "&appendtext=" + enc("\n" + wgPageName + " ~") + "&format=xml");      edit_usertalk.oncomplete(function{ if (edit_usertalk.results("Error")) { alert("An error occurred and the page creator (" + pagecreator + ") was not notified of the PROD: " + edit_usertalk.results("Error", "info") + "."); }      add_note("dazzle_prod_usertalk_edit_done"); if (has_note("dazzle_prod_main_edit_done")) { dazzle_prod_complete; }     });     }    });   }  }; } } function dazzle_prod_complete{ set_status("Done!"); location.reload; } //