please give your consent or refusal here.
Tech:Disable Upload file button until a license selected
From Wikitravel Shared
Contents
To force uploaders to select a license, modify upload.js to disable "Upload file" button on Special:Upload until a license selected.
I asked comments on this at Wikitravel Shared:Travellers' pub#Enforcement a license selection and waited for a week. As of now, it seems like there's no objection. -- Tatata 02:12, 16 June 2009 (EDT)
[edit] Scripts
This modification consists of adding several lines to two functions of upload.js; please see sections below. I tested it with Firefox, Internet Explorer and Safari as a local file on my Windows pc.
[edit] licenseSelectorCheck
Check selection and perform removeAttribute/setAttribute here, since this function is invoked at "onchange" attribute of "select" element.
[edit] current script
function licenseSelectorCheck() {
var selector = document.getElementById( "wpLicense" );
var selection = selector.options[selector.selectedIndex].value;
if( selector.selectedIndex > 0 ) {
if( selection == "" ) {
// Option disabled, but browser is broken and doesn't respect this
selector.selectedIndex = 0;
}
}
// We might show a preview
wgUploadLicenseObj.fetchPreview( selection );
}
[edit] new script
function licenseSelectorCheck() {
var selector = document.getElementById( "wpLicense" );
var selection = selector.options[selector.selectedIndex].value;
var uploadbutton = document.getElementsByName( "wpUpload" ).item(0);
if( selector.selectedIndex > 0 ) {
uploadbutton.removeAttribute("disabled");
if( selection == "" ) {
// Option disabled, but browser is broken and doesn't respect this
selector.selectedIndex = 0;
}
}
else {
uploadbutton.setAttribute("disabled", "disabled");
}
// We might show a preview
wgUploadLicenseObj.fetchPreview( selection );
}
[edit] licenseSelectorFixup
Perform setAttribute here at the time page loaded, since this function is set at "addOnloadHook" of the js file.
[edit] current script
function licenseSelectorFixup() {
// for MSIE/Mac; non-breaking spaces cause the <option> not to render
// but, for some reason, setting the text to itself works
var selector = document.getElementById("wpLicense");
if (selector) {
var ua = navigator.userAgent;
var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1);
if (isMacIe) {
for (var i = 0; i < selector.options.length; i++) {
selector.options[i].text = selector.options[i].text;
}
}
}
}
[edit] new script
function licenseSelectorFixup() {
// for MSIE/Mac; non-breaking spaces cause the <option> not to render
// but, for some reason, setting the text to itself works
var selector = document.getElementById("wpLicense");
if (selector) {
var ua = navigator.userAgent;
var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1);
if (isMacIe) {
for (var i = 0; i < selector.options.length; i++) {
selector.options[i].text = selector.options[i].text;
}
}
}
var uploadbutton = document.getElementsByName( "wpUpload" ).item(0);
uploadbutton.setAttribute("disabled", "disabled");
}
[edit] After implementation
After implementation, "Upload file" button will always be disabled on language versions which don't have MediaWiki:Licenses. In that case, we have two choices;
- lead uploaders to shared by hiding a link to local Special:Upload page in toolbox and adding a link to shared with "Upload file" label in navigation box.
- prepare licensing templates and create MediaWiki:Licenses.
If there are language versions without active admins, we can leave messages to Travellers' pub of those language versions. So, that case is not a problem. -- Tatata 02:12, 16 June 2009 (EDT)
[edit] Additional comments
Yes, yes and yes! This would be a fantastic way to handle licensing issues. Perhaps we should start now with encouraging other language versions to remove their upload link and point to shared, as we did on :en? I've done this on :hi already too – cacahuate talk 18:57, 16 June 2009 (EDT)
- We should, but it might be nice to get language portals in place first, so non-English speakers can still contribute images. --Peter Talk 21:48, 16 June 2009 (EDT)
[edit] See also
- Tech:Make uploads ccbysa1.0 by default – for an earlier discussion that lead here

