( function ( $, mw ) { var msuVars = mw.config.get( 'msuVars' ); var MsUpload = { fileError: function ( uploader, file, errorText ) { file.li.warning.text( errorText ); file.li.addClass( 'yellow' ); file.li.type.addClass( 'error' ); file.li.click( function () { // Remove li at click file.li.fadeOut( 'fast', function () { $( this ).remove(); uploader.trigger( 'CheckFiles' ); } ); } ); }, galleryArray: [], insertGallery: function () { var galleryText = 'File:' + MsUpload.galleryArray.join( '\nFile:' ); MsUpload.insertText( '\n' + galleryText + '\n\n' ); }, filesArray: [], insertFiles: function () { MsUpload.insertText( '[[File:' + MsUpload.filesArray.join( ']]\n[[File:' ) + ']]\n' ); }, insertLinks: function () { if ( msuVars.useMsLinks === true ) { MsUpload.insertText( '*{{#l:' + MsUpload.filesArray.join( '}}\n*{{#l:' ) + '}}\n' ); } else { MsUpload.insertText( '*[[:File:' + MsUpload.filesArray.join( ']]\n*[[:File:' ) + ']]\n' ); } }, /** * Add text to selection in the main textarea. * * @param {string} text */ insertText: function ( text ) { $( '#wpTextbox1' ).textSelection( 'encapsulateSelection', { pre: text } ); }, unconfirmedReplacements: 0, warningText: function ( fileItem, warning, uploader ) { switch ( warning ) { case '': case ' ': case ' ': $( fileItem.warning ).empty() .siblings( '.file-name' ).show() .siblings( '.file-name-input' ).hide() .siblings( '.file-extension' ).hide(); break; case 'Error: Unknown result from API': case 'Error: Request failed': $( fileItem.warning ).text( warning ); break; default: // IMPORTANT! The code below assumes that every warning not captured by the code above is about a file being replaced $( fileItem.warning ).html( warning ); // We break when the particula warning when a file name starts with IMG if ( warning.indexOf( 'The name of the file you are uploading begins with' ) === 0 ) { break; // When the file name starts with "IMG", MediaWiki issues this warning. Display it and continue. } if ( warning.indexOf( 'Der Dateiname beginnt mit' ) === 0 ) { break; // Make it work for German too. Must be done this way because the error response doesn't include an error code. } // When hovering over the link to the file about to be replaced, show the thumbnail $( fileItem.warning ).find( 'a' ).mouseover( function () { $( fileItem.warning ).find( 'div.thumb' ).show(); } ).mouseout( function () { $( fileItem.warning ).find( 'div.thumb' ).hide(); } ); /** * If a file with the same name already exists, add a checkbox to confirm the replacement * This checkbox will also appear when the file name differs only in the file extension * so the confirmation message must be kept generic enough */ if ( msuVars.confirmReplace ) { MsUpload.unconfirmedReplacements++; var title = $( fileItem.warning ).siblings( '.file-name' ); var checkbox = $( '' ).attr( 'type', 'checkbox' ).click( function () { if ( $( this ).is( ':checked' ) ) { title.show().next().hide(); MsUpload.unconfirmedReplacements--; } else { title.hide().next().show().select(); MsUpload.unconfirmedReplacements++; } uploader.trigger( 'CheckFiles' ); } ); $( '