MediaWiki:Gadget-UploadValidation.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// --------------------------------------------------
// Upload Validation
// Includes:
// Force lowercase file extensions - This ensures uploaded files have their extension in lowercase
// Make the Source required
// Add a space before Desc and Source for after the equals signs in the output template (temp)
// --------------------------------------------------
function upload_validation() {
$('#mw-upload-form').on('submit', function(){
//Add space preceding text in Desc and Source
$('#mw-input-source, #wpUploadDescription').each(function() {
var valFirstChar = $(this).val().charAt(0);
if (valFirstChar !== '' && valFirstChar !== ' ')
$(this).val( ' ' + $(this).val() );
});
//Make file extension lowercase
var fileName = $('#wpDestFile').val()
, ext = fileName.substring(fileName.lastIndexOf('.')+1).toLowerCase();
$('#wpDestFile').val( fileName.slice(0, -1*ext.length) + ext );
});
//Add the html5 'required' attribute to the Source field on Special:Upload
$('#mw-input-source').prop('required', true);
//Add helpful link to Help:Upload#Source
$('label[for=mw-input-source]').html('Source (<a href="/Help:Upload#Source" target="_blank" title="Help:Upload">help</a>)');
}
if ( mw.config.get('wgPageName') === 'Special:Upload' ) {
$( upload_validation() );
}