Add time ago in words at the bottom of the popup

Change-Id: I53f77a0c802ae3b9582c51a07fc56ad56e3fd53b
This commit is contained in:
Prateek Saxena 2014-02-07 13:05:34 +05:30
parent e9ad2ef798
commit ce59f92489
3 changed files with 70 additions and 3 deletions

View file

@ -26,7 +26,12 @@ $messages = array();
*/
$messages['en'] = array(
'popups-message' => 'Popups',
'popups-desc' => 'Displays popups with summaries of page contents when the user hovers over an page link',
'popups-desc' => 'Displays popups with summaries of article contents when the user hovers over an article 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.',
);
/** Message documentation (Message documentation)
@ -34,6 +39,11 @@ $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',
'popups-edited-minutes' => 'Message to show time span if page was edited less than an hour ago',
'popups-edited-hours' => 'Message to show time span if page was edited less than a day ago',
'popups-edited-days' => 'Message to show time span if page was edited less than a year ago',
'popups-edited-years' => 'Message to show time span if page was edited more than a year ago',
);
/** Arabic (العربية)

View file

@ -35,7 +35,9 @@ $remoteExtPath = 'Popups';
$wgResourceModules = array_merge( $wgResourceModules, array(
"ext.popups" => array(
'scripts' => 'resources/ext.popups.core.js',
'scripts' => array(
'resources/ext.popups.core.js',
),
'styles' => array(
'resources/ext.popups.core.less',
'resources/ext.popups.animation.less',
@ -43,6 +45,13 @@ $wgResourceModules = array_merge( $wgResourceModules, array(
'dependencies' => array(
'mediawiki.api',
),
'messages' => array(
'popups-edited-seconds',
'popups-edited-minutes',
'popups-edited-hours',
'popups-edited-days',
'popups-edited-years',
),
'remoteExtPath' => $remoteExtPath,
'localBasePath' => $localBasePath,
),

View file

@ -57,7 +57,7 @@
$timestamp = $( '<div>' )
.addClass( timestampclass )
.append(
$( '<span>' ).text( timestamp.toString() )
$( '<span>' ).text( timeAgo( timediff ).text() )
);
if ( thumbnail ){
@ -237,5 +237,53 @@
}
} )
.appendTo( document.body );
} );
// 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 );