"Wikitravel has a speed and convenience the books' publishers can only envy." Time Europe

Tech:Disable Upload file button until a license selected

From Wikitravel Shared
Jump to: navigation, search

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)

Scripts[edit]

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.

licenseSelectorCheck[edit]

Check selection and perform removeAttribute/setAttribute here, since this function is invoked at "onchange" attribute of "select" element.

current script[edit]


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 );
}

new script[edit]

Difference


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 );
}

licenseSelectorFixup[edit]

Perform setAttribute here at the time page loaded, since this function is set at "addOnloadHook" of the js file.

current script[edit]


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;
			}
		}
	}
}

new script[edit]

Difference


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");
}

After implementation[edit]

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;

  1. 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.
  2. 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)

Additional comments[edit]

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)

See also[edit]

Variants

Actions

In other languages