User:Rjd0060/otrs-pending.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
var UrlParameters = new Array ();
 
 function readparams() {
  var asReadInUrlParameters;
  var asReadInUrlParameter;
 
  // Get URL parameters
  asReadInUrlParameters = location.search.substring(1, location.search.length).split("&");
  for (i = 0; i < asReadInUrlParameters.length; i++) {
    asReadInUrlParameter = asReadInUrlParameters[i].split("=");
    UrlParameters[decodeURIComponent(asReadInUrlParameter[0])] = decodeURIComponent(asReadInUrlParameter[1]);
  }
 }
 
 readparams();
 
var noticket = {};
 
noticket.addfield = function() {
    var num = document.getElementById("contentSub").getElementsByTagName("input").length-1; //Based on logic and black magic. *poof*
    document.getElementById("otrsSourceTable").innerHTML += '<tr><td>Image name <small>(excluding the "Image:" prefix)</small>:</td><td><input type="text" id="imgName' + num + '" name="imgName' + num + '" tabindex="1" style="width:350px" /></td></tr>';
}
 
noticket.submit = function() {
    var howmany = document.getElementById("contentSub").getElementsByTagName("input").length-2;
    noticket.submit.generatelist = function() {
        var list_str = "";
        for(x=0;x<howmany;x++) {
            var this_img = document.getElementById("imgName" + (x+1)).value;
            list_str += (this_img ? "* [[:Image:" + this_img.substring(0,1).toUpperCase() + this_img.substring(1) + "]]\n" : "");
        }
        return list_str;
    }
    document.forms["editform"].wpTextbox1.value += "\n\n== Pending permission for image(s) ==\n\nHello.  On following image(s), you have added the {{tl|otrs pending}} template:\n\n" + noticket.submit.generatelist() + "\nUnfortunately, after conducting a search, I could not locate the ticket containing the permission to use the image(s).  Please respond \'\'\'on my talk page\'\'\' if you have the ticket number, or if you would like to send me the permission.  Please note that if we do not receive permission for the image(s), they will likely be deleted within 7-10 days.  Thanks! \~\~\~\~"; //New text in the edit form.
    document.forms["editform"].wpSummary.value = "/* Pending permission for image(s) */ new section"; //Summary.
    document.forms["editform"].wpMinoredit.checked = false; //Not a minor edit.
    document.forms["editform"].wpWatchthis.checked = false; //Let's not watchlist this.
    document.forms["editform"].submit();
}
 
addOnloadHook(function() { 
    if(UrlParameters["action"] == "edit" && wgNamespaceNumber == 3 && UrlParameters["noticket"] == 1) {
        document.getElementById("contentSub").innerHTML = '<br /><form id="otrsSource" name="otrsSource" style="font-size:10pt;color:#000000"><table id="otrsSourceTable" style="background-color:transparent"><tr><td>Image name <small>(excluding the "Image:" prefix)</small>:&nbsp;&nbsp;</td><td><input type="text" name="imgName1" id="imgName1" tabindex="1" style="width:350px" /></td></tr></table><tr><td><input type="button" onclick="noticket.addfield()" tabindex="1" value="Add one field" /></td><td><input type="button" onclick="noticket.submit()" tabindex="1" value="Submit" /></td></tr></form>';
    }
});
 
addOnloadHook(function() {
     if(wgNamespaceNumber == 3 && !UrlParameters["noticket"]) mw.util.addPortletLink("p-cactions", mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + wgPageName + "&action=edit&noticket=1", "noticket", "ca-otrstext"); //Add the tab.
});