MediaWiki:EditControl.js

/* */

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

// 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; } }

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

/* */