MediaWiki:UploadForm.js

/* ============ UPLOAD FILE FORM =============== author:   Petr Kajzar User:Slepi date:     02/2009, last update 06/2014 version:  MW 1.22 =============================================

// LABELS AND HINTS FOR SOME FORM FIELDS // HERE YOU CAN EASILY EDIT LABELS OF THE FORM

// Field "Description" var popis = "Description:"; var napoveda_popis = "";

// Field "Source" // Warning: at the end of the text there is a checkbox "My own work" // no description, the text should introduce it var zdroj = "Source:"; var napoveda_zdroj = "Please enter the source of the file. If the file is your own work, please check My own work."; var popisek_zatr_zdroj = "Own work:";

// Field "Author" var autor = "Author:"; var napoveda_autor = "";

// Field "Date" // Warning: at the end of the text there is a checkbox "Today" // no description, the text should introduce it var datum = "Date:"; var napoveda_datum = "We recommend write the date in YYYY-MM-DD or YYYY-MM or YYYY. Or you can check the box Today."; var popisek_zatr_datum = "Today:";

// Field "License" is generated by the MediaWiki code.

// Field "Category" var kategorie = "Categories:"; var napoveda_kategorie = "Enter categories, which are suitable for your file, and split them by a comma ."; var popis_odkazu_kategorii = "Link to categories list (open in new window):"; var odkaz_seznam_kategorii = "Category:Categories";

/* ==== SCRIPT SOURCE CODE - please do not edit, if you are not sure ==== */

