MediaWiki:EditControl.js

/* */

/* ============== Edit Control ========================== author:     Petr Kajzar User:Slepi date:       06/2011, updated 03/2014 description: script checks Summary field and has other edit-based functions ==========================================================

// Citation tool to all people importScript("MediaWiki:Gadget-cite.js");

$(function { // editorial tools for editors  if (mwGetUserRight("editor")) importScript("MediaWiki:Gadget-button-editorial.js");  // check tools for teachers  if (mwGetUserRight("pedagogue")) importScript("MediaWiki:Gadget-button-checked.js"); });

// THIS FUNCTION CHECKS FILLING IN THE SUMMARY FIELD // when saving edit $(function { // 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 ADDING "SAVE AS DRAFT" BUTTON $(function { // check edit  if ((wgAction != "edit" && wgAction != "submit") || wgUserName == null) 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; }

// edit buttons if ( typeof $ != 'undefined' && typeof $.fn.wikiEditor != 'undefined' ) { // start at onload page $( function {   // Links at the bottom of the article    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { 'section': 'main', 'group': 'insert', 'tools': { 'literaturebutton': { label: 'Links at the bottom of the article', type: 'button', icon: 'http://upload.wikimedia.org/wikipedia/commons/8/8d/Wikieditor-references.png', action: { type: 'encapsulate', options: { pre: " \n== Links ==\n=== Related Articles ===\n=== Bibliography ===\n=== References ===\n \n \n" // text to be inserted }         }        }      }    } );

// insert template $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {     'section': 'advanced',      'group': 'insert',      'tools': {        'templatebutton': {          label: 'Insert template',          type: 'button',          icon: 'http://upload.wikimedia.org/wikipedia/commons/4/4a/Norwegian_template_sign.png',          action: {            type: 'encapsulate',            options: {              pre: ""            }          }        }      }    } );

// inserted article $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {     'section': 'advanced',      'group': 'insert',      'tools': {        'insertbutton': {          label: 'This article is a part of another article',          type: 'button',          icon: 'http://upload.wikimedia.org/wikipedia/commons/a/a1/Toolbaricon_insert_reference_plus.png',          action: {            type: 'encapsulate',            options: {              pre: ""            }          }        }      }    } ); } ); }

// SIMPLIFY EDIT FIELD WITH REASONS TO DELETE THE ARTICLE $(function {  // without deleting it make no sense to do this  if (wgAction != "delete") return;

// reasons wpReason = document.getElementById("wpReason"); if (!wpReason) return;

// usual reasons usualReasons = /(content was|page was empty|content before blanking was)/i;

// help string wpReasonSmall = wpReason.value.toLowerCase;

// reasons edit if (usualReasons.test(wpReasonSmall)){ if((wpReasonSmall.indexOf("") != -1)) { indexStart = wpReasonSmall.indexOf(""); wpReason.value = wpReason.value.substring(indexStart, indexEnd); } else {wpReason.value = "";} } }); /* */