Skip to content

Commit bc0ee4b

Browse files
committed
[Fixed] Erratic behavior on first page load
This behavior would redirect the user to Special:Connect, even though they were already connected. On Special:Connect, because the user is already logged in, they wouldn't see any useful information and there would be no "return to previous page" button. The only way to exit Special:Connect would be to explicitly click the back button in their browser. Steps to reproduce the bug can be found in the comment in FacebookHooks.php.
1 parent 782c1c5 commit bc0ee4b

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

Facebook/FacebookHooks.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,37 @@ public static function ResourceLoaderGetConfigVars( &$vars ) {
316316
if ( $wgUser->isLoggedIn() ) {
317317
global $facebook;
318318
$ids = FacebookDB::getFacebookIDs($wgUser);
319-
// If the Facebook session is invalid, let the client know who we expect
320-
// to click "Log in with Facebook". Otherwise, if we have have a valid
321-
// session but for *someone else*, let the client know this as well.
322-
if (count($ids) && (!$facebook->getUser() || $facebook->getUser() != $ids[0])) {
319+
// If the user is logged in, let the JavaScript code know who the
320+
// account belongs to. The primary reason for this is so that if a
321+
// user logs in to Facebook with a different account, we can show
322+
// the "facebooklogoutandcontinue" form.
323+
//
324+
// Previously, if the user was logged in and had a valid Facebook
325+
// session, we would skip this step with the mentality that it was
326+
// unnecessary as the JavaScript code would obviously already know
327+
// the Facebook ID. However, this created a problem that can be
328+
// reproduced as follows:
329+
// 1. Log in to MediaWiki with a valid Facebook session
330+
// 2. In another tab, log out of Facebook and then log in again
331+
// as the same user, creating a different session
332+
// 3. Now reload the MediaWiki page. The server will see a valid
333+
// session and skip the fbId variable. However, the client
334+
// will fire the Facebook Login event because a new session
335+
// was picked up, even though the user was also logged in the
336+
// last time the page loaded.
337+
// Now, because the JavaScript can't find the fbId variable, it
338+
// assumes that the MediaWiki account isn't connected to a Facebook
339+
// account and shows the "facebookmergeaccount" form. However, when
340+
// this form is retrieved, the new session is synchronized to the
341+
// server and the AJAX request is invalid because you can't merge
342+
// an account that is already connected to a Facebook user.
343+
//
344+
// In and of itself, we skip this extra check and always include
345+
// the fbId variable.
346+
//
347+
// There must be a prize for finding bugs like this one. Because
348+
// seriously, I deserve it.
349+
if ( count( $ids ) ) {
323350
$vars['fbId'] = strval( $ids[0] );
324351
}
325352
}

Facebook/modules/ext.facebook.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
// if the server needs a valid access_token immediately, it can be
103103
// accomplished by posting the access_token to an AJAX method that
104104
// calls $facebook->setPersistentData('access_token', $access_token);
105+
// It also might be the case where an AJAX call, even without
106+
// explicitly setting the access token, causes this to happen by
107+
// automatically synchronizing the new cookie state with the server.
105108
//window.location.href = window.location.href;
106109

107110
// Because we don't reload, acknowledge the login by hiding the
@@ -114,17 +117,7 @@
114117
}
115118
} else {
116119
// New connection, show a MergeAccount form
117-
//
118-
// 2/5/12 - This is showing erratic behavior when the page first
119-
// loads. For now, send all traffic directly to Special:Connect.
120-
// It seems the root cause is that the AJAX request actually
121-
// syncs the Facebook session to the server when it requests the
122-
// form. If this is the cause, we can use it to our advantage.
123-
// TODO: In FacebookInit::init(), only instantiate the Facebook
124-
// API if it isn't an AJAX request. Then, in the AJAX form classes,
125-
// instantiate the API *after* we compute the state of authentication.
126-
window.getAndShowGetForm();
127-
//window.getAndShowGetForm('facebookmergeaccount');
120+
window.getAndShowGetForm('facebookmergeaccount');
128121
}
129122
} else {
130123
// User is trying to log in with Facebook. If the user exists, they will

0 commit comments

Comments
 (0)