diff --git a/extension.json b/extension.json index 4a7f5404a..ee93e52bc 100644 --- a/extension.json +++ b/extension.json @@ -439,8 +439,7 @@ "mmv.ui.ondemandshareddependencies", "mmv.ui.reuse.shareembed", "mmv.ui.download.pane", - "mmv.ui.tipsyDialog", - "moment" + "mmv.ui.tipsyDialog" ] }, "EventLoggingSchemas": { diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js index 619291cfc..e51db715a 100644 --- a/resources/mmv/mmv.js +++ b/resources/mmv/mmv.js @@ -1026,7 +1026,7 @@ * Preloads JS and CSS dependencies that aren't needed to display the first image, but could be needed later */ MMVP.preloadDependencies = function () { - mw.loader.load( [ 'mmv.ui.reuse.shareembed', 'moment' ] ); + mw.loader.load( [ 'mmv.ui.reuse.shareembed' ] ); }; /** diff --git a/resources/mmv/ui/mmv.ui.metadataPanel.js b/resources/mmv/ui/mmv.ui.metadataPanel.js index 5ded26a9e..de1a8c9e7 100644 --- a/resources/mmv/ui/mmv.ui.metadataPanel.js +++ b/resources/mmv/ui/mmv.ui.metadataPanel.js @@ -757,19 +757,9 @@ mw.mmv.attributionLogger.logAttribution( imageData ); if ( imageData.creationDateTime ) { - // Use the raw date until moment can try to interpret it - panel.setDateTime( imageData.creationDateTime ); - - this.formatDate( imageData.creationDateTime ).then( function ( formattedDate ) { - panel.setDateTime( formattedDate, true ); - } ); + panel.setDateTime( this.formatDate( imageData.creationDateTime ), true ); } else if ( imageData.uploadDateTime ) { - // Use the raw date until moment can try to interpret it - panel.setDateTime( imageData.uploadDateTime ); - - this.formatDate( imageData.uploadDateTime ).then( function ( formattedDate ) { - panel.setDateTime( formattedDate ); - } ); + panel.setDateTime( this.formatDate( imageData.uploadDateTime ) ); } this.buttons.set( imageData, repoData ); @@ -814,29 +804,24 @@ * Unrecognized strings are returned unchanged. * * @param {string} dateString - * @return {jQuery.Deferred} + * @return {string} formatted date */ MPP.formatDate = function ( dateString ) { - var deferred = $.Deferred(), - date; - - mw.loader.using( 'moment', function () { - /* global moment */ - date = moment( dateString ); - - if ( date.isValid() ) { - deferred.resolve( date.format( 'LL' ) ); - } else { - deferred.resolve( dateString ); + var date, + lang = mw.config.get( 'wgUserLanguage' ); + if ( lang === 'en' ) { lang = 'en-GB'; } // for D MMMM YYYY format + date = new Date( dateString ); + try { + if ( date instanceof Date && !isNaN( date ) ) { + return date.toLocaleString( lang, { + day: 'numeric', + month: 'long', + year: 'numeric' + } ); } - }, function ( error ) { - deferred.reject( error ); - if ( window.console && window.console.error ) { - window.console.error( 'mw.loader.using error when trying to load moment', error ); - } - } ); - - return deferred.promise(); + } catch ( ignore ) {} + // fallback to original date string + return dateString; }; /** diff --git a/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js b/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js index 0a6b88ab9..d804352c3 100644 --- a/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js @@ -113,16 +113,8 @@ getArticlePath: function () { return 'Foo'; }, isCommons: function () { return false; } }, - oldMoment = window.moment, - // custom clock will give MPP.formatDate some time to load moment.js clock = this.sandbox.useFakeTimers(); - /* window.moment = function ( date ) { - // This has no effect for now, since writing this test revealed that our moment.js - // doesn't have any language configuration - return oldMoment( date ).lang( 'fr' ); - };*/ - panel.setImageInfo( image, imageData, repoData ); assert.strictEqual( panel.$title.text(), title, 'Title is correctly set' ); @@ -164,7 +156,6 @@ assert.ok( panel.$datetime.text().indexOf( '25 August 2013' ) > 0, 'Correct date is displayed' ); - window.moment = oldMoment; clock.restore(); } ); @@ -181,11 +172,9 @@ var $qf = $( '#qunit-fixture' ), panel = new mw.mmv.ui.MetadataPanel( $qf, $( '