MediaWiki:UploadForm.js

/* */

/* ============ UPLOAD FILE FORM =============== author:   Petr Kajzar User:Slepi date:     02/2009 license:  Wikilectures (wikien.lf1.cuni.cz) =============================================

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

// Field "Description" var label_of_decription = "Description:"; var help_description = "";

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

// Field "Author" var label_of_author = "Author:"; var help_author = "";

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

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

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

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

// FUNCTION WHICH HIDES THE ELEMENTY BY ID function hideById(id) { hiddenElement = document.getElementById(id); hiddenElement.style.visibility = "hidden"; hiddenElement.style.position = "absolute"; }

// FUNCTION RETURNING THE USER // if he did not filled importent fields function notFilled(parametr) { window.alert("You have not entered the "+parametr+"!"); }

// VARIABLES USED THROUGH WHOLE CODE

// the sending form - defined in fillDescription var thisForm = "";

// Submit button - defined in fillDescription var buttonSubmit = "";

// FUNCTION FILLING FILEDS WITH "MY OWN WORK" function ownWorkFunction { if (thisForm.elements["ownwork"].checked == true) { thisForm.elements["mySource"].value = ""; thisForm.elements["mySource"].disabled = true; thisForm.elements["myAuthor"].value = ""; thisForm.elements["myAuthor"].disabled = true; } else { thisForm.elements["mySource"].disabled = false; thisForm.elements["myAuthor"].disabled = false; } }

// FUNCTION FILLING CURRENT DATE function todayFunction { if (thisForm.elements["today"].checked == true) { today_date = new Date;

fill_year = today_date.getFullYear; fill_month = (today_date.getMonth + 1); if (fill_month < 10) fill_month = "0" + fill_month; fill_day = today_date.getDate; if (fill_day < 10) fill_day = "0" + fill_day; fill_of_date = fill_year + "-" + fill_month + "-" + fill_day;

thisForm.elements["myDate"].value = fill_of_date; thisForm.elements["myDate"].disabled = true;

} else { thisForm.elements["myDate"].disabled = false; } }

// FUNCTION WHICH SUBMITS THE FORM // during uploading function submitForm {

// variables read from form, testing of input newDescription = thisForm.elements['myDesc'].value; if (!newDescription) {notFilled("desc"); return;} newSource = thisForm.elements['mySource'].value; if (!newSource) {notFilled("Source"); return;} newDate = thisForm.elements['myDate'].value; newAuthor = thisForm.elements['myAuthor'].value; if (!newAuthor) {notFilled("author"); return;} newCategory = thisForm.elements['myCategory'].value; if (!newCategory) newCategory="Uncategorised files";

// fill the license and delete it from MediaWiki Field Medialicense = thisForm.elements['wpLicense'].options[thisForm.elements['wpLicense'].selectedIndex].value; if (Medialicense) { newlicense = ""; } else { newlicense = ""; } thisForm.elements['wpLicense'].options[thisForm.elements['wpLicense'].selectedIndex].value = "";

// categories newCategorySplit=newCategory.split(","); newCategory=""; for(i=0;i<newCategorySplit.length;i++) { newCategory += "\n"; }

// put everything into template File form_desc = "\n"; form_desc += newCategory;

// insert the template back into form document.getElementById("wpUploadDescription").value = form_desc;

// submit click simulation puvodniSubmity = document.getElementsByName("wpUpload"); var buttonSubmit = puvodniSubmity[0]; buttonSubmit.click; }

// FUNCTION CHANGING THE FORM // of Upload file function fillDescription {

// exit when being on the warning page if(document.getElementById("uploadwarning")) return;

// exit when not logged in if(!wgUserName) return;

// variable link to a form thisForm = document.forms["upload"];

// variable link to a table with a form tabulka = document.getElementsByTagName("table"); tabulka = tabulka[0];

// hide the original submit button puvodniSubmity = document.getElementsByName("wpUpload"); var buttonSubmit = puvodniSubmity[0]; buttonSubmit.setAttribute("id", "idOdesilacibutton"); hideById("idOdesilacibutton");

// delete line with field "Description:" tabulka.deleteRow(2);

// delete line with Edittools tabulka.deleteRow(7);

// insert new line: description line_desc = tabulka.insertRow(2); line_desc_0 = line_desc.insertCell(0); line_desc_0.style.textAlign = "right"; line_desc_0.style.verticalAlign = "top"; line_desc_1 = line_desc.insertCell(1); line_desc_1.className = "mw-input";

desc_label = document.createElement("label"); line_desc_0.appendChild(desc_label); desc_label.setAttribute("for", "myDesc"); desc_label_text = document.createTextNode(label_of_decription); desc_label.appendChild(desc_label_text);

desc_field = document.createElement("input"); line_desc_1.appendChild(desc_field); desc_field.setAttribute("type", "text"); desc_field.setAttribute("id", "myDesc"); desc_field.setAttribute("name", "myDesc"); desc_field.setAttribute("size", "60"); desc_field.className="mw-input";

if (help_description || help_description != " ") { desc_hint = document.createElement("div"); line_desc_1.appendChild(desc_hint); desc_hint.className = "prefsectiontip"; desc_hint_text = document.createTextNode(help_description); desc_hint.appendChild(desc_hint_text); }

// insert new line: source line_Source = tabulka.insertRow(3); line_Source_0 = line_Source.insertCell(0); line_Source_0.style.textAlign = "right"; line_Source_0.style.verticalAlign = "top"; line_Source_1 = line_Source.insertCell(1); line_Source_1.className = "mw-input";

Source_label = document.createElement("label"); line_Source_0.appendChild(Source_label); Source_label.setAttribute("for", "mySource"); Source_label_text = document.createTextNode(label_of_source); Source_label.appendChild(Source_label_text);

Source_field = document.createElement("input"); line_Source_1.appendChild(Source_field); Source_field.setAttribute("type", "text"); Source_field.setAttribute("id", "mySource"); Source_field.setAttribute("name", "mySource"); Source_field.setAttribute("size", "60"); Source_field.className="mw-input";

if (help_source || help_source != " ") { Source_hint = document.createElement("div"); line_Source_1.appendChild(Source_hint); Source_hint.className = "prefsectiontip"; Source_hint_text = document.createTextNode(help_source); Source_hint.appendChild(Source_hint_text);

Source_zatr = document.createElement("input"); Source_zatr.setAttribute("type", "checkbox"); Source_hint.appendChild(Source_zatr); Source_zatr.setAttribute("name", "ownwork"); Source_zatr.setAttribute("id", "ownwork"); Source_zatr.onclick = ownWorkFunction; }

// insert new line: author line_author = tabulka.insertRow(4); line_author_0 = line_author.insertCell(0); line_author_0.style.textAlign = "right"; line_author_0.style.verticalAlign = "top"; line_author_1 = line_author.insertCell(1); line_author_1.className = "mw-input";

author_label = document.createElement("label"); line_author_0.appendChild(author_label); author_label.setAttribute("for", "myAuthor"); author_label_text = document.createTextNode(label_of_author); author_label.appendChild(author_label_text);

author_field = document.createElement("input"); line_author_1.appendChild(author_field); author_field.setAttribute("type", "text"); author_field.setAttribute("id", "myAuthor"); author_field.setAttribute("name", "myAuthor"); author_field.setAttribute("size", "60"); author_field.className="mw-input";

if (help_author || help_author != " ") { author_hint = document.createElement("div"); line_author_1.appendChild(author_hint); author_hint.className = "prefsectiontip"; author_hint_text = document.createTextNode(help_author); author_hint.appendChild(author_hint_text); }

// insert new line: date line_date = tabulka.insertRow(5); line_date_0 = line_date.insertCell(0); line_date_0.style.textAlign = "right"; line_date_0.style.verticalAlign = "top"; line_date_1 = line_date.insertCell(1); line_date_1.className = "mw-input";

date_label = document.createElement("label"); line_date_0.appendChild(date_label); date_label.setAttribute("for", "myDate"); date_label_text = document.createTextNode(label_of_date); date_label.appendChild(date_label_text);

date_field = document.createElement("input"); line_date_1.appendChild(date_field); date_field.setAttribute("type", "text"); date_field.setAttribute("id", "myDate"); date_field.setAttribute("name", "myDate"); date_field.setAttribute("size", "60"); date_field.className="mw-input";

if (help_date || help_date != " ") { date_hint = document.createElement("div"); line_date_1.appendChild(date_hint); date_hint.className = "prefsectiontip"; date_hint_text = document.createTextNode(help_date); date_hint.appendChild(date_hint_text);

date_zatr = document.createElement("input"); date_zatr.setAttribute("type", "checkbox"); date_hint.appendChild(date_zatr); date_zatr.setAttribute("name", "today"); date_zatr.setAttribute("id", "today"); date_zatr.onclick = todayFunction; }

// insert new line: category line_category = tabulka.insertRow(7); line_category_0 = line_category.insertCell(0); line_category_0.style.textAlign = "right"; line_category_0.style.verticalAlign = "top"; line_category_1 = line_category.insertCell(1); line_category_1.className = "mw-input";

category_label = document.createElement("label"); line_category_0.appendChild(category_label); category_label.setAttribute("for", "myCategory"); category_label_text = document.createTextNode(label_of_category); category_label.appendChild(category_label_text);

category_field = document.createElement("input"); line_category_1.appendChild(category_field); category_field.setAttribute("type", "text"); category_field.setAttribute("id", "myCategory"); category_field.setAttribute("name", "myCategory"); category_field.setAttribute("size", "60"); category_field.className="mw-input";

if (help_category || help_category != " ") { category_hint = document.createElement("div"); line_category_1.appendChild(category_hint); category_hint.className = "prefsectiontip"; completehelp_category = help_category; if (desc_link_category && link_list_category) { completehelp_category += ' ' + desc_link_category; prelink_list = wgServer + wgArticlePath; link_list_category = prelink_list.replace("$1", link_list_category); completehelp_category += ' '; completehelp_category += 'Categories.'; }   category_hint.innerHTML = completehelp_category; }

// insert new line: my submit button line_submit = tabulka.insertRow(9); line_submit_0 = line_submit.insertCell(0); line_submit_0.style.textAlign = "right"; line_submit_1 = line_submit.insertCell(1); line_submit_1.className = "mw-input";

submit_field = document.createElement("textarea"); line_submit_0.appendChild(submit_field); submit_field.setAttribute("id", "wpUploadDescription"); submit_field.setAttribute("name", "wpUploadDescription"); submit_field.setAttribute("cols", "60"); submit_field.setAttribute("cols", "6"); submit_field.className="mw-input"; hideById("wpUploadDescription");

submit_button = document.createElement("button"); line_submit_1.appendChild(submit_button); submit_button_text = document.createTextNode("Upload file"); submit_button.appendChild(submit_button_text); submit_button.onclick = submitForm; }

// IS THIS THE UPLOAD PAGE? // if yes, edit the form if (wgPageName=="Special:Upload") { if (window.addEventListener) { window.addEventListener ("load", fillDescription, false) } else if (window.attachEvent) { window.attachEvent ("onload", fillDescription) }; }

/* */