3 * Auth_viaMySQL MediaWiki extension MediaWiki version 1.14.0rc1
8 * @author John Derby Russell
9 * @link http://www.mediawiki.org/w/index.php/Extension:Auth_viaMySQL
12 # Not a valid entry point, skip unless MEDIAWIKI is defined
13 if( !defined( 'MEDIAWIKI' ) )
15 echo "Auth_viaMySQL extension";
19 // Extension credits that will show up on Special:Version
20 $wgExtensionCredits['other'][] = array(
21 'name' => 'MySQL Auto Authentication -> Auth_viaMySQL',
23 'author' => 'John Derby Russell',
24 'url' => 'http://www.mediawiki.org/w/index.php/Extension:Auth_viaMySQL',
25 'description' => 'Auto-authenticates users using MySQL database',
30 * MySQL Login Database Integration
34 require_once(MW_INSTALL_PATH.'/MySQLActiveUser.php') ;
36 $wgHooks['UserLoadFromSession'][] = 'Auth_viaMySQL';
39 $wgHooks['PersonalUrls'][] = 'PersonalUrls_killLogout'; /* Disallow logout link */
41 function Auth_viaMySQL( $user, $result ) {
42 global $MySQLActiveUserData;
43 $MySQLActiveUserData->distribute_cookie_data() ;
48 * A lot of this is from User::newFromName
50 // Force usernames to capital
53 $name = $wgContLang->ucfirst( $MySQLActiveUserData->active_user_name );
55 // Clean up name according to title rules
56 $t = Title::newFromText( $name );
61 $canonicalName = $t->getText();
63 if( !User::isValidUserName( $canonicalName ) ) {
67 $user->setName( $canonicalName );
69 $user_id_fromMW_DB = $user->idFromName( $MySQLActiveUserData->active_user_name ) ;
71 $user->setId( $user_id_fromMW_DB );
72 if ( $user->getID() == 0 ) {
74 * A lot of this is from LoginForm::initUser
75 * LoginForm in in the file called SpecialUserLogin.php line 342 (version 1.14.0rc1)
77 $canonicalName = $t->getText();
78 $user->setName( $canonicalName );
79 $user->addToDatabase();
81 $user->setEmail( $MySQLActiveUserData->active_user_email );
82 $user->setRealName( '' );
85 $user->saveSettings();
87 if ( !$user->loadFromDatabase() ) {
88 // Can't load from ID, user is anonymous
94 $result = 1; // This causes the rest of the authentication process to be skipped.
95 return(false); // As should this, according to the internal error report:
99 function PersonalUrls_killLogout($personal_urls, $title) {
100 $personal_urls['logout'] = null ;
101 $personal_urls['login'] = null ;
102 $personal_urls['anonlogin'] = null ;