MediaWiki:Gadget-UploadValidation.js: Difference between revisions
Jump to navigation
Jump to search
KokoroSenshi (talk | contribs) (Adjusted according to rename to Upload Validation and added 'Temporary upload-related things' from Common.js (the Required attribute for Source)) |
(Commenting out sections that are now counterproductive or are now not applicable) |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 12: | Line 12: | ||
//Add space preceding text in Desc and Source | //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 | //Make file extension lowercase | ||
var fileName = $('#wpDestFile').val() | var fileName = $('#wpDestFile').val() | ||
, ext = fileName.substring(fileName.lastIndexOf( | , ext = fileName.substring(fileName.lastIndexOf('.')+1).toLowerCase(); | ||
$('#wpDestFile').val( fileName.slice(0, -1*ext.length) + ext ); | $('#wpDestFile').val( fileName.slice(0, -1*ext.length) + ext ); | ||
}); | }); | ||
//Add the html5 'required' attribute to the Source field on Special:Upload | //Add the html5 'required' property and 'pattern' attribute to the Source field on Special:Upload | ||
// $('#mw-input-source').prop('required', true).attr('pattern', '.*\\S.*'); | |||
//Add helpful | //Add helpful links to Guidelines:Files | ||
// $('label[for=mw-input-source]').html('Source (<a href="/Guidelines:Files#Sourcing" target="_blank" title="Guidelines:Files">help</a>)'); | |||
// $('label[for=mw-input-subject]').html('Subject (<a href="/Guidelines:Files#Subject" target="_blank" title="Guidelines:Files">help</a>)'); | |||
} | } | ||
if ( mw.config.get( | if ( mw.config.get('wgPageName') === 'Special:Upload' ) { | ||
$( upload_validation() ); | $( upload_validation() ); | ||
} | } |
Latest revision as of 09:26, 6 March 2023
// --------------------------------------------------
// 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' property and 'pattern' attribute to the Source field on Special:Upload
// $('#mw-input-source').prop('required', true).attr('pattern', '.*\\S.*');
//Add helpful links to Guidelines:Files
// $('label[for=mw-input-source]').html('Source (<a href="/Guidelines:Files#Sourcing" target="_blank" title="Guidelines:Files">help</a>)');
// $('label[for=mw-input-subject]').html('Subject (<a href="/Guidelines:Files#Subject" target="_blank" title="Guidelines:Files">help</a>)');
}
if ( mw.config.get('wgPageName') === 'Special:Upload' ) {
$( upload_validation() );
}