On 07/05/12 15:13, Paweł Muszyński wrote:
Hello.
When someone is logged into my portal, and he has an account in MediaWiki, I want him to be logged into MediaWiki.
As a first step to achieve this, I wanted to do an autologin of Pmuszynski. This is my function attaced to UserLoadFromSession hook:
function pmUserAuth($user, &$result) {
$user = User::NewFromName('Pmuszynski');
$id = User::idFromName('Pmuszynski'); $user->setId( $id ); $user->loadfromId();
No need for this. Just User::newFromName + $user->load() will do the same
wfSetupSession(); $user->setCookies();
This is fine, but do you really need setCookies() if you are overriding it everytime? It won't get called
$user->setToken(); $user->saveSettings();
No need for these
$user->saveToCache() ; $result = true; return true;
};
But I'm getting following error on entering Wiki:
Warning: array_merge(): Argument #1 is not an array in /wiki/includes/User.php on line 2298 Warning: array_unique() expects parameter 1 to be array, null given in /wiki/includes/User.php on line 2298 Warning: Invalid argument supplied for foreach() in /wiki/includes/User.php on line 3472 Warning: Invalid argument supplied for foreach() in /wiki/includes/User.php on line 3481 MediaWiki internal error.
What am I missing?
I think your problem is that, even though you're correctly setting up $user there, the reassignation of $user is not reaching the caller (it's not passed by reference). And things like cookies sent to the user won't take effect if checked later in the same request (you'd need to fake the received data).
I try to implement my own authorization scheme - connect MediaWiki to the user database of my other site.
What you're trying to do seems harder than needed. Take a look at https://www.mediawiki.org/wiki/AuthPlugin