Merge "Use wfResetOutputBuffers in ResourceLoader"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 18 Sep 2013 17:01:20 +0000 (17:01 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 18 Sep 2013 17:01:20 +0000 (17:01 +0000)
.jshintignore
includes/Exception.php
includes/job/jobs/RefreshLinksJob.php
includes/resourceloader/ResourceLoader.php
resources/mediawiki.api/mediawiki.api.category.js
resources/mediawiki.api/mediawiki.api.edit.js
resources/mediawiki.api/mediawiki.api.parse.js
resources/mediawiki.api/mediawiki.api.watch.js
skins/common/upload.js

index 5fbbf81..bc10ad8 100644 (file)
@@ -28,7 +28,6 @@ resources/jquery.chosen/chosen.jquery.js
 # legacy scripts
 skins/common/IEFixes.js
 skins/common/config.js
-skins/common/upload.js
 
 # github.com/jshint/jshint/issues/729
 tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js
index dc1208a..e1bfb2d 100644 (file)
@@ -247,16 +247,9 @@ class MWException extends Exception {
         * It will be either HTML or plain text based on isCommandLine().
         */
        function report() {
-               global $wgLogExceptionBacktrace, $wgMimeType;
-               $log = $this->getLogMessage();
+               global $wgMimeType;
 
-               if ( $log ) {
-                       if ( $wgLogExceptionBacktrace ) {
-                               wfDebugLog( 'exception', $log . "\n" . $this->getTraceAsString() . "\n" );
-                       } else {
-                               wfDebugLog( 'exception', $log );
-                       }
-               }
+               $this->logException();
 
                if ( defined( 'MW_API' ) ) {
                        // Unhandled API exception, we can't be sure that format printer is alive
@@ -273,6 +266,22 @@ class MWException extends Exception {
                }
        }
 
+       /**
+        * Log the error message to the exception log (if enabled)
+        */
+       function logException() {
+               global $wgLogExceptionBacktrace;
+
+               $log = $this->getLogMessage();
+               if ( $log ) {
+                       if ( $wgLogExceptionBacktrace ) {
+                               wfDebugLog( 'exception', $log . "\n" . $this->getTraceAsString() . "\n" );
+                       } else {
+                               wfDebugLog( 'exception', $log );
+                       }
+               }
+       }
+
        /**
         * Check whether we are in command line mode or not to report the exception
         * in the correct format.
index 474212b..4fc8bac 100644 (file)
@@ -48,7 +48,7 @@ class RefreshLinksJob extends Job {
                # Wait for the DB of the current/next slave DB handle to catch up to the master.
                # This way, we get the correct page_latest for templates or files that just changed
                # milliseconds ago, having triggered this job to begin with.
-               if ( !empty( $this->params['masterPos'] ) ) {
+               if ( isset( $this->params['masterPos'] ) && $this->params['masterPos'] !== false ) {
                        wfGetLB()->waitFor( $this->params['masterPos'] );
                }
 
index 29946dc..704d781 100644 (file)
@@ -177,6 +177,7 @@ class ResourceLoader {
                        // Save filtered text to Memcached
                        $cache->set( $key, $result );
                } catch ( Exception $exception ) {
+                       $exception->logException();
                        wfDebugLog( 'resourceloader', __METHOD__ . ": minification failed: $exception" );
                        $this->hasErrors = true;
                        // Return exception as a comment
@@ -474,6 +475,7 @@ class ResourceLoader {
                try {
                        $this->preloadModuleInfo( array_keys( $modules ), $context );
                } catch ( Exception $e ) {
+                       $e->logException();
                        wfDebugLog( 'resourceloader', __METHOD__ . ": preloading module info failed: $e" );
                        $this->hasErrors = true;
                        // Add exception to the output as a comment
@@ -493,6 +495,7 @@ class ResourceLoader {
                                // Calculate maximum modified time
                                $mtime = max( $mtime, $module->getModifiedTime( $context ) );
                        } catch ( Exception $e ) {
+                               $e->logException();
                                wfDebugLog( 'resourceloader', __METHOD__ . ": calculating maximum modified time failed: $e" );
                                $this->hasErrors = true;
                                // Add exception to the output as a comment
@@ -719,6 +722,7 @@ class ResourceLoader {
                        try {
                                $blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() );
                        } catch ( Exception $e ) {
+                               $e->logException();
                                wfDebugLog( 'resourceloader', __METHOD__ . ": pre-fetching blobs from MessageBlobStore failed: $e" );
                                $this->hasErrors = true;
                                // Add exception to the output as a comment
@@ -826,6 +830,7 @@ class ResourceLoader {
                                                break;
                                }
                        } catch ( Exception $e ) {
+                               $e->logException();
                                wfDebugLog( 'resourceloader', __METHOD__ . ": generating module package failed: $e" );
                                $this->hasErrors = true;
                                // Add exception to the output as a comment
index 8bba1fc..98a9c54 100644 (file)
@@ -16,9 +16,9 @@
                isCategory: function ( title, ok, err ) {
                        var d = $.Deferred(),
                                apiPromise;
+
                        // Backwards compatibility (< MW 1.20)
-                       d.done( ok );
-                       d.fail( err );
+                       d.done( ok ).fail( err );
 
                        apiPromise = this.get( {
                                        prop: 'categoryinfo',
@@ -53,9 +53,9 @@
                getCategoriesByPrefix: function ( prefix, ok, err ) {
                        var d = $.Deferred(),
                                apiPromise;
+
                        // Backwards compatibility (< MW 1.20)
-                       d.done( ok );
-                       d.fail( err );
+                       d.done( ok ).fail( err );
 
                        // Fetch with allpages to only get categories that have a corresponding description page.
                        apiPromise = this.get( {
@@ -92,9 +92,9 @@
                getCategories: function ( title, ok, err, async ) {
                        var d = $.Deferred(),
                                apiPromise;
+
                        // Backwards compatibility (< MW 1.20)
-                       d.done( ok );
-                       d.fail( err );
+                       d.done( ok ).fail( err );
 
                        apiPromise = this.get( {
                                        prop: 'categories',
index 96947cc..381e172 100644 (file)
@@ -59,9 +59,9 @@
                getEditToken: function ( ok, err ) {
                        var d = $.Deferred(),
                                apiPromise;
+
                        // Backwards compatibility (< MW 1.20)
-                       d.done( ok );
-                       d.fail( err );
+                       d.done( ok ).fail( err );
 
                        apiPromise = this.get( {
                                        action: 'tokens',
index 08bb171..c4d23b8 100644 (file)
@@ -17,9 +17,9 @@
                parse: function ( wikitext, ok, err ) {
                        var d = $.Deferred(),
                                apiPromise;
+
                        // Backwards compatibility (< MW 1.20)
-                       d.done( ok );
-                       d.fail( err );
+                       d.done( ok ).fail( err );
 
                        apiPromise = this.get( {
                                        action: 'parse',
index e2be5c7..49a4c62 100644 (file)
@@ -22,9 +22,9 @@
                var params,
                        d = $.Deferred(),
                        apiPromise;
+
                // Backwards compatibility (< MW 1.20)
-               d.done( ok );
-               d.fail( err );
+               d.done( ok ).fail( err );
 
                params = {
                        action: 'watch',
index 160de86..580cf25 100644 (file)
@@ -1,12 +1,14 @@
+/*jshint camelcase:false */
 ( function ( mw, $ ) {
-var    ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ),
+var    licenseSelectorCheck, wgUploadWarningObj, wgUploadLicenseObj, fillDestFilename,
+       ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ),
        fileExtensions = mw.config.get( 'wgFileExtensions' );
 
-window.licenseSelectorCheck = function() {
-       var selector = document.getElementById( "wpLicense" );
-       var selection = selector.options[selector.selectedIndex].value;
-       if( selector.selectedIndex > 0 ) {
-               if( selection == "" ) {
+licenseSelectorCheck = window.licenseSelectorCheck = function () {
+       var selector = document.getElementById( 'wpLicense' ),
+               selection = selector.options[selector.selectedIndex].value;
+       if ( selector.selectedIndex > 0 ) {
+               if ( !selection ) {
                        // Option disabled, but browser is broken and doesn't respect this
                        selector.selectedIndex = 0;
                }
@@ -17,23 +19,29 @@ window.licenseSelectorCheck = function() {
 
 function uploadSetup() {
        // Disable URL box if the URL copy upload source type is not selected
-       var e = document.getElementById( 'wpSourceTypeurl' );
-       if( e ) {
-               if( !e.checked ) {
-                       var ein = document.getElementById( 'wpUploadFileURL' );
-                       if(ein)
-                               ein.setAttribute( 'disabled', 'disabled' );
+       var ein,
+               selector, ua, isMacIe, i,
+               optionsTable, row, td,
+               wpLicense, wpLicenseRow, wpLicenseTbody,
+               uploadSourceIds, len, onchange,
+               e = document.getElementById( 'wpSourceTypeurl' );
+       if ( e ) {
+               if ( !e.checked ) {
+                       ein = document.getElementById( 'wpUploadFileURL' );
+                       if ( ein ) {
+                               ein.disabled = true;
+                       }
                }
        }
 
        // For MSIE/Mac: non-breaking spaces cause the <option> not to render.
        // But for some reason, setting the text to itself works
-       var selector = document.getElementById("wpLicense");
-       if (selector) {
-               var ua = navigator.userAgent;
-               var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1);
-               if (isMacIe) {
-                       for (var i = 0; i < selector.options.length; i++) {
+       selector = document.getElementById( 'wpLicense' );
+       if ( selector ) {
+               ua = navigator.userAgent;
+               isMacIe = ua.indexOf( 'MSIE' ) !== -1 && ua.indexOf( 'Mac' ) !== -1;
+               if ( isMacIe ) {
+                       for ( i = 0; i < selector.options.length; i++ ) {
                                selector.options[i].text = selector.options[i].text;
                        }
                }
@@ -43,31 +51,31 @@ function uploadSetup() {
        if ( ajaxUploadDestCheck ) {
                // Insert an event handler that fetches upload warnings when wpDestFile
                // has been changed
-               document.getElementById( 'wpDestFile' ).onchange = function ( e ) {
-                       wgUploadWarningObj.checkNow(this.value);
+               document.getElementById( 'wpDestFile' ).onchange = function () {
+                       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' );
+               optionsTable = document.getElementById( 'mw-htmlform-description' ).tBodies[0];
+               row = optionsTable.insertRow( 1 );
+               td = document.createElement( 'td' );
                td.id = 'wpDestFile-warning';
                td.colSpan = 2;
 
                row.appendChild( td );
        }
 
-       var wpLicense = document.getElementById( 'wpLicense' );
+       wpLicense = document.getElementById( 'wpLicense' );
        if ( mw.config.get( 'wgAjaxLicensePreview' ) && wpLicense ) {
                // License selector check
                wpLicense.onchange = licenseSelectorCheck;
 
                // License selector table row
-               var wpLicenseRow = wpLicense.parentNode.parentNode;
-               var wpLicenseTbody = wpLicenseRow.parentNode;
+               wpLicenseRow = wpLicense.parentNode.parentNode;
+               wpLicenseTbody = wpLicenseRow.parentNode;
 
-               var row = document.createElement( 'tr' );
-               var td = document.createElement( 'td' );
+               row = document.createElement( 'tr' );
+               td = document.createElement( 'td' );
                row.appendChild( td );
                td = document.createElement( 'td' );
                td.id = 'mw-license-preview';
@@ -78,63 +86,75 @@ function uploadSetup() {
 
 
        // fillDestFile setup
-       var     i,
-               uploadSourceIds = mw.config.get( 'wgUploadSourceIds' ),
-               len = uploadSourceIds.length;
-       for ( i = 0; i < len; i += 1 )
-               document.getElementById( uploadSourceIds[i] ).onchange = function (e) {
-                       fillDestFilename( this.id );
-               };
-};
+       uploadSourceIds = mw.config.get( 'wgUploadSourceIds' );
+       len = uploadSourceIds.length;
+       onchange = function () {
+               fillDestFilename( this.id );
+       };
+       for ( i = 0; i < len; i += 1 ) {
+               document.getElementById( uploadSourceIds[i] ).onchange = onchange;
+       }
+}
 
+wgUploadWarningObj = window.wgUploadWarningObj = {
+       responseCache: { '' : '&nbsp;' },
+       nameToCheck: '',
+       typing: false,
+       delay: 500, // ms
+       timeoutID: false,
 
-window.wgUploadWarningObj = {
-       'responseCache' : { '' : '&nbsp;' },
-       'nameToCheck' : '',
-       'typing': false,
-       'delay': 500, // ms
-       'timeoutID': false,
+       keypress: function () {
+               var cached, destFile, warningElt;
 
-       'keypress': function () {
-               if ( !ajaxUploadDestCheck ) return;
+               if ( !ajaxUploadDestCheck ) {
+                       return;
+               }
 
                // Find file to upload
-               var destFile = document.getElementById('wpDestFile');
-               var warningElt = document.getElementById( 'wpDestFile-warning' );
-               if ( !destFile || !warningElt ) return ;
+               destFile = document.getElementById( 'wpDestFile' );
+               warningElt = document.getElementById( 'wpDestFile-warning' );
+               if ( !destFile || !warningElt ) {
+                       return;
+               }
 
-               this.nameToCheck = destFile.value ;
+               this.nameToCheck = destFile.value;
 
                // Clear timer
                if ( this.timeoutID ) {
-                       window.clearTimeout( this.timeoutID );
+                       clearTimeout( this.timeoutID );
                }
                // Check response cache
-               for (cached in this.responseCache) {
-                       if (this.nameToCheck == cached) {
+               for ( cached in this.responseCache ) {
+                       if ( this.nameToCheck === cached ) {
                                this.setWarning(this.responseCache[this.nameToCheck]);
                                return;
                        }
                }
 
-               this.timeoutID = window.setTimeout( 'wgUploadWarningObj.timeout()', this.delay );
+               this.timeoutID = setTimeout( function () {
+                       wgUploadWarningObj.timeout();
+               }, this.delay );
        },
 
-       'checkNow': function (fname) {
-               if ( !ajaxUploadDestCheck ) return;
+       checkNow: function ( fname ) {
+               if ( !ajaxUploadDestCheck ) {
+                       return;
+               }
                if ( this.timeoutID ) {
-                       window.clearTimeout( this.timeoutID );
+                       clearTimeout( this.timeoutID );
                }
                this.nameToCheck = fname;
                this.timeout();
        },
 
-       'timeout' : function() {
-               if ( !ajaxUploadDestCheck || this.nameToCheck === '' ) return;
-               injectSpinner( document.getElementById( 'wpDestFile' ), 'destcheck' );
+       timeout: function () {
+               if ( !ajaxUploadDestCheck || this.nameToCheck === '' ) {
+                       return;
+               }
+               window.injectSpinner( document.getElementById( 'wpDestFile' ), 'destcheck' );
 
                var uploadWarningObj = this;
-               ( new mw.Api ).get( {
+               ( new mw.Api() ).get( {
                        action: 'query',
                        titles: ( new mw.Title( this.nameToCheck, mw.config.get( 'wgNamespaceIds' ).file ) ).getPrefixedText(),
                        prop: 'imageinfo',
@@ -149,89 +169,101 @@ window.wgUploadWarningObj = {
                } );
        },
 
-       'processResult' : function ( result, fileName ) {
-               removeSpinner( 'destcheck' );
+       processResult: function ( result, fileName ) {
+               window.removeSpinner( 'destcheck' );
                this.setWarning( result.html );
                this.responseCache[fileName] = result.html;
        },
 
-       'setWarning' : function (warning) {
-               var warningElt = document.getElementById( 'wpDestFile-warning' );
-               var ackElt = document.getElementsByName( 'wpDestFileWarningAck' );
+       setWarning: function ( warning ) {
+               var warningElt = document.getElementById( 'wpDestFile-warning' ),
+                       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 == '' ) {
+               if ( !warning ) {
                        ackElt[0].value = '';
                } else {
                        ackElt[0].value = '1';
                }
 
        },
-       'setInnerHTML' : function (element, text) {
+       setInnerHTML: function ( element, text ) {
                // Check for no change to avoid flicker in IE 7
-               if (element.innerHTML != text) {
+               if ( element.innerHTML !== text ) {
                        element.innerHTML = text;
                }
        }
 };
 
-window.fillDestFilename = function(id) {
+fillDestFilename = window.fillDestFilename = function ( id ) {
+       var e, path, slash, backslash, fname,
+               found, ext, i,
+               destFile;
        if ( !mw.config.get( 'wgUploadAutoFill' ) ) {
                return;
        }
-       if (!document.getElementById) {
+       if ( !document.getElementById ) {
                return;
        }
        // Remove any previously flagged errors
-       var e = document.getElementById( 'mw-upload-permitted' );
-       if( e ) e.className = '';
+       e = document.getElementById( 'mw-upload-permitted' );
+       if ( e ) {
+               e.className = '';
+       }
 
-       var e = document.getElementById( 'mw-upload-prohibited' );
-       if( e ) e.className = '';
+       e = document.getElementById( 'mw-upload-prohibited' );
+       if ( e ) {
+               e.className = '';
+       }
 
-       var path = document.getElementById(id).value;
+       path = document.getElementById( id ).value;
        // Find trailing part
-       var slash = path.lastIndexOf('/');
-       var backslash = path.lastIndexOf('\\');
-       var fname;
-       if (slash == -1 && backslash == -1) {
+       slash = path.lastIndexOf( '/' );
+       backslash = path.lastIndexOf( '\\' );
+       if ( slash === -1 && backslash === -1 ) {
                fname = path;
-       } else if (slash > backslash) {
-               fname = path.substring(slash+1, 10000);
+       } else if ( slash > backslash ) {
+               fname = path.substring( slash + 1, 10000 );
        } else {
-               fname = path.substring(backslash+1, 10000);
+               fname = path.substring( backslash + 1, 10000 );
        }
 
        // 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 ( mw.config.get( 'wgStrictFileExtensions' ) && fileExtensions && id !== 'wpUploadFileURL' ) {
-               var found = false;
+               found = false;
                if ( fname.lastIndexOf( '.' ) !== -1 ) {
-                       var ext = fname.substr( fname.lastIndexOf( '.' ) + 1 );
-                       for ( var i = 0; i < fileExtensions.length; i += 1 ) {
+                       ext = fname.substr( fname.lastIndexOf( '.' ) + 1 );
+                       for ( i = 0; i < fileExtensions.length; i += 1 ) {
                                if ( fileExtensions[i].toLowerCase() === ext.toLowerCase() ) {
                                        found = true;
                                        break;
                                }
                        }
                }
-               if( !found ) {
+               if ( !found ) {
                        // Not a valid extension
                        // Clear the upload and set mw-upload-permitted to error
-                       document.getElementById(id).value = '';
-                       var e = document.getElementById( 'mw-upload-permitted' );
-                       if( e ) e.className = 'error';
+                       document.getElementById( id ).value = '';
+                       e = document.getElementById( 'mw-upload-permitted' );
+                       if ( e ) {
+                               e.className = 'error';
+                       }
 
-                       var e = document.getElementById( 'mw-upload-prohibited' );
-                       if( e ) e.className = 'error';
+                       e = document.getElementById( 'mw-upload-prohibited' );
+                       if ( e ) {
+                               e.className = 'error';
+                       }
 
                        // Clear wpDestFile as well
-                       var e = document.getElementById( 'wpDestFile' );
-                       if( e ) e.value = '';
+                       e = document.getElementById( 'wpDestFile' );
+                       if ( e ) {
+                               e.value = '';
+                       }
 
                        return false;
                }
@@ -245,45 +277,51 @@ window.fillDestFilename = function(id) {
        }
 
        // Output result
-       var destFile = document.getElementById( 'wpDestFile' );
+       destFile = document.getElementById( 'wpDestFile' );
        if ( destFile ) {
                // Call decodeURIComponent function to remove possible URL-encoded characters
                // from the file name (bug 30390). Especially likely with upload-form-url.
                // decodeURIComponent can throw an exception in input is invalid utf-8
                try {
                        destFile.value = decodeURIComponent( fname );
-               } catch ( e ) {
+               } catch ( err ) {
                        destFile.value = fname;
                }
                wgUploadWarningObj.checkNow( fname );
        }
 };
 
-window.toggleFilenameFiller = function() {
-       if(!document.getElementById) return;
-       var upfield = document.getElementById('wpUploadFile');
-       var destName = document.getElementById('wpDestFile').value;
-       wgUploadAutoFill = ( destName == '' || destName == ' ' );
+window.toggleFilenameFiller = function () {
+       if ( !document.getElementById ) {
+               return;
+       }
+       var destName = document.getElementById( 'wpDestFile' ).value;
+       mw.config.set( 'wgUploadAutoFill', !destName );
 };
 
-window.wgUploadLicenseObj = {
+wgUploadLicenseObj = window.wgUploadLicenseObj = {
 
-       'responseCache' : { '' : '' },
+       responseCache: { '' : '' },
 
-       'fetchPreview': function( license ) {
-               if ( !mw.config.get( 'wgAjaxLicensePreview' ) ) return;
-               for (cached in this.responseCache) {
-                       if (cached == license) {
+       fetchPreview: function ( license ) {
+               var cached, title;
+               if ( !mw.config.get( 'wgAjaxLicensePreview' ) ) {
+                       return;
+               }
+               for ( cached in this.responseCache ) {
+                       if ( cached === license ) {
                                this.showPreview( this.responseCache[license] );
                                return;
                        }
                }
-               injectSpinner( document.getElementById( 'wpLicense' ), 'license' );
+               window.injectSpinner( document.getElementById( 'wpLicense' ), 'license' );
 
-               var title = document.getElementById('wpDestFile').value;
-               if ( !title ) title = 'File:Sample.jpg';
+               title = document.getElementById( 'wpDestFile' ).value;
+               if ( !title ) {
+                       title = 'File:Sample.jpg';
+               }
 
-               ( new mw.Api ).get( {
+               ( new mw.Api() ).get( {
                        action: 'parse',
                        text: '{{' + license + '}}',
                        title: title,
@@ -294,16 +332,17 @@ window.wgUploadLicenseObj = {
                } );
        },
 
-       'processResult' : function( result, license ) {
-               removeSpinner( 'license' );
-               this.responseCache[license] = result['parse']['text']['*'];
+       processResult: function ( result, license ) {
+               window.removeSpinner( 'license' );
+               this.responseCache[license] = result.parse.text['*'];
                this.showPreview( this.responseCache[license] );
        },
 
-       'showPreview' : function( preview ) {
+       showPreview: function ( preview ) {
                var previewPanel = document.getElementById( 'mw-license-preview' );
-               if( previewPanel.innerHTML != preview )
+               if ( previewPanel.innerHTML !== preview ) {
                        previewPanel.innerHTML = preview;
+               }
        }
 
 };