User:Flominator/Replace umlauts before upload

From MediaWiki.org
Jump to navigation Jump to search

Insert this function into MediaWiki:Monobook.js or MediaWiki:Common.js in ordner to rename files with German umlauts before uploading them.

 function fillDestFilename() {
 	if (!document.getElementById)
 		return;
 	var path = document.getElementById('wpUploadFile').value;
 	// Find trailing part
 	var slash = path.lastIndexOf('/');
 	var backslash = path.lastIndexOf('\\');
 	var fname;
 	if (slash == -1 && backslash == -1) {
 		fname = path;
 	} else if (slash > backslash) {
 		fname = path.substring(slash+1, 10000);
 	} else {
 		fname = path.substring(backslash+1, 10000);
 	}
 
 	// Capitalise first letter and replace spaces by underscores
 	fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');

 	//Replace umlauts and stuff by ascii-characters
 	fname = fname.replace(/Ä/g, 'Ae');
 	fname = fname.replace(/Ö/g, 'Oe');
 	fname = fname.replace(/Ü/g, 'Ue');
 	fname = fname.replace(/ä/g, 'ae');
 	fname = fname.replace(/ö/g, 'oe');
 	fname = fname.replace(/ü/g, 'ue'); 	
 	fname = fname.replace(/ß/g, 'ss'); 	
 	fname = fname.replace(/§/g, 'Paragraph'); 
 	fname = fname.replace(/“/g, ''); 
 	fname = fname.replace(/”/g, ''); 
 	fname = fname.replace(/„/g, ''); 
 	fname = fname.replace(/‘/g, ''); 
 	fname = fname.replace(/’/g, ''); 
 	fname = fname.replace(/‚/g, ''); 
 	fname = fname.replace(/«/g, ''); 
 	fname = fname.replace(/»/g, ''); 
 	fname = fname.replace(/€/g, 'Euro'); 
	fname = fname.replace(/–/g, '-'); 
	fname = fname.replace(/¯/g, '-'); 
	fname = fname.replace(/—/g, '-'); 

 	// Output result
	var destFile = document.getElementById('wpDestFile');
 	if (destFile)
 		destFile.value = fname;

 }

Keywords: Upload - Dateien umbenennen - Umlaute - Paragraph - Sonderzeichen - Hochladen