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(
'popups-message' => 'Popups',
'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-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-last-edited' => 'Last edited $1',
'popups-redirects' => 'redirects to <h3>$1</h3>',
);
@ -41,21 +37,7 @@ $messages['en'] = array(
$messages['qqq'] = array(
'popups-message' => 'Name shown in user preference for this extension',
'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:
* $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-last-edited' => 'Message to show time span since the page was last edited. $1 is the timespan in words.',
'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(
'mediawiki.api',
'mediawiki.jqueryMsg',
'moment',
),
'messages' => array(
'popups-edited-seconds',
'popups-edited-minutes',
'popups-edited-hours',
'popups-edited-days',
'popups-edited-years',
'popups-last-edited',
'popups-redirects',
),
'remoteExtPath' => $remoteExtPath,

View file

@ -63,7 +63,7 @@
$timestamp = $( '<div>' )
.addClass( timestampclass )
.append(
$( '<span>' ).text( timeAgo( timediff ).text() )
$( '<span>' ).text( mw.message( 'popups-last-edited', moment( timestamp ).fromNow() ).text() )
);
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 );