Skip to content

Commit

Permalink
xfd: avoid client clock for RFD log page determination
Browse files Browse the repository at this point in the history
The curtimestamp parameter is added to the API request while finding the target of the redirect, so that the server time is available while determining the log page.
  • Loading branch information
siddharthvp committed Nov 8, 2019
1 parent 7cf3d64 commit d235e6f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions modules/twinklexfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,8 @@ Twinkle.xfd.callbacks = {
var query = {
'action': 'query',
'titles': mw.config.get('wgPageName'),
'redirects': true
'redirects': true,
'curtimestamp': true
};
var wikipedia_api = new Morebits.wiki.api('Finding target of redirect', query, Twinkle.xfd.callbacks.rfd.findTargetCallback(callback));
wikipedia_api.params = params;
Expand All @@ -1242,20 +1243,22 @@ Twinkle.xfd.callbacks = {
// This is a closure for the callback from the above API request, which gets the target of the redirect
findTargetCallback: function(callback) {
return function(apiobj) {
var xmlDoc = apiobj.responseXML;
var target = $(xmlDoc).find('redirects r').first().attr('to');
var $xmlDoc = $(apiobj.responseXML);
var curtimestamp = $xmlDoc.find('api').attr('curtimestamp');
var target = $xmlDoc.find('redirects r').first().attr('to');
if (!target) {
apiobj.statelem.error('This page is currently not a redirect, aborting');
return;
}
var section = $xmlDoc.find('redirects r').first().attr('tofragment');
apiobj.params.curtimestamp = curtimestamp;
apiobj.params.target = target;
var section = $(xmlDoc).find('redirects r').first().attr('tofragment');
apiobj.params.section = section;
callback(apiobj.params);
};
},
main: function(params) {
var date = new Date(); // XXX: avoid use of client clock
var date = new Date(params.curtimestamp);
params.logpage = 'Wikipedia:Redirects for discussion/Log/' + date.getUTCFullYear() + ' ' + date.getUTCMonthName() + ' ' + date.getUTCDate();
params.discussionpage = params.logpage + '#' + Morebits.pageNameNorm;

Expand Down

0 comments on commit d235e6f

Please sign in to comment.