Nur in /home/www/testwiki/: AdminSettings.php. Nur in /home/www/testwiki/: cvs14_against_mycvs14.diff. Nur in /home/www/testwiki/: cvs14update.log. Nur in /home/www/testwiki/: debug.log. diff -u -b -r /home/www/rel14_ref/includes/AuthPlugin.php /home/www/testwiki/includes/AuthPlugin.php --- /home/www/rel14_ref/includes/AuthPlugin.php 2005-03-09 10:26:46.000000000 +0100 +++ /home/www/testwiki/includes/AuthPlugin.php 2005-04-03 17:38:33.000000000 +0200 @@ -2,6 +2,16 @@ # Copyright (C) 2004 Brion Vibber # http://www.mediawiki.org/ # +# Authentication plugin for Auto-Login / Auto-Account creation +# +# See flowchart and description on +# http://bugzilla.wikimedia.org/show_bug.cgi?id=1360 +# +# T. Gries +# +# 03.04.2005 v1.1 added User->SetupSession() +# 02.04.2005 v1.0 initial +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -96,19 +106,95 @@ return false; } + function lookuptable_NameAndEmailaddressFromUserID($wgIP, &$user) { + + # Checks if a user with the given real name exists + # We use it for storing the authenticated unique userid + + # As an alternative, you can call your LDAP server here + # to get data (full name, email-address) for user $wgIP + # (see flowchart) + + # in : $wgIP : the userid (or login name) of the logged-in user + # in/out : $user object : name, emailaddress, realname(=userid) + # returns: true if a user with realname = $wgIP is found + + /* Change this according to your needs + + The lookup-table file stores three values per user: + log-in-userid|Fullname|emailaddress + + Example: + foo12345|Foo F. Foo|foo@foo.com + */ + $lines = file("/home/qs/data/uidname.dat"); + + $match=array_values(preg_grep("/^$wgIP\|.*$/i",$lines)); /* does 1st value = userid match ? */ + if ($match[0]) { + $piece=explode('|',$match[0]); + $user->mName =trim($piece[1]); /* 2nd value = full name */ + $user->mEmail =trim($piece[2]); /* 3rd value = emailaddr */ + $user->mRealName=$wgIP; + return true; + } return false; + } + /** * When creating a user account, optionally fill in preferences and such. * For instance, you might pull the email address or real name from the * external user database. * - * The User object is passed by reference so it can be modified; don't - * forget the & on your function declaration. + * The User object or a new User object are returned -- + * -- logged into the (existing or created) account + * + * See flowchart and description on + * http://bugzilla.wikimedia.org/show_bug.cgi?id=1360 + * T. Gries + * 02.04.2005 * * @param User $user * @access public */ - function initUser( &$user ) { - # Override this to do something. + function initUser() { + global $wgAutoLogin, $wgIP; + $user = new User(); + if ($wgAutoLogin) { + if (!$this->lookuptable_NameAndEmailaddressFromUserID($wgIP, $user)) { /* unknown or anonymous user */ + return $user; /* a new user */ + } else { + if ($id=$user->idForRealName()) { /* account with RealName = userid exists */ + $user->mId=$id; + $user->loadFromDatabase(); + $user->spreadBlock(); + if( !isset( $_COOKIE[ini_get('session.name')] ) ) $user->SetupSession(); + $user->setCookies(); + return $user; + } else { + if ($id=$user->idForName()) { /* account with such a name does exist: add the userid to accountname */ + $user->loadFromDatabase; + if ($user->mRealName!='') { + $user->mName .= ' ('.strtolower($wgIP).')'; + } else { // update user entry and store mRealName := uid + $user->mId=$id; + $user->mRealName=$wgIP; + $user->saveSettings(); + $user->spreadBlock(); + if( !isset( $_COOKIE[ini_get('session.name')] ) ) $user->SetupSession(); + $user->setCookies(); + return $user; + } + } + /* no account with that name yet - create one. Use defaults from loaddefaults of new User() */ + // set default user option from content language + $user->mPassword=$user->encryptPassword($user->randomPassword()); /* users do not know their passwords */ + $user->addToDatabase(); + $user->spreadBlock(); + if( !isset( $_COOKIE[ini_get('session.name')] ) ) $user->SetupSession(); + $user->setCookies(); + return $user; + } + } + } else return $user; } } diff -u -b -r /home/www/rel14_ref/includes/DefaultSettings.php /home/www/testwiki/includes/DefaultSettings.php --- /home/www/rel14_ref/includes/DefaultSettings.php 2005-03-21 02:59:52.000000000 +0100 +++ /home/www/testwiki/includes/DefaultSettings.php 2005-04-03 16:55:49.000000000 +0200 @@ -766,6 +766,8 @@ $wgDefaultUserOptions = array(); # Whether or not to allow real name fields. Defaults to true. +# This will be set to false with AutoLogin, +# as this uses real name field for storing userid of logged-in user $wgAllowRealName = true; # Use XML parser? @@ -923,6 +925,13 @@ */ $wgAuth = null; +/* see bugzilla 1360 (Auto-Login / Auto-Account creation) */ +/* see AuthPlugin.php */ +$wgAutoLogin = true; + + +if ($wgAutoLogin) $wgAllowRealName=false; + /** * Global list of hooks. * Add a hook by doing: diff -u -b -r /home/www/rel14_ref/includes/Setup.php /home/www/testwiki/includes/Setup.php --- /home/www/rel14_ref/includes/Setup.php 2005-03-14 03:13:38.000000000 +0100 +++ /home/www/testwiki/includes/Setup.php 2005-04-03 17:20:38.000000000 +0200 @@ -17,6 +17,7 @@ # global $wgProfiling, $wgProfileSampleRate, $wgIP, $wgUseSquid, $IP; +global $wgAutoLogin; if( !isset( $wgProfiling ) ) $wgProfiling = false; @@ -54,6 +55,14 @@ array_pop($hopips); } $wgIP = trim(end($hopips)); +} else if($wgAutoLogin) { + if (isset($_SERVER['REMOTE_USER'])) { + $wgIP=$_SERVER['REMOTE_USER']; + } else { + $host=gethostbyaddr($_SERVER['REMOTE_ADDR']); + list($wgIP,$domain)=explode(".",$host); + } + /* $wgIP is userid or hostname of the logged-in user */ } elseif( isset( $_SERVER['REMOTE_ADDR'] ) ) { $wgIP = $_SERVER['REMOTE_ADDR']; } else { @@ -242,14 +251,6 @@ $wgAuth = new AuthPlugin(); } -if( $wgCommandLineMode ) { - # Used for some maintenance scripts; user session cookies can screw things up - # when the database is in an in-between state. - $wgUser = new User(); -} else { - $wgUser = User::loadFromSession(); -} - wfProfileOut( $fname.'-User' ); wfProfileIn( $fname.'-language2' ); @@ -290,6 +291,16 @@ $wgContLang = setupLangObj( $wgContLangClass ); $wgContLang->initEncoding(); +# The following lines are moved from above the language settings +# http://bugzilla.wikimedia.org/show_bug.cgi?id=1805 explains why +if( $wgCommandLineMode ) { + # Used for some maintenance scripts; user session cookies can screw things up + # when the database is in an in-between state. + $wgUser = new User(); +} else { + $wgUser = User::loadFromSession(); +} + // set default user option from content language if( !$wgUser->mDataLoaded ) { $wgUser->loadDefaultFromLanguage(); diff -u -b -r /home/www/rel14_ref/includes/Skin.php /home/www/testwiki/includes/Skin.php --- /home/www/rel14_ref/includes/Skin.php 2005-03-08 16:22:33.000000000 +0100 +++ /home/www/testwiki/includes/Skin.php 2005-04-03 17:09:57.000000000 +0200 @@ -729,10 +729,15 @@ $tl = " ({$tl})"; + global $wgAutoLogin; + if (!$wgAutoLogin) { + $logoutLink = $this->makeKnownLink( $lo, wfMsg( 'logout' ), + "returnto={$rt}" ) . ' | '; + } else $logoutLink = ''; + $s .= $this->makeKnownLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$n}", $n ) . "{$tl}
" . - $this->makeKnownLink( $lo, wfMsg( 'logout' ), - "returnto={$rt}" ) . ' | ' . + $logoutLink . $this->specialLink( 'preferences' ); } $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ), diff -u -b -r /home/www/rel14_ref/includes/SkinTemplate.php /home/www/testwiki/includes/SkinTemplate.php --- /home/www/rel14_ref/includes/SkinTemplate.php 2005-03-18 09:01:05.000000000 +0100 +++ /home/www/testwiki/includes/SkinTemplate.php 2005-04-02 09:13:41.000000000 +0200 @@ -386,7 +386,7 @@ wfProfileIn( $fname ); /* set up the default links for the personal toolbar */ - global $wgShowIPinHeader; + global $wgShowIPinHeader, $wgAutoLogin; $personal_urls = array(); if ($this->loggedin) { $personal_urls['userpage'] = array( @@ -412,10 +412,12 @@ 'text' => wfMsg('mycontris'), 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username ) ) ); + if (!$wgAutoLogin) { $personal_urls['logout'] = array( 'text' => wfMsg('userlogout'), 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl ) ); + } } else { if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) { $personal_urls['anonuserpage'] = array( @@ -429,12 +431,13 @@ 'href' => &$usertalkUrlDetails['href'], 'class' => $usertalkUrlDetails['exists']?false:'new' ); + if (!$wgAutoLogin) { $personal_urls['anonlogin'] = array( 'text' => wfMsg('userlogin'), 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ) ); - } else { - + } + } else if (!$wgAutoLogin) { $personal_urls['login'] = array( 'text' => wfMsg('userlogin'), 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ) diff -u -b -r /home/www/rel14_ref/includes/SpecialPreferences.php /home/www/testwiki/includes/SpecialPreferences.php --- /home/www/rel14_ref/includes/SpecialPreferences.php 2005-02-21 03:00:05.000000000 +0100 +++ /home/www/testwiki/includes/SpecialPreferences.php 2005-04-02 11:32:05.000000000 +0200 @@ -190,7 +190,10 @@ if( $wgEnableEmail ) { $wgUser->setEmail( $this->mUserEmail ); } + global $wgAutoLogin; + if (!$wgAutoLogin) { $wgUser->setRealName( $this->mRealName ); + } $wgUser->setOption( 'language', $this->mUserLanguage ); $wgUser->setOption( 'variant', $this->mUserVariant ); $wgUser->setOption( 'nickname', $this->mNick ); diff -u -b -r /home/www/rel14_ref/includes/SpecialUserlogin.php /home/www/testwiki/includes/SpecialUserlogin.php --- /home/www/rel14_ref/includes/SpecialUserlogin.php 2005-03-17 01:13:26.000000000 +0100 +++ /home/www/testwiki/includes/SpecialUserlogin.php 2005-04-02 02:11:16.000000000 +0200 @@ -16,12 +16,18 @@ function wfSpecialUserlogin() { global $wgCommandLineMode; global $wgRequest; + global $wgAutoLogin, $wgOut; + if (!$wgAutoLogin) { if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get('session.name')] ) ) { User::SetupSession(); } $form = new LoginForm( $wgRequest ); $form->execute(); + } else { + $wgOut->addHTML( wfMsg('disabled_on_this_wiki') ); + $wgOut->returntoMain(); + } } /** diff -u -b -r /home/www/rel14_ref/includes/SpecialUserlogout.php /home/www/testwiki/includes/SpecialUserlogout.php --- /home/www/rel14_ref/includes/SpecialUserlogout.php 2005-03-17 01:13:26.000000000 +0100 +++ /home/www/testwiki/includes/SpecialUserlogout.php 2005-04-02 00:46:35.000000000 +0200 @@ -10,9 +10,11 @@ */ function wfSpecialUserlogout() { global $wgUser, $wgOut, $returnto; + global $wgAutoLogin; if (wfRunHooks('UserLogout', array(&$wgUser))) { + if (!$wgAutoLogin) { $wgUser->logout(); wfRunHooks('UserLogoutComplete', array(&$wgUser)); @@ -20,6 +22,7 @@ $wgOut->mCookies = array(); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->addHTML( wfMsg( 'logouttext' ) ); + } else $wgOut->addHTML( wfMsg("disabled_on_this_wiki") ); $wgOut->returnToMain(); } diff -u -b -r /home/www/rel14_ref/includes/User.php /home/www/testwiki/includes/User.php --- /home/www/rel14_ref/includes/User.php 2005-03-16 08:49:03.000000000 +0100 +++ /home/www/testwiki/includes/User.php 2005-04-02 15:27:34.000000000 +0200 @@ -312,19 +312,19 @@ * @static */ function loadFromSession() { - global $wgMemc, $wgDBname; + global $wgMemc, $wgDBname, $wgAuth; if ( isset( $_SESSION['wsUserID'] ) ) { if ( 0 != $_SESSION['wsUserID'] ) { $sId = $_SESSION['wsUserID']; } else { - return new User(); + return $wgAuth->initUser(); } } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) { $sId = IntVal( $_COOKIE["{$wgDBname}UserID"] ); $_SESSION['wsUserID'] = $sId; } else { - return new User(); + return $wgAuth->initUser(); } if ( isset( $_SESSION['wsUserName'] ) ) { $sName = $_SESSION['wsUserName']; @@ -332,7 +332,7 @@ $sName = $_COOKIE["{$wgDBname}UserName"]; $_SESSION['wsUserName'] = $sName; } else { - return new User(); + return $wgAuth->initUser(); } $passwordCorrect = FALSE; @@ -351,7 +351,7 @@ } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) { $passwordCorrect = $user->mToken == $_COOKIE["{$wgDBname}Token"]; } else { - return new User(); # Can't log in from session + return $wgAuth->initUser(); # Can't log in from session } if ( ( $sName == $user->mName ) && $passwordCorrect ) { @@ -364,7 +364,7 @@ $user->spreadBlock(); return $user; } - return new User(); # Can't log in from session + return $wgAuth->initUser(); # Can't log in from session } /** @@ -912,6 +912,24 @@ } /** + * Checks if a user with the given name exists, returns the ID + */ + function idForRealName() { + $fname = 'User::idForRealName'; + + $gotid = 0; + $s = trim( $this->mRealName ); + if ( 0 == strcmp( '', $s ) ) return 0; + + $dbr =& wfGetDB( DB_SLAVE ); + $id = $dbr->selectField( 'user', 'user_id', array( 'user_real_name' => $s ), $fname ); + if ( $id === false ) { + $id = 0; + } + return $id; + } + + /** * Add user object to the database */ function addToDatabase() { diff -u -b -r /home/www/rel14_ref/languages/Language.php /home/www/testwiki/languages/Language.php --- /home/www/rel14_ref/languages/Language.php 2005-03-21 17:38:33.000000000 +0100 +++ /home/www/testwiki/languages/Language.php 2005-04-02 00:26:36.000000000 +0200 @@ -527,6 +527,8 @@ 'login' => 'Log in', 'loginprompt' => "You must have cookies enabled to log in to {{SITENAME}}.", 'userlogin' => 'Create an account or log in', +'disabled_on_this_wiki' => '
The function you came across is permanently disabled at this wiki, +because we use auto-login/auto-account creation techniques and neither login nor logout functions are needed.
', 'logout' => 'Log out', 'userlogout' => 'Log out', 'notloggedin' => 'Not logged in', Nur in /home/www/testwiki/: LocalSettings.php. Nur in /home/www/testwiki/: x.diff.