[Mediawiki-l] Automatic Login using get_current_user()

Lane, Ryan Ryan.Lane at ocean.navo.navy.mil
Thu Jan 4 19:15:59 UTC 2007

> I tried filling the request variables and calling the 
> form-post because the initUser() did not appear to set the 
> values. They still do not. Perhaps I am missing some 
> necessary code in that block? (See
> below.)

Have you bothered to look at how I do this in my plugin? My code is
working with mediawiki 1.6+, and the part you are having problems with
should be almost 100% what you need line for line. (you can ignore the
$wgAuth->printDebug statements).

        $wgAuth->printDebug("User does not exist in local database;

        //Require SpecialUserlogin so that we can get a loginForm

        //This section contains a silly hack for MW
        global $wgLang;
        global $wgContLang;
        global $wgRequest;
                $wgLang = $wgContLang;
                $wgLangUnset = true;
        $wgAuth->printDebug("Creating LoginForm.",1);
        //This creates our form that'll let us create a new user in the
        $lf = new LoginForm($wgRequest);
        //The user we'll be creating...
        $wgUser = &$tmpuser;

        $wgAuth->printDebug("Creating User.",1);

        //Create the user

        //Update the user's settings

        //Initialize the user

Funny enough I just noticed I call my plugin's updateUser() function,
and not initUser() (and now looking at SpecialUserlogin.php and
initUser(), I don't actually even need to call that...).

In MediaWiki 1.8 and below it looks like $lf->initUser() didn't
automatically call $u->saveSettings(), so you'll need to make sure to
call it yourself. Since $lf->initUser() calls $wgAuth->initUser(), you
should make all changes required in that function, and manually call
saveSettings() on the user object. This is pretty confusing behavior
between the versions of MediaWiki, especially since $lf->initUser()
didn't previously save settings and it does now, and the LoginForm used
to save settings after $wgAuth->updateUser() was called and now it

Best bet is to update user info in updateUser() and initUser() in your
plugin, and call saveSettings() in both. Who knows what wacky changes
will be made in the future.


Ryan Lane

More information about the MediaWiki-l mailing list