Followup I59dfcfb25c, language change work with out event logging

In I59dfcfb25c, for logging events when page is navigating away, we
used callbacks with mw.hook. That is wrong approach. If event logging
is disabled those callbacks will never called: it broke language change
and all use cases which navigates away from current page.

Event logging should not interfere with any ULS functionality. If ULS
functionality depends on callbacks from event logging, it is wrong.

In this patch, we give a small time window to make sure event logging is
fired, but we won't wait for its success or failure.

If eventlogging is disabled, this time window does not exist.

Change-Id: I0b7d9d8b9d1d01b99422010596ebfa80b2589d04
This commit is contained in:
Santhosh Thottingal
2013-08-17 11:15:33 +05:30
committed by Nikerabbit
parent 1f66cb22bc
commit 7649b47f5c
4 changed files with 50 additions and 36 deletions

View File

@@ -158,18 +158,30 @@
new mw.Api().parse( $.i18n( 'ext-uls-display-settings-anon-log-in-cta' ) )
.done( function ( parsedCta ) {
var deferred = new $.Deferred();
$loginCta.html( parsedCta );
$loginCta.find( 'a' ).click( function ( event ) {
event.preventDefault();
// Because browsers navigate away when clicking a link,
// we are are overriding the normal click behavior to
// allow the event be logged first - currently there is no
// local queue for events. The timeout is there to make sure
// the user gets to the new page even if event logging is slow
// or fails.
mw.hook( 'mw.uls.login.click' ).fire( function () {
// local queue for events. Since the hook system does not
// allow returning values, we have this ugly event logging
// specific hack to delay the page load if event logging
// is enabled. The promise is passed to the hook, so that
// if event logging is enabled, in can resole the promise
// immediately to avoid extra delays.
deferred.done( function () {
window.location.href = event.target.href;
} );
mw.hook( 'mw.uls.login.click' ).fire( deferred );
// Delay is zero if event logging is not enabled
window.setTimeout( function () {
deferred.resolve();
}, mw.config.get( 'wgULSEventLogging' ) * 500 );
} );
} );