Index: trunk/phase3/includes/SpecialUserlogin.php |
— | — | @@ -296,7 +296,7 @@ |
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
300 | | - return $this->initUser( $u ); |
| 300 | + return $this->initUser( $u, false ); |
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
— | — | @@ -304,10 +304,11 @@ |
305 | 305 | * Give it a User object that has been initialised with a name. |
306 | 306 | * |
307 | 307 | * @param $u User object. |
| 308 | + * @param $autocreate boolean -- true if this is an autocreation via auth plugin |
308 | 309 | * @return User object. |
309 | 310 | * @private |
310 | 311 | */ |
311 | | - function initUser( $u ) { |
| 312 | + function initUser( $u, $autocreate ) { |
312 | 313 | global $wgAuth; |
313 | 314 | |
314 | 315 | $u->addToDatabase(); |
— | — | @@ -320,7 +321,7 @@ |
321 | 322 | $u->setRealName( $this->mRealName ); |
322 | 323 | $u->setToken(); |
323 | 324 | |
324 | | - $wgAuth->initUser( $u ); |
| 325 | + $wgAuth->initUser( $u, $autocreate ); |
325 | 326 | |
326 | 327 | $u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 ); |
327 | 328 | $u->saveSettings(); |
— | — | @@ -359,7 +360,7 @@ |
360 | 361 | */ |
361 | 362 | if ( $wgAuth->autoCreate() && $wgAuth->userExists( $u->getName() ) ) { |
362 | 363 | if ( $wgAuth->authenticate( $u->getName(), $this->mPassword ) ) { |
363 | | - $u = $this->initUser( $u ); |
| 364 | + $u = $this->initUser( $u, true ); |
364 | 365 | } else { |
365 | 366 | return self::WRONG_PLUGIN_PASS; |
366 | 367 | } |
Index: trunk/extensions/CentralAuth/CentralAuthPlugin.php |
— | — | @@ -144,9 +144,6 @@ |
145 | 145 | * @public |
146 | 146 | */ |
147 | 147 | function updateExternalDB( $user ) { |
148 | | - global $wgDBname; |
149 | | - $central = new CentralAuthUser( $user->getName() ); |
150 | | - $central->addLocalName( $wgDBname ); |
151 | 148 | return true; |
152 | 149 | } |
153 | 150 | |
— | — | @@ -176,8 +173,18 @@ |
177 | 174 | * @public |
178 | 175 | */ |
179 | 176 | 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; |
182 | 189 | } |
183 | 190 | |
184 | 191 | |
— | — | @@ -206,12 +213,15 @@ |
207 | 214 | * @param $user User object. |
208 | 215 | * @public |
209 | 216 | */ |
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 | + } |
216 | 226 | } |
217 | 227 | } |
218 | 228 | |
Index: trunk/extensions/CentralAuth/CentralAuthUser.php |
— | — | @@ -771,6 +771,19 @@ |
772 | 772 | array( |
773 | 773 | 'ln_dbname' => $dbname, |
774 | 774 | '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 ), |
775 | 788 | __METHOD__ ); |
776 | 789 | $dbw->commit(); |
777 | 790 | } |
Index: trunk/extensions/CentralAuth/CentralAuth.php |
— | — | @@ -9,6 +9,11 @@ |
10 | 10 | */ |
11 | 11 | $wgCentralAuthDatabase = 'centralauth'; |
12 | 12 | |
| 13 | +/** |
| 14 | + * If true, new account registrations will be registered globally if |
| 15 | + * the username hasn't been used elsewhere. |
| 16 | + */ |
| 17 | +$wgCentralAuthAutoNew = false; |
13 | 18 | |
14 | 19 | /** |
15 | 20 | * If true, existing unattached accounts will be automatically migrated |
Index: trunk/extensions/CentralAuth/central-auth.sql |
— | — | @@ -104,7 +104,8 @@ |
105 | 105 | 'mail', |
106 | 106 | 'password', |
107 | 107 | 'admin', |
108 | | - 'new'), |
| 108 | + 'new', |
| 109 | + 'login'), |
109 | 110 | |
110 | 111 | primary key (lu_dbname, lu_name), |
111 | 112 | key (lu_name, lu_dbname) |