MediaWiki:EditControl.js

/* */

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

// FUNCTION CHECKING WHETHER THE PREVIEW WAS USED // by a new user function checkPreview {

// userrights check - if the user is "autoconfirmed" if (wgUserGroups) { userrights = wgUserGroups.toString; autoconfirmed = userrights.search("autoconfirmed"); } else { autoconfirmed = -1; }

// if the user is autoconfirmed, stop this check if (autoconfirmed != -1) return;

// if there is no edit field, stop if (!document.forms["editform"]) return;

// check the usage of the Preview button if (wgAction=="edit") { document.forms["editform"].elements["wpSave"].onclick = function {return checkBlockSave(true)}; } else if (document.forms["editform"]) { document.forms["editform"].elements["wpSave"].onclick = function {return checkBlockSave(false)}; } }

// FUNCTION CHECKING THE SUMMARY FIELD AND SENDING ALERT // called by function checkPreview function checkBlockSave(edit) {

// check the summary field if(document.getElementById("wpSummary")) { wpsummary = document.getElementById("wpSummary").value; if (wpsummary == "") wpsummary = false; } else { wpsummary = true; }

// alert warning if (edit || !wpsummary) { confirmation_text = ""; if (!wpsummary) {confirmation_text += "You did not filled in the summary.\n"; i++} if (edit) confirmation_text += "You did not check your edit by clicking the Preview button.\n"; confirmation_text += "\nDo you still want to save your editation?"; if (edit) confirmation_text += '\n(click on "Cancel" to preview)'; confirmation = window.confirm(confirmation_text); } else {confirmation = true;}

// show preview or save if (!confirmation) { if (document.getElementById("wpPreview")) { if (edit) document.forms["editform"].elements["wpPreview"].click; }   return false; } else { window.onbeforeunload = null; // obsolete row 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(checkPreview); addOnloadHook(checkCaptcha); if ((wgAction == "edit" || wgAction == "submit") && wgUserName != null) addOnloadHook(addInProcessButton);

/* */