MediaWiki:EditControl.js

/* */

/* ============== Edit Control ========================== author:     Petr Kajzar User:Slepi date:       10/2009 license:    for Wikilectures lf1.cuni.cz   description: script checks new user, whether he filled in               the Summary and used Preview, it checks changes and warns when leaving page ==========================================================

// FUNCTION CHECKING USER ACCOUNT DURATION AND USING SUMMARY AND PREVIEW function previewControl {

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

if (autoconfirmed != -1) return;

if (!document.forms["editform"]) return;

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

// FUNCTION CHECKING THE SUMMARY AND WARNING THE USER function blockEdit(edit) {

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

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

// preview, sending edit to server if (!warning) { if (document.getElementById("wpPreview")) { if (edit) document.forms["editform"].elements["wpPreview"].click; }   return false; } else { return true; } }

// FUNCTION CONFIRMING LEAVING THE EDIT PAGE function confirmLeaveEdit { window.onbeforeunload = function {return "Your changes have not been saved yet. If you leave this page, your edit will be lost.";}; }

// FUNCTION CHECKING CHANGES DURING EDIT function leaveEdit { if (wgAction == "edit") { document.forms["editform"].elements["wpTextbox1"].onchange = confirmLeaveEdit; document.forms["editform"].elements["wpSave"].onclick = function {window.onbeforeunload = null;}; document.forms["editform"].elements["wpPreview"].onclick = function {window.onbeforeunload = null;}; document.forms["editform"].elements["wpDiff"].onclick = function {window.onbeforeunload = null;}; document.getElementById("toggle_wpTextbox1").onclick = function onclick{ToggleFCKEditor('toggle','wpTextbox1'); window.onbeforeunload = null;};

} }

// START CONTROL AFTER LOADING THE PAGE addOnloadHook(previewControl); addOnloadHook(leaveEdit);

/* */