r24588 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24587‎ | r24588 | r24589 >
Date:16:34, 4 August 2007
Author:brion
Status:old
Tags:
Comment:
Clean up autocreation a smidge... let the auth plugin know whether the user you're setting up was created manually or by the autocreation path, and have the CentralAuth plugin know whether it should be attaching (for autocreate) or not (for non-autocreate)
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthPlugin.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/extensions/CentralAuth/central-auth.sql (modified) (history)
  • /trunk/phase3/includes/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialUserlogin.php
@@ -296,7 +296,7 @@
297297 return false;
298298 }
299299
300 - return $this->initUser( $u );
 300+ return $this->initUser( $u, false );
301301 }
302302
303303 /**
@@ -304,10 +304,11 @@
305305 * Give it a User object that has been initialised with a name.
306306 *
307307 * @param $u User object.
 308+ * @param $autocreate boolean -- true if this is an autocreation via auth plugin
308309 * @return User object.
309310 * @private
310311 */
311 - function initUser( $u ) {
 312+ function initUser( $u, $autocreate ) {
312313 global $wgAuth;
313314
314315 $u->addToDatabase();
@@ -320,7 +321,7 @@
321322 $u->setRealName( $this->mRealName );
322323 $u->setToken();
323324
324 - $wgAuth->initUser( $u );
 325+ $wgAuth->initUser( $u, $autocreate );
325326
326327 $u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
327328 $u->saveSettings();
@@ -359,7 +360,7 @@
360361 */
361362 if ( $wgAuth->autoCreate() && $wgAuth->userExists( $u->getName() ) ) {
362363 if ( $wgAuth->authenticate( $u->getName(), $this->mPassword ) ) {
363 - $u = $this->initUser( $u );
 364+ $u = $this->initUser( $u, true );
364365 } else {
365366 return self::WRONG_PLUGIN_PASS;
366367 }
Index: trunk/extensions/CentralAuth/CentralAuthPlugin.php
@@ -144,9 +144,6 @@
145145 * @public
146146 */
147147 function updateExternalDB( $user ) {
148 - global $wgDBname;
149 - $central = new CentralAuthUser( $user->getName() );
150 - $central->addLocalName( $wgDBname );
151148 return true;
152149 }
153150
@@ -176,8 +173,18 @@
177174 * @public
178175 */
179176 function addUser( $user, $password, $email='', $realname='' ) {
180 - $central = new CentralAuthUser( $user->getName() );
181 - return $central->register( $password, $email, $realname );
 177+ global $wgCentralAuthAutoNew;
 178+ if( $wgCentralAuthAutoNew ) {
 179+ $central = new CentralAuthUser( $user->getName() );
 180+ if( !$central->exists() && !$central->listUnattached() ) {
 181+ // Username is unused; set up as a global account
 182+ // @fixme is this even vaguely reliable? pah
 183+ global $wgDBname;
 184+ $central->register( $password, $email, $realname );
 185+ $central->attach( $wgDBname, 'new' );
 186+ }
 187+ }
 188+ return true;
182189 }
183190
184191
@@ -206,12 +213,15 @@
207214 * @param $user User object.
208215 * @public
209216 */
210 - function initUser( &$user ) {
211 - global $wgDBname;
212 - $central = new CentralAuthUser( $user->getName() );
213 - $central->attach( $wgDBname, 'new' );
214 -
215 - $this->updateUser( $user );
 217+ function initUser( &$user, $autocreate=false ) {
 218+ if( $autocreate ) {
 219+ $central = new CentralAuthUser( $user->getName() );
 220+ if( $central->exists() ) {
 221+ global $wgDBname;
 222+ $central->attach( $wgDBname, 'login' );
 223+ $this->updateUser( $user );
 224+ }
 225+ }
216226 }
217227 }
218228
Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -771,6 +771,19 @@
772772 array(
773773 'ln_dbname' => $dbname,
774774 'ln_name' => $this->mName ),
 775+ __METHOD__,
 776+ array( 'IGNORE' ) );
 777+ $dbw->commit();
 778+ }
 779+
 780+ function removeLocalName( $dbname ) {
 781+ $dbw = self::getCentralDB();
 782+ $dbw->begin();
 783+ $this->lazyImportLocalNames();
 784+ $dbw->delete( self::tableName( 'localnames' ),
 785+ array(
 786+ 'ln_dbname' => $dbname,
 787+ 'ln_name' => $this->mName ),
775788 __METHOD__ );
776789 $dbw->commit();
777790 }
Index: trunk/extensions/CentralAuth/CentralAuth.php
@@ -9,6 +9,11 @@
1010 */
1111 $wgCentralAuthDatabase = 'centralauth';
1212
 13+/**
 14+ * If true, new account registrations will be registered globally if
 15+ * the username hasn't been used elsewhere.
 16+ */
 17+$wgCentralAuthAutoNew = false;
1318
1419 /**
1520 * If true, existing unattached accounts will be automatically migrated
Index: trunk/extensions/CentralAuth/central-auth.sql
@@ -104,7 +104,8 @@
105105 'mail',
106106 'password',
107107 'admin',
108 - 'new'),
 108+ 'new',
 109+ 'login'),
109110
110111 primary key (lu_dbname, lu_name),
111112 key (lu_name, lu_dbname)

Follow-up revisions

RevisionCommit summaryAuthorDate
r24631Merged revisions 24480-24600 via svnmerge from...david18:39, 6 August 2007

Status & tagging log