From 3b4ae214bd29e4c7213c29a8073c58f0313b66eb Mon Sep 17 00:00:00 2001 From: Amory Meltzer Date: Thu, 20 Feb 2020 21:55:58 -0500 Subject: [PATCH] xfd: Avoid client clock for soft redirects In doing #862, I undid the intent of #714 to avoid the client clock as much as possible for the specific case of soft redirects being nominated at RfD. It never worked - thus #861 - but the idea is sound. This has softredirects go through the same `curtimestamp` query and "typical" redirects, but simply skips processing of target or section. It's not an entirely free check anymore, but it should be incredibly infrequent and fairly quick. --- modules/twinklexfd.js | 45 +++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index 1d36fa851..b6b5ea2ef 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -1292,43 +1292,46 @@ Twinkle.xfd.callbacks = { rfd: { // This gets called both on submit and preview to determine the redirect target findTarget: function(params, callback) { + // Used by regular redirects to find the target, but for all redirects, + // avoid relying on the client clock to build the log page + var query = { + 'action': 'query', + 'curtimestamp': true + }; if (document.getElementById('softredirect')) { - // For soft redirects, skip straight to the callback + // For soft redirects, define the target early + // to skip target checks in findTargetCallback params.target = document.getElementById('softredirect').textContent.replace(/^:+/, ''); - callback(params); } else { // Find current target of redirect - var query = { - 'action': 'query', - 'titles': mw.config.get('wgPageName'), - '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; - wikipedia_api.post(); + query.titles = mw.config.get('wgPageName'); + query.redirects = true; } + var wikipedia_api = new Morebits.wiki.api('Finding target of redirect', query, Twinkle.xfd.callbacks.rfd.findTargetCallback(callback)); + wikipedia_api.params = params; + wikipedia_api.post(); }, // 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 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; - apiobj.params.section = section; + if (!apiobj.params.target) { // Not a softredirect + var target = $xmlDoc.find('redirects r').first().attr('to'); + if (!target) { + apiobj.statelem.error('This page is currently not a redirect, aborting'); + return; + } + apiobj.params.target = target; + var section = $xmlDoc.find('redirects r').first().attr('tofragment'); + apiobj.params.section = section; + } callback(apiobj.params); }; }, main: function(params) { - // Fallback to client clock for softredirects - var date = params.curtimestamp ? new Date(params.curtimestamp) : new Date(); + 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;