Commons:Upload Wizard feedback/Archive/2016/12

From Wikimedia Commons, the free media repository
Jump to: navigation, search
Archive This is an archive of past discussions. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page.

Multilingual & description fields

Hi, As I am active in multiple languages and live in an area where multiple languages are used, I like to have the upload wizard show always 3 description fields in these preferred languages. Is there some code for my .js or .css to get this done somehow. It was possible in the older upload tool. Thanks! Romaine (talk) 01:13, 9 December 2016 (UTC)

@Romaine: I just wrote a small, slightly hacky script to do this. You can paste the following into your common.js page (customize the languages at the top). If you ever run into problems with UploadWizard, please remember than you're using this, it depends on some internal functions that may some day change (although unlikely to happen soon). Matma Rex (talk) 23:14, 9 December 2016 (UTC)
( function () {
	// Display multiple empty descriptions by default in UploadWizard, not just one.

	// Customize these to your liking
	var myLanguages = [ 'nl', 'en', 'de' ];

	// If this is Special:UploadWizard
	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'UploadWizard' ) {
		// Wait for UploadWizard to load
		mw.loader.using( 'ext.uploadWizard' ).done( function () {
			// Override the function which normally prefills descriptions from image metadata
			var prefillDescription = mw.UploadWizardDetails.prototype.prefillDescription;
			mw.UploadWizardDetails.prototype.prefillDescription = function () {
				// Call overridden function
				prefillDescription.call( this, arguments );
				// Get the prefilled descriptions, if any
				var data = this.descriptionsDetails.getSerialized();
				for ( var i = 0; i < myLanguages.length; i++ ) {
					if ( data.descriptions[ i ] ) {
						// Change the language if this description already exists
						data.descriptions[ i ].language = myLanguages[ i ];
					} else {
						// Add empty descriptions in remaining languages
						data.descriptions.push( {
							language: myLanguages[ i ],
							description: ''
						} );
					}
				}
				// Set updated descriptions
				this.descriptionsDetails.setSerialized( data );
			};
		} );
	}

} )();
Matma Rex (talk) 23:14, 9 December 2016 (UTC)
Hi Matma Rex, Thanks! Romaine (talk) 01:01, 12 December 2016 (UTC)