MediaWiki:UploadForm.js

/* */

/* ============ UPLOAD FILE FORM =============== author:   Petr Kajzar User:Slepi date:     02/2009, last update 03/2012 version:  MW 1.17 =============================================

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

// Field "Description" var popisek_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 popisek_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 popisek_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 popisek_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 popisek_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 WHICH HIDES THE ELEMENTY BY ID function schovat(id) { schovanyElement = document.getElementById(id); schovanyElement.style.visibility = "hidden"; schovanyElement.style.position = "absolute"; }

// 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 CZ" zvolenaLicence = formular.elements["wpLicense"].selectedIndex; formular.elements["wpLicense"].selectedIndex = 9; 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 function vytvoritRadek (jmeno, id, cislo_radku, nabidka_checkboxu, funkce_checkboxu) {

eval("radek_" + jmeno + " = tabulka.insertRow(" + cislo_radku + ");"); eval("radek_" + jmeno + "_0 = radek_" + jmeno + ".insertCell(0);"); eval("radek_" + jmeno + "_1 = radek_" + jmeno + ".insertCell(1);"); eval("radek_" + jmeno + "_0.className = 'mw-label';"); eval("radek_" + jmeno + "_1.className = 'mw-input';");

eval(jmeno + "_label = document.createElement('label');"); eval("radek_" + jmeno + "_0.appendChild(" + jmeno + "_label);"); eval(jmeno + "_label.setAttribute('for', '" + id + "');"); eval(jmeno + "_label_text = document.createTextNode(popisek_" + jmeno + ");"); eval(jmeno + "_label.appendChild(" + jmeno + "_label_text);");

eval(jmeno + "_pole = document.createElement('input');"); eval(jmeno + "_pole.setAttribute('type', 'text');"); eval("radek_" + jmeno + "_1.appendChild(" + jmeno + "_pole);"); eval(jmeno + "_pole.setAttribute('id', '" + id + "');"); eval(jmeno + "_pole.setAttribute('name', '" + id + "');"); eval(jmeno + "_pole.setAttribute('size', '60');"); eval(jmeno + "_pole.className='mw-input';");

// check input eval(jmeno + "_pole.onblur = function{this.value = trim(this.value);};");

if (nabidka_checkboxu && funkce_checkboxu) {

eval("radek_" + jmeno + "_1.appendChild(document.createElement('br'));"); eval(jmeno + "_zatr_label = document.createElement('label');"); eval("radek_" + jmeno + "_1.appendChild(" + jmeno + "_zatr_label);"); eval(jmeno + "_zatr_label.setAttribute('for', '" + nabidka_checkboxu + "');"); eval(jmeno + "_zatr_label_text = document.createTextNode('- '+ popisek_zatr_" + jmeno + ");"); eval(jmeno + "_zatr_label.appendChild(" + jmeno + "_zatr_label_text);");

eval(jmeno + "_zatr = document.createElement('input');" +   jmeno + "_zatr.setAttribute('type', 'checkbox');" +    "radek_" + jmeno + "_1.appendChild(" + jmeno + "_zatr);" +    jmeno + "_zatr.setAttribute('name', '" + nabidka_checkboxu + "');" +    jmeno + "_zatr.setAttribute('id', '" + nabidka_checkboxu + "');" +    jmeno + "_zatr.onclick = " + funkce_checkboxu + ";") }

podminka_napoveda = "if (napoveda_" + jmeno + "|| napoveda_" + jmeno + "!= ' ') {" + jmeno + "_hint = document.createElement('div');" + "radek_" + jmeno + "_1.appendChild(" + jmeno + "_hint);" + jmeno + "_hint.className = 'htmlform-tip';" + jmeno + "_hint_text = document.createTextNode(napoveda_" + jmeno + ");" + jmeno + "_hint.appendChild(" + jmeno + "_hint_text);}"; eval(podminka_napoveda); }

// 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'); if(wpReUpload!=null) { getElementsByClass("mw-htmlform-field-Licenses")[0].style.display = "none"; getElementsByClass("mw-editTools")[0].style.display = "none"; 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 puvodniSubmity = document.getElementsByName("wpUpload"); var tlacitkoOdeslat = puvodniSubmity[0]; tlacitkoOdeslat.setAttribute("id", "idOdesilaciTlacitko"); schovat("idOdesilaciTlacitko");

// delete description row tabulka.rows[2].id = "schovanyRadekPopis"; schovat("schovanyRadekPopis");

// hide edittools tabulka.deleteRow(3);

// new line: description vytvoritRadek("popis", "myDesc", "2");

// new line: source vytvoritRadek("zdroj", "mySource", "3", "vlastniprace", "vlastniPraceFce");

// new line: author vytvoritRadek("autor", "myAuthor", "4");

// new line: date vytvoritRadek("datum", "myDate", "5", "dnesnidatum", "dnesniDatumFce");

// new line: category vytvoritRadek("kategorie", "myCategory", "6");

if (napoveda_kategorie || napoveda_kategorie != " ") { komplethelp_kategorie = napoveda_kategorie; if (popis_odkazu_kategorii && odkaz_seznam_kategorii) { komplethelp_kategorie += ' ' + popis_odkazu_kategorii; preodkaz_seznam = wgServer + wgArticlePath; odkaz_seznam_kategorii = preodkaz_seznam.replace("$1", odkaz_seznam_kategorii); komplethelp_kategorie += ' '; komplethelp_kategorie += 'List of categories.'; }   kategorie_hint.innerHTML = komplethelp_kategorie; }

// new line: submit button tabulkaProTlacitka = document.getElementById("mw-htmlform-options"); radek_submit = tabulkaProTlacitka.insertRow(2); radek_submit_0 = radek_submit.insertCell(0); radek_submit_1 = radek_submit.insertCell(1); radek_submit_1.className = "mw-input";

submit_tlacitko = document.createElement("button"); radek_submit_1.appendChild(submit_tlacitko); submit_tlacitko_text = document.createTextNode("Upload file"); submit_tlacitko.appendChild(submit_tlacitko_text); submit_tlacitko.onclick = function {return odeslatFormular;}; }

// START $(function { zmenitFormular; });

/* */