User:Seven-League Bot/monobook/images.js

/* */

function addButtonLicenseInconnue { if (decodeURI(window.location.href).indexOf("Image:") > 0) { ul = document.getElementById("filetoc"); if (!ul) return; var a = document.createElement("a"); var uls = document.getElementsByTagName("ul"); var usr = null; for (var cpt = 0 ; cpt < uls.length && !usr ; cpt++) if (uls[cpt].getAttribute("class") == "special") usr = uls[cpt]; var lis = usr.getElementsByTagName("li"); var as = lis[lis.length -1].getElementsByTagName("a"); usr = null; for (var cpt = 0 ; cpt < as.length && !usr; cpt++) if (decodeURI(as[cpt].getAttribute("href")).indexOf("User:") > 0) usr = decodeURI(as[cpt].innerHTML); a.innerHTML = "No License"; a.href = "javascript: void(0);"; if (a.attachEvent) a.attachEvent("onclick", addLicenseInconnueImage); else a.setAttribute("onclick", "javascript: addLicenseInconnueImage"); var li = document.createElement("li"); li.appendChild(a); li.appendChild(document.createTextNode("   ")); var a1 = document.createElement("a"); a1.innerHTML = "Warn " + usr; a1.href = "javascript: void(0);"; if (a1.attachEvent) a1.attachEvent("onclick", addLicenseInconnueUser); else a1.setAttribute("onclick", "javascript: addLicenseInconnueUser"); li.appendChild(a1); li.id = "liAvertissement"; ul.appendChild(li); } //if }

addLoadEvent(addButtonLicenseInconnue);

function addLicenseInconnueImage { addMessage("Leaving No license template..."); var article = getArticleName; //on the image page var ajax2 = new objAJAX; ajax2.textBox = " ~"; ajax2.summary = "Warning: Image copyright problem"; ajax2.clearTextBox = false; ajax2.article = article; ajax2.newSection = true; ajax2.finishedMessage = ajax2.article + ": Template left"; editArticle(ajax2, article); }

function addLicenseInconnueUser { addMessage("Sending message to the uploader..."); //on the user page var uls = document.getElementsByTagName("ul"); var tmp = null; for (var cpt = 0 ; cpt < uls.length && !tmp ; cpt++) if (uls[cpt].getAttribute("class") == "special") tmp = uls[cpt]; var lis = tmp.getElementsByTagName("li"); var as = lis[lis.length -1].getElementsByTagName("a"); var article = null; for (var cpt = 0 ; cpt < as.length && !article ; cpt++) if (decodeURI(as[cpt].getAttribute("href")).indexOf("User:") > 0) article = decodeURI(as[cpt].innerHTML); var ajax2 = new objAJAX; ajax2.textBox = " ~"; ajax2.summary = "Images copyright problem"; ajax2.clearTextBox = false; ajax2.article = "User_talk:" + article; ajax2.newSection = true; ajax2.finishedMessage = article + ": user warned"; editArticle(ajax2); }

function editArticle(ajaxObject) { //first we read the time stamp var url = "/w/index.php?title=" + ajaxObject.article + "&action=edit" + (ajaxObject.newSection ? "&section=new" : ""); ajaxObject.conn.onreadystatechange = function { if (ajaxObject.conn.readyState == 4) { //getElementsByName doesn't work (??), let's get it manually var doc = ajaxObject.conn.responseXML; var ts = 0, token = 0; var inputs = doc.getElementsByTagName("input"); for (var cpt = 0 ; cpt < inputs.length && !ts; cpt++) { if (inputs[cpt].getAttribute("name") == "wpEdittime") ts = inputs[cpt].value; }                               var as = 0; for (var cpt = 0 ; cpt < inputs.length && !as; cpt++) { if (inputs[cpt].getAttribute("name") == "wpAutoSummary") as = inputs[cpt].value; }                               var st = 0; for (var cpt = 0 ; cpt < inputs.length && !st; cpt++) { if (inputs[cpt].getAttribute("name") == "wpStarttime") st = inputs[cpt].value; }                               if (ajaxObject.clearTextBox) var tb = ""; else var tb = doc.getElementById("wpTextbox1").value + String.fromCharCode(13, 13); for (var cpt = 0 ; cpt < inputs.length && !token; cpt++) { if (inputs[cpt].getAttribute("name") == "wpEditToken") token = inputs[cpt].value; }                               if (ts) { submitArticle(ajaxObject, ts, token, tb, as, st); }                       }                }        ajaxObject.conn.open("GET", url, true) ajaxObject.conn.overrideMimeType('text/xml'); ajaxObject.conn.send(null); }

function submitArticle(ajaxObject, ts, tk, tb, as, st) { //submit (save) the page var url = "/w/index.php?title=" + ajaxObject.article + "&action=submit"; var params = "wpEdittime=" + ts + "&wpTextbox1=" + tb + ajaxObject.textBox + "&wpSummary=" + ajaxObject.summary + "&wpEditToken=" + tk + "&wpAutoSummary=" + as + (ajaxObject.newSection ? "&wpSection=new" : "") + "&wpStarttime=" + st;

ajaxObject.conn.onreadystatechange = function { if (ajaxObject.conn.readyState == 4) { try { if (ajaxObject.conn.responseXML.getElementsByTagName("form").length == 1) addMessage(null, " Succès ! " + ajaxObject.finishedMessage); else addMessage("Failure: " + ajaxObject.article) } catch (e) { addMessage("Failure: " + ajaxObject.article) } }               }        ajaxObject.conn.open('POST', url, true); ajaxObject.conn.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); ajaxObject.conn.setRequestHeader("Content-length", params.length); ajaxObject.conn.setRequestHeader("Connection", "close"); ajaxObject.conn.send(params); }

function addMessage(msg, innerHTML, clear) { var div = document.getElementById("messageUtilisateur"); if (!div) { div = document.createElement("div"); div.className = "messageUtilisateur"; div.id = "messageUtilisateur"; var bcont = document.getElementById("bodyContent"); try { bcont.insertBefore(div, bcont.getElementsByTagName("p")[0]); } catch (e) { try { bcont.insertBefore(div, bcont.getElementsByTagName("div")[0]); } catch(e) { } }       }        if (clear) div.innerHTML = ""; if (msg) { var txtNode = document.createTextNode(msg); div.appendChild(txtNode); } else if (innerHTML) { div.innerHTML += innerHTML; }       div.appendChild(document.createElement("br")); }

/* */