mediawiki.cookie: Implement expiry option as time from now
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 10 Feb 2015 06:12:15 +0000 (06:12 +0000)
committerMattflaschen <mflaschen@wikimedia.org>
Sat, 14 Feb 2015 00:55:45 +0000 (00:55 +0000)
commitb7796c608cb1b80b7f242a8914a3bd66fb4f8f2e
tree4dcc1ed53118ed2b2619bd98896719e6e07e02bf
parent7706c906b8a659cc1e817ef5ac026e204dac9767
mediawiki.cookie: Implement expiry option as time from now

The current option (Date object) isn't user-friendly as it requires
users to construct a Date and set the time offset accordingly.

They likely do that using an offset, not an exact date. Optimise
for the common case by supporting this directly (similar to the
server-side cookie expiration logic, as well as our ObjectCache
classes and other systems).

Support for exact dates is kept as this is still useful for the
native transport layer where timestamps are used. But the API
surface now supports durations as well.

Note that there was an undocumented fall-through of options.expires
as number of days. This is implemented by upstream jquery.cookie
and mw.cookie previously didn't recognise or reject this value so
it fell through.

Change-Id: Ia2e51d3a3e4d19484367cb74003c4f756c87345d
resources/src/mediawiki/mediawiki.cookie.js
tests/qunit/suites/resources/mediawiki/mediawiki.cookie.test.js