Do r91966 in a different way, per Brion: use unicode-bidi:embed; instead of white...
[lhc/web/wiklou.git] / skins / common / upload.js
index 3e91e06..99917c7 100644 (file)
@@ -1,4 +1,4 @@
-function licenseSelectorCheck() {
+window.licenseSelectorCheck = function() {
        var selector = document.getElementById( "wpLicense" );
        var selection = selector.options[selector.selectedIndex].value;
        if( selector.selectedIndex > 0 ) {
@@ -9,11 +9,11 @@ function licenseSelectorCheck() {
        }
        // 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' );
@@ -34,9 +34,55 @@ function wgUploadSetup() {
                        }
                }
        }
-}
+       
+       
+       // 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 = optionsTable.insertRow( 1 );
+               var td = document.createElement( 'td' );
+               td.id = 'wpDestFile-warning';
+               td.colSpan = 2;
+               
+               row.appendChild( td );
+       }
+       
+       var wpLicense = document.getElementById( 'wpLicense' );
+       if ( wgAjaxLicensePreview && wpLicense ) {
+               // License selector check
+               wpLicense.onchange = licenseSelectorCheck;
+       
+               // License selector table row
+               var wpLicenseRow = wpLicense.parentNode.parentNode;
+               var wpLicenseTbody = wpLicenseRow.parentNode;
+               
+               var row = document.createElement( 'tr' );
+               var td = document.createElement( 'td' );
+               row.appendChild( td );
+               td = document.createElement( 'td' );
+               td.id = 'mw-license-preview';
+               row.appendChild( td );
+               
+               wpLicenseTbody.insertBefore( row, wpLicenseRow.nextSibling );
+       }
+       
+       
+       // fillDestFile setup
+       for ( var i = 0; i < wgUploadSourceIds.length; i++ )
+               document.getElementById( wgUploadSourceIds[i] ).onchange = function (e) {
+                       fillDestFilename( this.id );
+               };
+};
+
 
-var wgUploadWarningObj = {
+window.wgUploadWarningObj = {
        'responseCache' : { '' : '&nbsp;' },
        'nameToCheck' : '',
        'typing': false,
@@ -86,7 +132,7 @@ var wgUploadWarningObj = {
                // ajax requests can be supported.
                var obj = this;
                var fileName = this.nameToCheck;
-               sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck],
+               sajax_do_call( 'SpecialUpload::ajaxGetExistsWarning', [this.nameToCheck],
                        function (result) {
                                obj.processResult(result, fileName)
                        }
@@ -101,16 +147,18 @@ var wgUploadWarningObj = {
 
        'setWarning' : function (warning) {
                var warningElt = document.getElementById( 'wpDestFile-warning' );
-               var ackElt = document.getElementById( 'wpDestFileWarningAck' );
-               this.setInnerHTML(warningElt, warning);
+               var ackElt = document.getElementsByName( 'wpDestFileWarningAck' );
 
+               this.setInnerHTML(warningElt, warning);
+               
                // Set a value in the form indicating that the warning is acknowledged and
                // doesn't need to be redisplayed post-upload
                if ( warning == '' || warning == '&nbsp;' ) {
-                       ackElt.value = '';
+                       ackElt[0].value = '';
                } else {
-                       ackElt.value = '1';
+                       ackElt[0].value = '1';
                }
+
        },
        'setInnerHTML' : function (element, text) {
                // Check for no change to avoid flicker in IE 7
@@ -118,9 +166,9 @@ var wgUploadWarningObj = {
                        element.innerHTML = text;
                }
        }
-}
+};
 
-function fillDestFilename(id) {
+window.fillDestFilename = function(id) {
        if (!wgUploadAutoFill) {
                return;
        }
@@ -150,7 +198,7 @@ function fillDestFilename(id) {
        // 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 );
@@ -172,15 +220,19 @@ function fillDestFilename(id) {
                        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
-       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');
@@ -188,25 +240,21 @@ function fillDestFilename(id) {
                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' : { '' : '' },
 
        'fetchPreview': function( license ) {
-               if( !wgAjaxLicensePreview || !sajax_init_object() ) return;
+               if( !wgAjaxLicensePreview ) return;
                for (cached in this.responseCache) {
                        if (cached == license) {
                                this.showPreview( this.responseCache[license] );
@@ -214,17 +262,29 @@ var wgUploadLicenseObj = {
                        }
                }
                injectSpinner( document.getElementById( 'wpLicense' ), 'license' );
-               sajax_do_call( 'UploadForm::ajaxGetLicensePreview', [license],
-                       function( result ) {
-                               wgUploadLicenseObj.processResult( result, license );
-                       }
-               );
+               
+               var title = document.getElementById('wpDestFile').value;
+               if ( !title ) title = 'File:Sample.jpg';
+               
+               var url = wgScriptPath + '/api' + wgScriptExtension
+                       + '?action=parse&text={{' + encodeURIComponent( license ) + '}}'
+                       + '&title=' + encodeURIComponent( title ) 
+                       + '&prop=text&pst&format=json';
+               
+               var req = sajax_init_object();
+               req.onreadystatechange = function() {
+                       if ( req.readyState == 4 && req.status == 200 )
+                               wgUploadLicenseObj.processResult( eval( '(' + req.responseText + ')' ), license );
+               };
+               req.open( 'GET', url, true );
+               req.send( '' );
        },
 
        'processResult' : function( result, license ) {
                removeSpinner( 'license' );
-               this.showPreview( result.responseText );
-               this.responseCache[license] = result.responseText;
+               this.responseCache[license] = result['parse']['text']['*'];
+               this.showPreview( this.responseCache[license] );
+
        },
 
        'showPreview' : function( preview ) {
@@ -233,6 +293,6 @@ var wgUploadLicenseObj = {
                        previewPanel.innerHTML = preview;
        }
 
-}
+};
 
 addOnloadHook( wgUploadSetup );