MediaWiki:EditControl.js

/* */

/* ============== Edit Control ========================== author:     Petr Kajzar User:Slepi date:       06/2011 description: script checks new user, whether he filled in               the Summary field, and has other edit-based functions ==========================================================

// THIS FUNCTION CHECKS FILLING IN THE SUMMARY FIELD // when saving edit function startCheckSummaryFill {

// check the summary field if (wgAction=="edit") { document.forms["editform"].elements["wpSave"].onclick = function {return checkSummaryFill}; } else if (document.forms["editform"]) { document.forms["editform"].elements["wpSave"].onclick = function {return checkSummaryFill}; }

return; }

function checkSummaryFill {

// check the summary field if(document.getElementById("wpSummary")) { wpsummary = document.getElementById("wpSummary").value; if (wpsummary == "") wpsummary = false; } else { wpsummary = true; } if (!wpsummary) { document.forms["editform"].elements["wpSummary"].focus; document.getElementById("wpSummaryLabel").style.color = "red"; window.alert("Your changes cannot be saved as you did not filled in the Summary field. Please, describe there shortly what changes you did.\n\nIf you created a new article, write simply \“new article\”. If you did only small changes, describe them (e.g. \“correction of the pathology\” or \“added clinical notes\”).\n\nAfter filling in the Summary field you can save the article.\n\nThank you!"); return false; } else return true; }

// FUNCTION CHANGING reCAPTCHA POSITION function checkCaptcha { if(typeof(RecaptchaOptions) == "undefined") return false; if(document.getElementById("wikiPreview")) document.getElementById("wikiPreview").style.display = "none"; if(document.getElementById("toolbar")) document.getElementById("toolbar").style.display = "none"; if(document.getElementById("wpTextbox1")) document.getElementById("wpTextbox1").style.display = "none"; if(document.getElementById("editpage-copywarn")) document.getElementById("editpage-copywarn").style.display = "none"; if(document.getElementById("wpSummaryLabel")) { document.getElementById("wpSummaryLabel").style.display = "none"; document.getElementById("wpSummary").style.display = "none"; } if(document.getElementById("mw-anon-edit-warning")) document.getElementById("mw-anon-edit-warning").innerHTML = ""; }

// FUNCTION ADDING "SAVE AS DRAFT" BUTTON function addInProcessButton { // check edit if (wgAction != "edit" && wgAction != "submit") return; if (!document.getElementById("wpTextbox1")) return;

// create button draftButton = document.createElement("input"); draftButton.type = "submit"; draftButton.value = "Save as draft";

// button will add "Under construction" template and save changes draftButton.onclick = function { article = document.getElementById("wpTextbox1").value;

if (article.indexOf("") == -1) { article = "\n\n" + article; document.getElementById("wpTextbox1").value = article; }

window.alert("This article will be saved as a draft under construction.\n\nNobody will change your work for one month. If you forget this article, our editorial board will contact you.\n\nIn case of any problem or question, do not hesitate to contact us at info@wikilectures.eu.");

document.forms["editform"].elements["wpSave"].click; };

// insert button document.getElementById("wpDiff").parentNode.insertBefore(draftButton, document.getElementById("wpDiff").nextSibling);

// button SHOW CHANGES // prepare buttonShowChanges = document.createElement("span"); editButtonsRow = getElementsByClass("editButtons")[0]; editButtonsRow.appendChild(buttonShowChanges); // button Show changes bscChanges = document.createElement("a"); bscChanges.href = "#"; bscChanges.onclick = function { document.forms["editform"].elements["wpDiff"].click; return false; } bscChanges.appendChild(document.createTextNode("Show changes")); buttonShowChanges.appendChild(bscChanges); // vertical bar buttonShowChanges.appendChild(document.createTextNode(" | ")); // button CANCEL bscAnchor = document.createElement("a"); bscAnchor.href = wgServer + wgScript + "/" + wgPageName; bscAnchor.appendChild(document.createTextNode("Cancel")); buttonShowChanges.appendChild(bscAnchor); }

// DURING PATROLLING RETURN TO THE ARTICLE if(wgAction == "markpatrolled") { history.back; }

// START addOnloadHook(checkCaptcha); if ((wgAction == "edit" || wgAction == "submit") && wgUserName != null) addOnloadHook(addInProcessButton); addOnloadHook(startCheckSummaryFill);

/* */