User:AFigureOfBlue/dazzle/di.js

// //Initiate user-definable variables if( typeof( DazzleConfig ) == 'undefined' ) { DazzleConfig = {}; } if( typeof( DazzleConfig.edit_summary ) == 'undefined' ) { DazzleConfig.edit_summary = ") (Dazzle!"; } if( typeof( DazzleConfig.watch_dis ) == 'undefined' ) { DazzleConfig.watch_dis = true; } //Add the portlet link on page load $(function{ return; // T72470 if((wgNamespaceNumber == 6  && wgIsArticle == true)){   addDazzleLink("javascript:dazzle_di_start;", "DI", "dz-di", "Tag image for deletion"); } });

function dazzle_di_start{ var floatbox = new Floatbox("Deletable image", "FireBrick"); set_status("Loading...", "Black");

var pagecreator = query("action=query&prop=revisions&titles=" + enc(wgPageName) + "&rvlimit=1&rvprop=user&rvdir=newer&format=xml"); pagecreator.oncomplete(function{ add_note("dazzle_di_pagecreator", pagecreator.results("TagAttr", "rev", "user"));  dazzle_di_run; }); function dazzle_di_run{ pagecreator = get_note("dazzle_di_pagecreator"); var floatform = floatbox.create_form; var right = floatbox.form_append("div"); right.style.cssFloat = "right"; right.style.styleFloat = "right";

var notifybutton = add_input(right, "checkbox", "notifybutton"); notifybutton.checked = true; notifybutton.id = "dazzle_di_notify"; add_child(right, "label", "Notify uploader (" + pagecreator + ") of tagging.");

add_child(right, "br"); var derivative = add_input(right, "checkbox", "derivative"); derivative.id = "dazzle_di_derivative"; add_child(right, "label", "Image is a derivative work"); add_child(right, "br"); var watchbutton = add_input(right, "checkbox", "watchbutton"); watchbutton.checked = DazzleConfig.watch_dis; watchbutton.id = "dazzle_di_watch"; add_child(right, "label", "Add page to watchlist"); add_child(right, "br"); var submitbutton = add_input(right, "button", "submit"); submitbutton.value = "Submit";

floatbox.form_append("label", "Select the reason(s) for deletion:"); floatbox.form_append("br"); var box_nosource = floatbox.form_input("checkbox", "box_nosource"); box_nosource.id = "dazzle_di_box_nosource"; floatbox.form_append("label", "No source"); floatbox.form_append("br");

var box_nolicense = floatbox.form_input("checkbox", "box_nolicense"); box_nolicense.id = "dazzle_di_box_nolicense"; floatbox.form_append("label", "No license"); floatbox.form_append("br");

var box_nopermission = floatbox.form_input("checkbox", "box_nopermission"); box_nopermission.id = "dazzle_di_box_nopermission"; floatbox.form_append("label", "No evidence of permission"); floatbox.form_append("br");

var box_nousage = floatbox.form_input("checkbox", "box_nousage"); box_nousage.id = "dazzle_di_box_nousage"; floatbox.form_append("label", "Orphaned fair use"); floatbox.form_append("br");

var box_nofur = floatbox.form_input("checkbox", "box_nofur"); box_nofur.id = "dazzle_di_box_nofur"; floatbox.form_append("label", "No fair-use rationale"); floatbox.form_append("br");

var box_disputedfur = floatbox.form_input("checkbox", "box_disputedfur"); box_disputedfur.id = "dazzle_di_box_disputedfur"; floatbox.form_append("label", "Disputed fair-use rationale"); floatbox.form_append("br");

var box_replaceable = floatbox.form_input("checkbox", "box_replaceable"); box_replaceable.id = "dazzle_di_box_replaceable"; floatbox.form_append("label", "Replaceable fair use"); set_status("Awaiting input..."); submitbutton.onclick = function{ //Create the variables first var notify = id("dazzle_di_notify").checked; if (notify) { add_note("dazzle_di_notify_checked"); }  var watch = id("dazzle_di_watch").checked; var derivative = id("dazzle_di_derivative").checked; //Create the variables which will be used to "build" the edits. var fileprepend = ""; var userappend = "\n"; if (id("dazzle_di_box_nosource").checked && id("dazzle_di_box_nolicense").checked) { if (derivative) { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; } else { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; }  } else { if (id("dazzle_di_box_nosource").checked) { if (derivative) { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; } else { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; }   }    if (id("dazzle_di_box_nolicense").checked) { if (derivative) { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; } else { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; }   }   }   if (id("dazzle_di_box_nopermission").checked) { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; }  if (id("dazzle_di_box_nousage").checked) { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; }  if (id("dazzle_di_box_nofur").checked) { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; }  if (id("dazzle_di_box_replaceable").checked) { fileprepend += "\n"; userappend += "\n" + wgTitle + " ~"; }  if (id("dazzle_di_box_disputedfur").checked) { var reason = prompt("Why is the fair-use rationale disputed?", ""); fileprepend += "" + reason + "\n"; userappend += "\n" + wgTitle + " ~"; }  floatbox.mainbox.removeChild(floatform); add_child(floatbox.mainbox, "p", "Editing pages... please wait. The page will reload once editing is complete."); set_status("Editing..."); if (watch) { var do_watch = "&watchlist=watch"; } else { var do_watch = "&watchlist=preferences"; }

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("This file may qualify for speedy deletion" + DazzleConfig.edit_summary) + do_watch + "&prependtext=" + enc(fileprepend) + "&format=xml");    edit_page.oncomplete(function{ if (edit_page.results("Error")) { alert("An error occurred and the image could not be tagged for deletion: " + edit_page.results("Error", "info") + "."); }    if (notify) { add_note("dazzle_di_main_edit_done"); if (has_note("dazzle_di_usertalk_edit_done")) { dazzle_di_complete; }    } else { dazzle_di_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: Deletion tagging of " + DazzleConfig.edit_summary) + "&appendtext=" + enc(userappend) + "&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 deletion tagging: " + edit_usertalk.results("Error", "info") + "."); }     add_note("dazzle_di_usertalk_edit_done"); if (has_note("dazzle_di_main_edit_done")) { dazzle_di_complete; }    });    }   });  }; } }

function dazzle_di_complete{ set_status("Done!"); location.reload; }

//The following code is commented out because it DOES NOT WORK. I have more or less given up on implementing such code for the time being; however, I'm keeping it here as a springboard for possible future development. Note: Uses old version of toolkit. /* wtk.change_status("Finding image usage..."); var usage = wtk.query("action=query&list=imageusage&iutitle=" + enc(wgPageName)); for(var i = 0; i < usage.query.imageusage.length; i++){ var currentpage = usage.query.imageusage[i].title; wtk.change_status("Editing " + currentpage + "..."); var pagecontent = wtk.cur_rev_text(currentpage); alert(pagecontent); var matchtext = new RegExp("(image|file)\\:\\s*" + wgTitle, "gi"); if(pagecontent.match(matchtext)){ var newcontent = pagecontent.replace(matchtext, "File:" + wgTitle + "|"); alert(newcontent); wtk.query("action=edit&title=" + enc(currentpage) + "&token=" + wtk.edit_token + "&text=" + enc(newcontent) + "&notminor&summary=" + enc(" has been nominated for speedy deletion" + DazzleConfig.edit_summary)); } } */

//