Topic on Extension talk:MultiUpload

Show only the first file and up to max

5
P858snake (talkcontribs)

Just add the below to multiupload.js and you are ready to go.

// should probably be in i18n
wgAddMoreName = 'Add next file'; // en
//wgAddMoreName = 'Dodaj następny plik'; // pl
/**
 * Enable showing one file at first and add more
 *
 * This will hide all files input but the first one
 * and will add an add more button.
 *
 * @note $wgMaxUploadFiles param sets maximum number of files uploaded at once
 */
function wgUploadHideSetup() {
	var eRows;
	try {
		eRows = document.getElementById( 'mw-htmlform-source' ).getElementsByTagName('tr');
	} catch (e) {
		return;
	}
	if( eRows ) {
		//
		// get rows array
		//
		var arrRows = new Array();
		var iLastRow;
		var oRow = new Object();
		for (var i=0; i<eRows.length; i++) {
			var e = eRows[i];
			if (e.className.search(/(^| )mw-htmlform-field-UploadSourceField( |$)/)>=0) {
				oRow.rIn = e;
				iLastRow = i;
			} else if (e.className.search(/(^| )mw-htmlform-field-HTMLTextField( |$)/)>=0) {
				oRow.rOut = e;
				iLastRow = i;
				arrRows.push(oRow);
				oRow = new Object();
			}
		}
		
		if (arrRows.length <= 0)
		{
			if (typeof(console) != 'undefined' && typeof(console.log) == 'function')
			{
				console.log ('wgUploadHideSetup: no form fields found - class name changed?');
			}
			return;
		}
		
		//
		// hide all but first
		//
		var strRowNormalDisplay = arrRows[0].rIn.style.display;
		for (var i=1; i<arrRows.length; i++) {
			arrRows[i].rIn.style.display = 'none';
			arrRows[i].rOut.style.display = 'none';
		}
		
		//
		// add button
		//
		// cells
		var nel = document.createElement('tr');
		var nelTd = document.createElement('td');
		nel.appendChild(nelTd);
		nelTd = document.createElement('td');
		nel.appendChild(nelTd);
		// the button
		var nelInp = document.createElement('input');
		nelInp.setAttribute('type', 'button');
		var lastVisible = 0;
		nelInp.onclick = function () {
			if (lastVisible<arrRows.length-1) {
				lastVisible++;
				arrRows[lastVisible].rIn.style.display = strRowNormalDisplay;
				arrRows[lastVisible].rOut.style.display = strRowNormalDisplay;
			}
			if (lastVisible>=arrRows.length-1) {
				this.style.display = 'none';
			}
		}
		nelInp.value = wgAddMoreName;
		nelTd.appendChild(nelInp);
		if (iLastRow == eRows.length-1) {
			eRows[iLastRow].parentNode.appendChild(nel);
		} else {
			eRows[iLastRow+1].parentNode.insertBefore(nel, eRows[iLastRow+1]);
		}
	}
}
addOnloadHook( wgUploadHideSetup );

Regards,

This post was posted by Peachey88, but signed as Nux.

62.159.77.166 (talkcontribs)

Just edited (added the hide-setup function behind the normal setup) multiupload.js but did not affected anything. I still have my maxupload fields (I use default which is 5- therfore not explicit value in wgMaxUpload in LocalSettings). I wanted to try that to see if i can get rid of the warnings in case you only upload one and not the max number allowed.

Is adding the function to multiupload.js the really the only thing to do?

Teststudent (talkcontribs)

I must be missing something here. I appended the above code to the end of the .js but I didn't see what apparently is working... am I supposed to search and replace? Or is there a specific line it should be inserted at?

Nux (talkcontribs)

Fixed above. As seems HTML changed. And yes - you just paste the code at the end of "multiupload.js" (this is AFTER `addOnloadHook( wgUploadSetup );`).

Reply to "Show only the first file and up to max"