Jump to content

User:Rjd0060/oldprod.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>
importScript('User:Animum/urlparameters.js'); //For the "UrlParameters[]" below.
 
$(function() {
 if(wgNamespaceNumber == 1 && UrlParameters["action"] == "edit" && UrlParameters["oldprod"] == 1) {
  var xmlreq = new XMLHttpRequest();
  xmlreq.open("GET", "http://en.wikipedia.org/w/api.php?action=query&list=logevents&ledir=older&leprop=timestamp&letype=delete&letitle=" + encodeURIComponent(wgPageName.split(":")[1]) + "&format=xml", true);
  xmlreq.send("");
  xmlreq.onreadystatechange = function() {
   if(xmlreq.readyState == 4 && xmlreq.status == 200) { //Crucial XML fluff.
    var item = xmlreq.responseXML.getElementsByTagName("item")[(document.getElementById("ca-nstab-main").getElementsByTagName("a")[0].getAttribute("href").indexOf("action=edit") != -1 ? 0 : 1)]; //Is the article existent or not?  If so, do not fetch the restoration date.
    document.editform.wpTextbox1.value = "{{oldprod\|date=" + item.getAttribute("timestamp").split("T")[0] + "}}\n" + document.editform.wpTextbox1.value; //Add it to the editform.
    document.editform.wpMinoredit.checked = false;
    document.editform.wpWatchthis.checked = false;
    document.editform.wpSummary.value = "Tagging with {{[[Template:Oldprod|oldprod]]}}";
    document.editform.submit();
   }
  };
 }
});
 
$(function() {
 if(wgNamespaceNumber == 1) mw.util.addPortletLink("p-cactions", mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&oldprod=1", "oldprod", "ca-oldprod");
});
// </nowiki>