// FUNCTION RETURNING THE USER // if he did not filled importent fields function nezadanyParametr(parametr) { window.alert("You did not enter a "+parametr+" of the file! Please, fill in missing information."); return false; } // VARIABLES USED THROUGH WHOLE CODE // the sending form var formular = ""; // Submit button var tlacitkoOdeslat = ""; // license chosen in "Own work" var zvolenaLicence = 0; // FUNCTION FILLING FILEDS WITH "MY OWN WORK" function vlastniPraceFce { if (formular.elements["vlastniprace"].checked == true) { formular.elements["mySource"].value = ""; formular.elements["mySource"].disabled = true; formular.elements["myAuthor"].value = "" + "~"; formular.elements["myAuthor"].disabled = true; // license "CC-BY-SA" zvolenaLicence = formular.elements["wpLicense"].selectedIndex; formular.elements["wpLicense"].selectedIndex = 6; licenseSelectorCheck; } else { formular.elements["mySource"].disabled = false; formular.elements["myAuthor"].disabled = false; formular.elements["wpLicense"].selectedIndex = zvolenaLicence; licenseSelectorCheck; } } // FUNCTION FILLING CURRENT DATE function dnesniDatumFce { if (formular.elements["dnesnidatum"].checked == true) { dnesni_datum = new Date; vyplneni_rok = dnesni_datum.getFullYear; vyplneni_mesic = (dnesni_datum.getMonth + 1); if (vyplneni_mesic < 10) vyplneni_mesic = "0" + vyplneni_mesic; vyplneni_den = dnesni_datum.getDate; if (vyplneni_den < 10) vyplneni_den = "0" + vyplneni_den; vyplneni_data = vyplneni_rok + "-" + vyplneni_mesic + "-" + vyplneni_den; formular.elements["myDate"].value = vyplneni_data; formular.elements["myDate"].disabled = true; } else { formular.elements["myDate"].disabled = false; } } // FUNCTION WHICH SUBMITS THE FORM // during uploading function odeslatFormular { // variables read from form, testing of input mujPopis = formular.elements['myDesc'].value; if (!mujPopis) {nezadanyParametr("description"); return false;} mujZdroj = formular.elements['mySource'].value; if (!mujZdroj) {nezadanyParametr("source"); return false;} mujDatum = formular.elements['myDate'].value; mujAutor = formular.elements['myAuthor'].value; if (!mujAutor) {nezadanyParametr("author"); return false;} mujKategorie = formular.elements['myCategory'].value; if (!mujKategorie) mujKategorie="Uncategorized files"; // fill the license and delete it from MediaWiki Field MediaLicence = formular.elements['wpLicense'].options[formular.elements['wpLicense'].selectedIndex].value; if (MediaLicence) { mujLicence = ""; } else { mujLicence = ""; testLicence = window.confirm("You did not enter any license of the file.\n\nIf you want to save file under another license, please, enter the license after file upload.\n\nIf you are not sure abou the licenses, please, contact our editorial board (info@wikilectures.eu).\n\nDo you really want to save this file without licese?"); if(!testLicence) return false; } formular.elements['wpLicense'].options[formular.elements['wpLicense'].selectedIndex].value = ""; // Category check mujKategorieSplit=mujKategorie.split(","); mujKategorie=""; for(i=0;i<mujKategorieSplit.length;i++) { mujKategorie += "\n"; } // added category according to its mime type if (mujKategorie.indexOf("Images") == -1 && mujKategorie.indexOf("Flash animations") == -1 && mujKategorie.indexOf("Sounds") == -1 && mujKategorie.indexOf("text files") == -1 && mujKategorie.indexOf("Compiled archives") == -1) { nazevSouboru = formular.elements["wpDestFile"].value.split("."); switch(nazevSouboru[nazevSouboru.length-1].toLowerCase) { case "png": case "gif": case "jpg": case "jpeg": case "djvu": case "svg": mujKategorie += "\n"; break; case "swf": mujKategorie += "\n"; break; case "mp3": case "ogg": mujKategorie += "\n"; break; case "pdf": mujKategorie += "\n"; break; case "zip": mujKategorie += "\n"; break; } }  // template File with input text formular_popis = "\n"; formular_popis += mujKategorie; // insert the template back into form document.getElementById("wpUploadDescription").value = formular_popis; // submit click simulation puvodniSubmity = document.getElementsByName("wpUpload"); var tlacitkoOdeslat = puvodniSubmity[0]; tlacitkoOdeslat.click; return false; } // FUNCTION PREPARING A ROW IN THE FORM // with checkbox, with onclick etc. function vytvoritRadek (jmeno, id, napoveda, pop_checkbox, nabidka_checkboxu, funkce_checkboxu) { novyradek = ' ' + jmeno + ' '; if (nabidka_checkboxu && funkce_checkboxu) { novyradek += ' ' + pop_checkbox + ' '; } if (napoveda || napoveda != " ") { novyradek += ' ' + napoveda + ' '; } novyradek+="  "; $(".mw-htmlform-field-Licenses").before(novyradek); } // FUNCTION CHANGING THE FORM // of Upload file function zmenitFormular { // if no upload, exit if(wgPageName!="Special:Upload") return false; // exit when being on the warning page if(document.getElementById("uploadwarning")) return; // exit when not logged in if(!wgUserName) return; // exit if only uploading new version wpReUpload = mw.util.getParamValue('wpForReUpload'); // get url parameter if(wpReUpload!=null) return; // exit if error message is displayed pocetChyb = getElementsByClass("error"); if(pocetChyb.length > 0) return; // link to form if(document.forms["mw-upload-form"]) formular = document.forms["mw-upload-form"]; // link to tab if(document.getElementById("mw-htmlform-description")) tabulka = document.getElementById("mw-htmlform-description"); // exit if deleted file // do not show edit tools and license field if (wgUploadSourceIds.length == 0) { tabulka.deleteRow(4); tabulka.deleteRow(3); return false; } // hide submit button $('input[name="wpUpload"]').css({"visibility":"hidden", "position":"absolute"}); // delete description row $(".mw-htmlform-field-HTMLTextAreaField").css({"visibility":"hidden", "position":"absolute"}) // hide edittools $(".mw-editTools").hide; // new line: description vytvoritRadek(popis, "myDesc", napoveda_popis); // new line: source vytvoritRadek(zdroj, "mySource", napoveda_zdroj, popisek_zatr_zdroj, "vlastniprace", "vlastniPraceFce"); // new line: author vytvoritRadek(autor, "myAuthor", napoveda_autor); // new line: date vytvoritRadek(datum, "myDate", napoveda_datum, popisek_zatr_datum, "dnesnidatum", "dnesniDatumFce"); // new line: category vytvoritRadek(kategorie, "myCategory", napoveda_kategorie); // new submit button $('table#mw-htmlform-options tr:last').after('   Načíst soubor  '); } // start $(function { zmenitFormular; });