Use moment.js instead of timeAgo method

Bug: 61481
Change-Id: I8e08335aa091c098a9efd1eb148627b134e42940
This commit is contained in:
Prateek Saxena 2014-02-27 11:37:14 +05:30
parent 8973f95163
commit 1818c0d2e6
3 changed files with 5 additions and 71 deletions

View file

@ -27,11 +27,7 @@ $messages = array();
$messages['en'] = array( $messages['en'] = array(
'popups-message' => 'Popups', 'popups-message' => 'Popups',
'popups-desc' => 'Displays popups with summaries of page contents when the user hovers over a page link.', 'popups-desc' => 'Displays popups with summaries of page contents when the user hovers over a page link.',
'popups-edited-seconds' => 'Last edited {{PLURAL:$1|1 second|$1 seconds}} ago.', 'popups-last-edited' => 'Last edited $1',
'popups-edited-minutes' => 'Last edited {{PLURAL:$1|1 minute|$1 minutes}} ago.',
'popups-edited-hours' => 'Last edited {{PLURAL:$1|1 hour|$1 hours}} ago.',
'popups-edited-days' => 'Last edited {{PLURAL:$1|yesterday|$1 days ago}}.',
'popups-edited-years' => 'Last edited {{PLURAL:$1|1 year|$1 years}} ago.',
'popups-redirects' => 'redirects to <h3>$1</h3>', 'popups-redirects' => 'redirects to <h3>$1</h3>',
); );
@ -41,21 +37,7 @@ $messages['en'] = array(
$messages['qqq'] = array( $messages['qqq'] = array(
'popups-message' => 'Name shown in user preference for this extension', 'popups-message' => 'Name shown in user preference for this extension',
'popups-desc' => '{{desc|name=Popups|url=https://www.mediawiki.org/wiki/Extension:Popups}}', 'popups-desc' => '{{desc|name=Popups|url=https://www.mediawiki.org/wiki/Extension:Popups}}',
'popups-edited-seconds' => 'Message to show time span if page was edited less than a minute ago. Parameters: 'popups-last-edited' => 'Message to show time span since the page was last edited. $1 is the timespan in words.',
* $1 - number of seconds
{{Related|Popups-edited}}',
'popups-edited-minutes' => 'Message to show time span if page was edited less than an hour ago. Parameters:
* $1 - number of minutes
{{Related|Popups-edited}}',
'popups-edited-hours' => 'Message to show time span if page was edited less than a day ago. Parameters:
* $1 - number of hours
{{Related|Popups-edited}}',
'popups-edited-days' => 'Message to show time span if page was edited less than a year ago. Parameters:
* $1 - number of days
{{Related|Popups-edited}}',
'popups-edited-years' => 'Message to show time span if page was edited more than a year ago. Parameters:
* $1 - number of years
{{Related|Popups-edited}}',
'popups-redirects' => 'Message shown when the popup is showing a redirected page', 'popups-redirects' => 'Message shown when the popup is showing a redirected page',
); );

View file

@ -45,13 +45,10 @@ $wgResourceModules = array_merge( $wgResourceModules, array(
'dependencies' => array( 'dependencies' => array(
'mediawiki.api', 'mediawiki.api',
'mediawiki.jqueryMsg', 'mediawiki.jqueryMsg',
'moment',
), ),
'messages' => array( 'messages' => array(
'popups-edited-seconds', 'popups-last-edited',
'popups-edited-minutes',
'popups-edited-hours',
'popups-edited-days',
'popups-edited-years',
'popups-redirects', 'popups-redirects',
), ),
'remoteExtPath' => $remoteExtPath, 'remoteExtPath' => $remoteExtPath,

View file

@ -63,7 +63,7 @@
$timestamp = $( '<div>' ) $timestamp = $( '<div>' )
.addClass( timestampclass ) .addClass( timestampclass )
.append( .append(
$( '<span>' ).text( timeAgo( timediff ).text() ) $( '<span>' ).text( mw.message( 'popups-last-edited', moment( timestamp ).fromNow() ).text() )
); );
if ( redirects ) { if ( redirects ) {
@ -412,49 +412,4 @@
} ); } );
// Util functions that should be separated out into their own files at some point
/**
* @method timeAgo
* Formats a given time duration (in ms) into a relative string.
*
* @param {number} ms The time duration to convert to a relative string, in ms
* @return {Object} A mw.message object with the appropriate relative string.
*/
function timeAgo( ms ) {
var i, ts, timeSegments = [
{
factor: 1000,
min: 60,
message: 'popups-edited-seconds'
},
{
factor: 60,
min: 60,
message: 'popups-edited-minutes'
},
{
factor: 60,
min: 24,
message: 'popups-edited-hours'
},
{
factor: 24,
min: 365,
message: 'popups-edited-days'
},
{
factor: 365,
message: 'popups-edited-years'
}
], curDuration = ms;
for ( i = 0; i <= timeSegments.length; i++ ) {
ts = timeSegments[ i ];
curDuration = Math.floor( curDuration / ts.factor );
if ( typeof ts.min === 'undefined' || curDuration < ts.min ) {
return mw.message( ts.message, curDuration );
}
}
}
} ) ( jQuery ); } ) ( jQuery );