MediaWiki:Wikia.js/fileUpload.js

/*
 * @name		File Upload Form
 * @description	Reformats the Special:Upload page to ensure correct labelling and licensing of uploaded files.
 * @author	T3CHNOCIDE
 * - Link complete and upload warnings taken from UltimateSupreme
 * - http://naruto.wikia.com/wiki/MediaWiki:Common.js/FairUseUpload.js
 * @description	Reformats the Special:Upload page to ensure correct labelling the licensing of uploaded files.
 * @license	CC-BY-SA - http://creativecommons.org/licenses/by-sa/3.0/

if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload') { //Null variables sourceValue = '' //Sets content and maintenance buttons to toggle between image subjects function toggleContent { $('#subjectDiv').html(subjectContent) $("input").change(function{			typeSelected			updateCategories			updateForm		}); $("input").tooltip; }	function toggleMaintenance { $('#subjectDiv').html(subjectMaintenance) $("input").change(function{			typeSelected			updateCategories			updateForm		}); $("input").tooltip; }	//Changes source input selection function toggleSource { if ($('#sourceField').val == 'Website') { $('#sourceDiv').html(sourceWebsite) } else if ($('#sourceField').val == 'Game') { $('#sourceDiv').html(sourceGame) } else if ($('#sourceField').val == 'Book') { $('#sourceDiv').html(sourceBook) } else if ($('#sourceField').val == 'Other') { $('#sourceDiv').html(sourceOther) } else { $('#sourceDiv').html('') }	}	//Sets image source value in output box function updateSource { if ($('#sourceField').val == 'Website') { sourceValue = $('#websiteURL').val } else if ($('#sourceField').val == 'Game') { sourceValue = $('#gameTitle').val + ' - ' + $('#gameMission').val } else if ($('#sourceField').val == 'Book') { sourceValue = $('#bookTitle').val + ' - ' + $('#bookPage').val } else if ($('#sourceField').val == 'Other') { sourceValue = $('#otherDescription').val } else if ($('#sourceField').val == 'None') { sourceValue = '' }	}	//Adds and removes image type to category list var typeCategory = '';

function typeSelected { if ($('#typeField').val != "None") { typeCategory = '\n' } else { typeCategory = ''; }	}	//Adds and removes image subjects to category list var subjectCategories = [];

function subjectChecked(checkboxId) { if ($(checkboxId).is(':checked')) { if(jQuery.inArray('\n', subjectCategories) === -1) { subjectCategories.push('\n') }		} else { if(jQuery.inArray('\n', subjectCategories) > -1) { subjectCategories = $.grep(subjectCategories, function(value) {				return value != '\n';				}); }		}	}	function updateCategories{ subjectChecked('#playerCheckbox') subjectChecked('#vehicleCheckbox') subjectChecked('#combatCheckbox') subjectChecked('#inhabitantCheckbox') subjectChecked('#locationCheckbox') subjectChecked('#eventCheckbox') subjectChecked('#gameCheckbox') subjectChecked('#peopleCheckbox') subjectChecked('#announcementCheckbox') subjectChecked('#merchandiseCheckbox') subjectChecked('#templateCheckbox') subjectChecked('#categoryCheckbox') subjectChecked('#policyCheckbox') subjectChecked('#themeCheckbox') subjectChecked('#flagCheckbox') subjectChecked('#wikiaCheckbox') }	//Moves field changes to input box on change function updateForm{ inputLayout = '\n' + subjectCategories.toString.replace(/\,/g, '') + typeCategory; $('#wpUploadDescription').val(inputLayout) }	//Toggle page contents box function toggleFilePage { if ($('#wpUploadDescription').is(':visible')) { $('#wpUploadDescription').hide } else { $('#wpUploadDescription').show }	}	//Sets empty field warnings function uploadWarning { if ($('#typeField').val === 'None') { window.alert('Please select the image media type before uploading.'); return false; } else if (!$('#descriptionField').val) { window.alert('Please enter short description of the image before uploading.'); return false; } else if ($('#sourceField').val === 'None') { window.alert('Please select the source of this image before uploading.'); return false; } else if ($('#sourceField').val === 'Website' && $('#websiteURL').val === '') { window.alert('Please enter the image source web address before uploading.'); return false; } else if ($('#sourceField').val === 'Game' && $('#gameTitle').val ===  && $('#gameMission').val === ) { window.alert('Please enter the image source game title and mission before uploading.'); return false; } else if ($('#sourceField').val === 'Book' && $('#bookTitle').val ===  && $('#bookPage').val === ) { window.alert('Please enter the image source book title and page(s) before uploading.'); return false; } else if ($('#sourceField').val === 'Other' && $('#otherDescription').val === '') { window.alert('Please enter a short description of the source of this image before uploading.'); return false; } else if ($('#holderField').val === '') { window.alert('Please enter the image\'s coypright holder before uploading.'); return false; } else if ($('#licenseField').val === 'None') { window.alert('Please select the license underwhich this image was taken before uploading.'); return false; }		typeSelected updateCategories updateForm }

//Set form format var subjectContent = ' '	var subjectMaintenance = ' '	var sourceNone = '' var sourceWebsite = ' '	var sourceGame = ' '	var sourceBook = ' '	var sourceOther = ' '	var formLayout = //Type field ' Type: ' + 'None selected ' + 'Screenshot ' + 'Animation ' + 'Concept Art ' + 'Box Art ' + 'Logo ' + 'Icon ' + 'Scan ' + ' '

//Subject field + ' Subject: ' + ' Content</a>  <a class="wikia-button" href="javascript:toggleMaintenance">Maintenance</a>' + ' ' + subjectContent + ' ' + ' '		//Description field + ' <td class="mw-label"><label for="#descriptionField">Description: <td class="mw-input"> ' //Source field + ' <td class="mw-label"><label for="#sourceField">Source: <td class="mw-input"><select id="sourceField" title="What source was this image taken from?" style="width:50%; margin-left:5px;">' + '<option value="None">None selected ' + '<option value="Website">Website ' + '<option value="Game">Game ' + '<option value="Book">Book ' + '<option value="Other">Other ' + ' '		+ ' ' + sourceNone + ' ' + ' '		//Copyright holder field + ' <td class="mw-label"><label for="#holderField">Copyright holder: <td class="mw-input"> ' //License field + ' <td class="mw-label"><label for="#licenseField">Licensing: <td class="mw-input"><select id="licenseField" title="Select the license under which the image was taken." style="width:50%; margin-left:5px;">' + '<option value="None">None selected ' + '<option value="Copyright">Copyright ' + '<option value="Fair Use">Fair Use ' + '<option value="Share Alike">Share Alike ' + '<option value="Public Domain">Public Domain ' + '<option value="Unknown">Unknown ' + ' ';	//Reformat DOM to new form design $('.mw-htmlform-field-Licenses,.mw-label:contains("Summary")').remove $('#mw-htmlform-description').append($('.mw-htmlform-field-HTMLTextAreaField')) $('#wpUploadDescription').attr("cols", 100).attr("rows", 15) $('#wpUploadDescription').parent.attr('colspan', '2') $('#wpUploadDescription').hide $('.mw-htmlform-field-HTMLTextAreaField').children.prepend(' <a class="wikia-button" title="Preview page file mark up code." href="javascript:toggleFilePage">Page Contents</a> ') $('.mw-htmlform-field-HTMLTextField').after(formLayout) //Set up tool tips after DOM $("select,input,.formTextBox,#wpUploadDescription,.wikia-button").tooltip; //Updates on drop-down and checkbox change $("select,input").change(function {		typeSelected		updateCategories		updateForm	}).change; //Changes source input selection $('#sourceField').change(function {		toggleSource		$("select,input,.formTextBox,#wpUploadDescription").tooltip;		if ($('#sourceField').val == 'None') {			updateSource			updateForm		}		$('#websiteURL,#gameTitle,#gameMission,#bookTitle,#bookPage,#otherDescription').on('input', function { updateSource updateForm });	});

//Updates on textbox change $('.formTextBox').on('input', function {		typeSelected		updateCategories		updateForm	}); //Adds auto link complete to textboxes $.getScript(		'/load.php?debug=false&lang=en&mode=articles&skin=oasis&missingCallback=importArticleMissing&articles=u%3Acamtest%3AMediaWiki%3ATextareaHelper.js%7Cu%3Adev%3AColors%2Fcode.js%7Cu%3Adev%3AMiniComplete%2Fcode.js&only=scripts', function {		dev.minicomplete.load( $('#mw-htmlform-description').find('.formTextBox') );	});	//Forces upload warnings if fields are empty $('#wpUploadDescription').closest('form').submit(uploadWarning); }

if (mw.config.get('wgCanonicalSpecialPageName') === 'NewFiles') { //Force page change to Special:Upload on upload click $('.wikia-button.upphotos').click(function {		window.location.href = '/wiki/Special:Upload'	}); }

if (mw.config.get('wgCanonicalSpecialPageName') === 'MultipleUpload') { //Pre-enters image summary template to multiple upload description box multipleLayout = '\n' $('#wpUploadDescription').val(multipleLayout) $('.mw-htmlform-field-Licenses').remove }