New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use server time rather than client time wherever possible #741
Use server time rather than client time wherever possible #741
Conversation
Note: the |
7ddf55e
to
d235e6f
Compare
I've yet to thoroughly review this, but it all looks very reasonable; I'm surprised we've gone so long without wanting
Could you add a comment to this effect? #615 can be our open ticket, but a comment in the code would be nice. I'll try to get to this in the new year, sorry for the lag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magnifique! Two requests for updated comments, but otherwise 💯
@@ -241,8 +241,7 @@ Twinkle.prod.callbacks = { | |||
|
|||
// Alert if article is at least three days old, not in Category:Living people, and BLPPROD is selected | |||
if (params.blp) { | |||
var now = new Date().toISOString(); | |||
var timeDiff = (new Date(now) - new Date(params.creation)) / 1000 / 60 / 60 / 24; // days from milliseconds | |||
var timeDiff = (new Date(pageobj.getLoadTime()).getTime() - new Date(params.creation).getTime()) / 1000 / 60 / 60 / 24; // days from milliseconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Yes, much better!
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that elsewhere in xfd
we don't use the jquery naming convention; this is the only one that actually uses it for more than convenience, so it's reasonable to do here.
Largely addresses wikimedia-gadgets#6. Per wikimedia-gadgets#6 (comment), the server time is available to us whenever we are in a `.load()` callback, via the starttimestamp attribute in load API output which is stored in Morebits.wiki.page as ctx.loadTime, publicly exposed via `.getLoadTime()`.
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.
Looks like my git directory on windows has went bust (weird permission denied errors). Will push the latest changes when later when I log into ubuntu. |
d235e6f
to
3e21765
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏆
1. Since wikimedia-gadgets#741 (specifically, 3e21765), RfD was using a returned `curtimestamp` to generate the log page. That query was only being done if the page wasn't a soft redirect, however, leading to NaN/undefined issues. Closes wikimedia-gadgets#861 by falling back to the previous client clock method. 2. wikimedia-gadgets#527 (44c0e42) added the ability to notify a redirect's target, but returns an error if the title is invalid, such as with soft redirects via {{wi}}. This now skips the notification in such cases.
…tokens Deprecated ages ago (see https://www.mediawiki.org/wiki/MediaWiki_1.24#API_changes and https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/153110/). Closes wikimedia-gadgets#615. Use `curtimestamp` on `.load` calls now that we no longer use `intoken`. As noted in wikimedia-gadgets#741, `starttimestamp` was only available because we were still using the outdated `intoken` method. With that gone, we need to explicitly provide `query.curtimestamp`, thus replicating the loading timestamp that we can feed it into `starttimestamp` and avoid edit conflicts. Also replaced `intoken` in `twinklefluff.js` and removed the undelete kludge from wikimedia-gadgets#616. Some references to token names in error messages are kept for ease of debugging.
1. Since wikimedia-gadgets#741 (specifically, 3e21765), RfD was using a returned `curtimestamp` to generate the log page. That query was only being done if the page wasn't a soft redirect, however, leading to NaN/undefined issues. Closes wikimedia-gadgets#861 by falling back to the previous client clock method. 2. wikimedia-gadgets#527 (44c0e42) added the ability to notify a redirect's target, but returns an error if the title is invalid, such as with soft redirects via {{wi}}. This now skips the notification in such cases.
…tokens Deprecated ages ago (see https://www.mediawiki.org/wiki/MediaWiki_1.24#API_changes and https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/153110/). Closes wikimedia-gadgets#615. Use `curtimestamp` on `.load` calls now that we no longer use `intoken`. As noted in wikimedia-gadgets#741, `starttimestamp` was only available because we were still using the outdated `intoken` method. With that gone, we need to explicitly provide `query.curtimestamp`, thus replicating the loading timestamp that we can feed it into `starttimestamp` and avoid edit conflicts. Also replaced `intoken` in `twinklefluff.js` and removed the undelete kludge from wikimedia-gadgets#616. Some references to token names in error messages are kept for ease of debugging.
Largely addresses #6. Per #6 (comment), the server time is available to us whenever we are in a
.load()
callback, via the starttimestamp attribute in load API output which is stored in Morebits.wiki.page asctx.loadTime
, publicly exposed via.getLoadTime()
.In case of RFD, 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.
The only remaining usages of client clock is in: