Hi,
I want to log a user into our wiki if they are logged into our website.
I assume that I need to use the UserLoadFromSession hook, but at this
point in the code, the MW session is already active. Does it make sense
to close the MW session, configure & start my website session in order
to access the user ID, and then re-open the MW session using
wfSetupSession(), or is this not recommended?
I see that some people access their website username from another
cookie, but I'd like to avoid this if possible.
This is the rough idea that seems to be working, I think:
$wgHooks['UserLoadFromSession'][] = function($user, &$result) {
// Check if the user is already logged into MW.
// How do I do this???
// Close MW session.
session_write_close();
// Configure website session.
session_name('x');
session_save_path('x');
ini_set('session.cookie_domain', '.x');
session_start();
// Check if user is logged in to website.
if (isset($_SESSION['Zend_Auth'])) {
$userId = (int)$_SESSION['Zend_Auth']['storage'];
// Close website session.
session_write_close();
// temp, look up username in DB.
if ($userId == 123) {
$username = 'xyz';
}
$user = User::newFromName($username);
// Log user in.
$user->setToken();
$user->saveSettings();
wfSetupSession();
$user->setCookies();
} else {
wfSetupSession();
}
return true;
};
I'm not sure if this is the best option, and also how to bypass this
code if the user is already logged into the wiki.
I also need to auto-create an account for users without MW accounts, but
I think I can use $user->addToDatabase() for that.
Any help would be greatly appreciated.
Glen.
So does anyone know why the Extension Matrix is not being updated? Mediawiki is generally behind the game already compared to other open source software packages (Joomla, Wordpress,etc) and now there's no page that shows new, improved and better extensions! Just makes no sense to me, but I'm hoping I missed a secret message that redirects everyone to a new spot to find all the brand new extensions.
Sent from my iPad