MediaWiki:Common.js/FairUseUpload.js

// Just a get it done version

/** * Sets the cookie * @param c_name string Name of the cookie * @param value string 'on' or 'off' * @param expiredays integer Expiry time of the cookie in days */ function setCookie( c_name, value, expiredays ) { var exdate = new Date; exdate.setDate( exdate.getDate + expiredays); document.cookie = c_name + "=" + escape(value) + ( ( expiredays === null ) ? "" : ";expires=" + exdate.toGMTString ); } /** * Gets the cookie * @param c_name string Cookie name * @return The cookie name or empty string */ function getCookie( c_name ) { if ( document.cookie.length > 0 ) { var c_start = document.cookie.indexOf( c_name + "=" ); if ( c_start !== -1 ) { c_start = c_start + c_name.length + 1; var c_end = document.cookie.indexOf( ";", c_start ); if ( c_end === -1 ) { c_end = document.cookie.length; }			return unescape( document.cookie.substring( c_start, c_end ) ); }	}	return ""; }

// Upload form - need to run before adding hide buttons if ( wgCanonicalSpecialPageName === 'Upload' ) { setupUploadForm; }

/** * Start upload form customisations */

function setupUploadForm{ // Check if cookie has been set for form style. Overrides URL parameter if set. var formstyle = getCookie("uploadform");

$("#uploadBasicLinkJS").show; $("#uploadTemplateNoJS").hide;

var wpLicense = $('#wpLicense');

if ( wpLicense.length && window.location.search.indexOf('wpForReUpload=1') == -1){ if (formstyle == "guided" || (formstyle == "" && window.location.search.indexOf('basic=true') == -1)){ // Add link to basic form $("#uploadtext").prepend(' Switch to basic upload form ');

// Stretch table to full width $('#mw-htmlform-description').css('width', '100%');

// Bind upload button to verify function $('#mw-upload-form').bind('submit', verifySummary);

// Hide existing rows var rows = $('#mw-htmlform-description').find('tr'); $('tr.mw-htmlform-field-HTMLTextAreaField').hide; $('tr.mw-htmlform-field-HTMLTextAreaField').next.detach;

$('#mw-htmlform-description').addClass('hidable start-hidden');

// Add new required rows rows.eq(1).after(' Source:  '); $('#mw-htmlform-description').append(' '); var tbody1 = $('#mw-htmlform-description').children('tbody').eq(0); tbody1.append(' Description:  '); tbody1.append(' Optional fields  ');

// Add new optional rows var tbody2 = $('#mw-htmlform-description').children('tbody').eq(1); tbody2.append(' Purpose:  '); tbody2.append(' Portion Used:  '); tbody2.append(' <td class="mw-label" style="width: 125px;">Replaceable?: <td class="mw-input"><textarea id="replaceBox" cols="60" rows="2" style="overflow: auto;"> '); tbody2.append(' <td class="mw-label" style="width: 125px;">Resolution: <td class="mw-input"><textarea id="resolutionBox" cols="60" rows="2" style="overflow: auto;"> '); tbody2.append(' <td class="mw-label" style="width: 125px;">Other Information: <td class="mw-input"><textarea id="otherinfoBox" cols="60" rows="2" style="overflow: auto;"> '); } else { // Old style form just needs Information template in the summary box $('#wpUploadDescription').val('==Summary==\r\n');

// Add link to guided form $("#uploadtext").prepend(' Switch to guided upload form</a> '); } } }

function verifySummary{ var wpLicense = document.getElementById('wpLicense');

// Check for licensing if ( wpLicense.value == "" ){ alert('Licensing must be completed.'); return false; }

// Check for source if ( document.getElementById('sourceBox').value == "" ){ alert('Source must be completed.'); return false; }

// Check for Description if ( document.getElementById('descriptionBox').value == "" ){ alert('Description must be completed.'); return false; }

var strBuilder = '==Summary==\r\n';

document.getElementById('wpUploadDescription').value = strBuilder;

wpLicense.selectedIndex = 0;

return true; }