User:Dschwen/checklicense.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
Documentation for this user script can be added at User:Dschwen/checklicense. |
- Report page listing warnings and errors.
//
// licenseChecker
// checks whether the selected license on Special:Upload is valid
// and provides feedback
//
// Maintainer: [[User:Dschwen]]
//
var licenseChecker =
{
//
// List of invalid licenses
//
invalid : [ "subst:nld",
"subst:template 2|cc-by-nc-sa-2.0|flickrreview",
"subst:template 2|flickrreview|subst:nld" ],
//
// Translations of the warning message
//
i18n :
{
'de': 'Die ausgewählte <b>Lizenz ist nicht akzeptabel für Wikimedia Commons</b>. Dein <b>Upload wird gelöscht</b> werden!',
'en': 'The selected licensing is <b>unacceptable on Wikimedia Commons</b> and will lead to the <b>deletion</b> of your upload!'
},
licensemenu : null,
warnbanner : null,
message : '',
// cross-browser event attachment (John Resig)
// http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
addEvent : function ( obj, type, fn )
{
if (obj.addEventListener)
obj.addEventListener( type, fn, false );
else if (obj.attachEvent)
{
obj["e"+type+fn] = fn;
obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
obj.attachEvent( "on"+type, obj[type+fn] );
}
},
// Event handler for the license selector
check : function()
{
with(licenseChecker) {
for( var n in invalid )
if( licensemenu.value == invalid[n] )
{
warnbanner.innerHTML = message;
return;
}
warnbanner.innerHTML = '';
}
},
install : function()
{
if(window.location.href == "http://commons.wikimedia.org/wiki/Special:Upload")
{
with(licenseChecker) {
warnbanner = document.createElement('DIV');
warnbanner.className = 'center';
warnbanner.style.color = 'red';
warnbanner.style.background = '#eeeeee';
var uploadtext = document.getElementById('uploadtext');
// Check for skins not providing the uploadtext ID
if( typeof(uploadtext) == 'undefined' ) return;
uploadtext.appendChild( warnbanner );
if( typeof(i18n[mw.config.get('wgUserLanguage')]) == 'string' )
message = i18n[mw.config.get('wgUserLanguage')];
else
message = i18n.en;
licensemenu = document.getElementById('wpLicense');
addEvent( licensemenu , 'change', check );
}
}
}
}
$( licenseChecker.install );