-function licenseSelectorCheck() {
+window.licenseSelectorCheck = function() {
var selector = document.getElementById( "wpLicense" );
var selection = selector.options[selector.selectedIndex].value;
if( selector.selectedIndex > 0 ) {
}
// We might show a preview
wgUploadLicenseObj.fetchPreview( selection );
-}
+};
-function wgUploadSetup() {
+window.wgUploadSetup = function() {
// Disable URL box if the URL copy upload source type is not selected
- var e = document.getElementById( 'wpSourceTypeURL' );
+ var e = document.getElementById( 'wpSourceTypeurl' );
if( e ) {
if( !e.checked ) {
var ein = document.getElementById( 'wpUploadFileURL' );
}
}
- // Toggle source type
- var sourceTypeCheckboxes = document.getElementsByName( 'wpSourceType' );
- for ( var i = 0; i < sourceTypeCheckboxes.length; i++ ) {
- sourceTypeCheckboxes[i].onchange = toggleUploadInputs;
- }
// AJAX wpDestFile warnings
if ( wgAjaxUploadDestCheck ) {
+ // Insert an event handler that fetches upload warnings when wpDestFile
+ // has been changed
document.getElementById( 'wpDestFile' ).onchange = function ( e ) {
wgUploadWarningObj.checkNow(this.value);
};
+ // Insert a row where the warnings will be displayed just below the
+ // wpDestFile row
var optionsTable = document.getElementById( 'mw-htmlform-description' ).tBodies[0];
- var row = document.createElement( 'tr' );
+ var row = optionsTable.insertRow( 1 );
var td = document.createElement( 'td' );
td.id = 'wpDestFile-warning';
td.colSpan = 2;
row.appendChild( td );
- optionsTable.insertBefore( row, optionsTable.children[1] );
}
- if ( wgAjaxLicensePreview ) {
+ var wpLicense = document.getElementById( 'wpLicense' );
+ if ( wgAjaxLicensePreview && wpLicense ) {
// License selector check
- document.getElementById( 'wpLicense' ).onchange = licenseSelectorCheck;
+ wpLicense.onchange = licenseSelectorCheck;
// License selector table row
- var wpLicense = document.getElementById( 'wpLicense' );
var wpLicenseRow = wpLicense.parentNode.parentNode;
var wpLicenseTbody = wpLicenseRow.parentNode;
document.getElementById( wgUploadSourceIds[i] ).onchange = function (e) {
fillDestFilename( this.id );
};
-}
-
-/**
- * Iterate over all upload source fields and disable all except the selected one.
- *
- * @param enabledId The id of the selected radio button
- * @return emptiness
- */
-function toggleUploadInputs() {
- // Iterate over all rows with UploadSourceField
- var rows;
- if ( document.getElementsByClassName ) {
- rows = document.getElementsByClassName( 'mw-htmlform-field-UploadSourceField' );
- } else {
- // Older browsers don't support getElementsByClassName
- rows = new Array();
-
- var allRows = document.getElementsByTagName( 'tr' );
- for ( var i = 0; i < allRows.length; i++ ) {
- if ( allRows[i].className == 'mw-htmlform-field-UploadSourceField' )
- rows.push( allRows[i] );
- }
- }
-
- for ( var i = 0; i < rows.length; i++ ) {
- var inputs = rows[i].getElementsByTagName( 'input' );
-
- // Check if this row is selected
- var isChecked = true; // Default true in case wpSourceType is not found
- for ( var j = 0; j < inputs.length; j++ ) {
- if ( inputs[j].name == 'wpSourceType' )
- isChecked = inputs[j].checked;
- }
-
- // Disable all unselected rows
- for ( var j = 0; j < inputs.length; j++ ) {
- if ( inputs[j].type != 'radio')
- inputs[j].disabled = !isChecked;
- }
- }
-}
+};
-var wgUploadWarningObj = {
+
+window.wgUploadWarningObj = {
'responseCache' : { '' : ' ' },
'nameToCheck' : '',
'typing': false,
element.innerHTML = text;
}
}
-}
+};
-function fillDestFilename(id) {
+window.fillDestFilename = function(id) {
if (!wgUploadAutoFill) {
return;
}
// Clear the filename if it does not have a valid extension.
// URLs are less likely to have a useful extension, so don't include them in the
// extension check.
- if( wgFileExtensions && id != 'wpUploadFileURL' ) {
+ if( wgStrictFileExtensions && wgFileExtensions && id != 'wpUploadFileURL' ) {
var found = false;
if( fname.lastIndexOf( '.' ) != -1 ) {
var ext = fname.substr( fname.lastIndexOf( '.' ) + 1 );
if( e ) e.className = 'error';
// Clear wpDestFile as well
- var e = document.getElementById( 'wpDestFile' )
+ var e = document.getElementById( 'wpDestFile' );
if( e ) e.value = '';
return false;
}
}
- // Capitalise first letter and replace spaces by underscores
- // FIXME: $wgCapitalizedNamespaces
- fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
+ // Replace spaces by underscores
+ fname = fname.replace( / /g, '_' );
+ // Capitalise first letter if needed
+ if ( wgCapitalizeUploads ) {
+ fname = fname.charAt( 0 ).toUpperCase().concat( fname.substring( 1, 10000 ) );
+ }
// Output result
var destFile = document.getElementById('wpDestFile');
destFile.value = fname;
wgUploadWarningObj.checkNow(fname) ;
}
-}
+};
-function toggleFilenameFiller() {
+window.toggleFilenameFiller = function() {
if(!document.getElementById) return;
var upfield = document.getElementById('wpUploadFile');
var destName = document.getElementById('wpDestFile').value;
- if (destName=='' || destName==' ') {
- wgUploadAutoFill = true;
- } else {
- wgUploadAutoFill = false;
- }
-}
+ wgUploadAutoFill = ( destName == '' || destName == ' ' );
+};
-var wgUploadLicenseObj = {
+window.wgUploadLicenseObj = {
'responseCache' : { '' : '' },
previewPanel.innerHTML = preview;
}
-}
+};
addOnloadHook( wgUploadSetup );