( function( $, mw ) {
var baseTooltip = 'List of pages with unreviewed edits'
mw.util.addPortletLink(
'p-tb', // toolbox ID
mw.util.getUrl( 'Special:PendingChanges' ), // Pending changes link
'Pending changes', // link text
't-pendingchanges', // link ID
baseTooltip // link tooltip
);
function plural( num, text ) {
return num + ' ' + text + ( num !== 1 ? 's' : '' );
}
function updateNumChanges() {
new mw.Api().get( {
action: 'query',
list: 'oldreviewedpages',
orlimit: 40,
ornamespace: [ 0, 4 ]
} ).done( function ( data ) {
if ( !data.query ) {
return;
}
var numChanges = data.query.oldreviewedpages.length,
oldestTimestamp = null;
if ( numChanges > 0 ) {
oldestTimestamp = data.query.oldreviewedpages[0].pending_since;
var then = new Date( oldestTimestamp ).getTime(),
now = Date.now(),
msDiff = now - then,
hourDiff = Math.round( msDiff / 36e5 );
}
if( data.continue ){
numChanges += '+';
}
$( '#t-pendingchanges a' )
.text( plural( numChanges, 'pending edit' ) )
.attr( 'title', function () {
if ( !oldestTimestamp ) {
return baseTooltip;
}
return baseTooltip + '.\nOldest is ' + plural( hourDiff, 'hour' ) + ' old.';
} );
});
}
updateNumChanges();
setInterval( updateNumChanges, 2 * 60000 ); // update every 2 minutes
} ) ( jQuery, mediaWiki );