r17974 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17973‎ | r17974 | r17975 >
Date:06:45, 28 November 2006
Author:brion
Status:old
Tags:
Comment:
Use explicit db name in $wgCentralAuthDatabase so it's not required
to set up a fancy $wgDBservers thingy with a totally separate entry
for the central server unless you really have multiple servers, and
then you can just stick the groupLoads setting on it instead of a
second entry that's only usable for CentralAuth
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/extensions/CentralAuth/migratePass1.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -29,7 +29,7 @@
3030 function newFromLocal( $dbname, $userid ) {
3131 $dbr = wfGetDB( DB_MASTER, 'CentralAuth' );
3232 $username = $dbr->selectField(
33 - array( 'globaluser', 'localuser' ),
 33+ array( self::tableName( 'globaluser' ), self::tableName( 'localuser' ) ),
3434 'gu_name',
3535 array(
3636 'gu_id=lu_global_id',
@@ -55,13 +55,23 @@
5656 $this->mName = $username;
5757 }
5858
 59+ static function tableName( $name ) {
 60+ global $wgCentralAuthDatabase;
 61+ return
 62+ '`' .
 63+ $wgCentralAuthDatabase .
 64+ '`.`' .
 65+ $name .
 66+ '`';
 67+ }
 68+
5969 /**
6070 * this code is crap
6171 */
6272 function getId() {
6373 $dbr = wfGetDB( DB_MASTER, 'CentralAuth' );
6474 $id = $dbr->selectField(
65 - 'globaluser',
 75+ self::tableName( 'globaluser' ),
6676 'gu_id',
6777 array( 'gu_name' => $this->mName ),
6878 __METHOD__ );
@@ -79,7 +89,7 @@
8090 $dbw = wfGetDB( DB_MASTER, 'CentralAuth' );
8191 list( $salt, $hash ) = $this->saltedPassword( $password );
8292 $ok = $dbw->insert(
83 - 'globaluser',
 93+ self::tableName( 'globaluser' ),
8494 array(
8595 'gu_name' => $this->mName,
8696
@@ -113,7 +123,7 @@
114124 static function storeLocalData( $dbname, $row, $editCount ) {
115125 $dbw = wfGetDB( DB_MASTER, 'CentralAuth' );
116126 $ok = $dbw->insert(
117 - 'localuser',
 127+ self::tableName( 'localuser' ),
118128 array(
119129 'lu_global_id' => null, // Not yet migrated!
120130 'lu_dbname' => $dbname,
@@ -135,7 +145,7 @@
136146 */
137147 function storeGlobalData( $salt, $hash, $email, $emailAuth ) {
138148 $dbw = wfGetDB( DB_MASTER, 'CentralAuth' );
139 - $dbw->insert( 'globaluser',
 149+ $dbw->insert( self::tableName( 'globaluser' ),
140150 array(
141151 'gu_name' => $this->mName,
142152 'gu_salt' => $salt,
@@ -286,31 +296,6 @@
287297 }
288298
289299 /**
290 - * Check if the current username is defined and attached on this wiki yet
291 - * @param $dbname Local database key to look up
292 - * @return ("attached", "unattached", "no local user")
293 - */
294 - /*
295 - function isAttached( $dbname ) {
296 - $dbr = wfGetDB( DB_MASTER, 'CentralAuth' );
297 - $row = $dbr->selectRow( 'localuser',
298 - array( 'lu_attached' ),
299 - array( 'lu_name' => $this->mName, 'lu_database' => $dbname ),
300 - __METHOD__ );
301 -
302 - if( !$row ) {
303 - return "no local user";
304 - }
305 -
306 - if( $row->lu_attached ) {
307 - return "attached";
308 - } else {
309 - return "unattached";
310 - }
311 - }
312 - */
313 -
314 - /**
315300 * Add a local account record for the given wiki to the central database.
316301 * @param string $dbname
317302 * @param int $localid
@@ -320,7 +305,7 @@
321306 */
322307 function addLocal( $dbname, $localid ) {
323308 $dbw = wfGetDB( DB_MASTER, 'CentralAuth' );
324 - $dbw->insert( 'localuser',
 309+ $dbw->insert( self::tableName( 'localuser' ),
325310 array(
326311 'lu_global_id' => $this->getId(),
327312 'lu_dbname' => $dbname,
@@ -336,7 +321,7 @@
337322 */
338323 public function attach( $dbname, $method ) {
339324 $dbw = wfGetDB( DB_MASTER, 'CentralAuth' );
340 - $dbw->update( 'localuser',
 325+ $dbw->update( self::tableName( 'localuser' ),
341326 array(
342327 // Boo-yah!
343328 'lu_global_id' => $this->getId(),
@@ -365,7 +350,7 @@
366351 */
367352 public function authenticate( $password ) {
368353 $dbw = wfGetDB( DB_MASTER, 'CentralAuth' );
369 - $row = $dbw->selectRow( 'globaluser',
 354+ $row = $dbw->selectRow( self::tableName( 'globaluser' ),
370355 array( 'gu_salt', 'gu_password', 'gu_locked' ),
371356 array( 'gu_id' => $this->getId() ),
372357 __METHOD__ );
@@ -424,7 +409,7 @@
425410
426411 function fetchUnattached() {
427412 $dbw = wfGetDB( DB_MASTER, 'CentralAuth' );
428 - $result = $dbw->select( 'localuser',
 413+ $result = $dbw->select( self::tableName( 'localuser' ),
429414 array(
430415 'lu_dbname',
431416 'lu_local_id',
@@ -449,7 +434,8 @@
450435
451436 function getEmail() {
452437 $dbr = wfGetDB( DB_MASTER, 'CentralAuth' );
453 - return $dbr->selectField( 'globaluser', 'gu_email',
 438+ return $dbr->selectField( self::tableName( 'globaluser' ),
 439+ 'gu_email',
454440 array( 'gu_id' => $this->getId() ),
455441 __METHOD__ );
456442 }
@@ -472,7 +458,7 @@
473459 list( $salt, $hash ) = $this->saltedPassword( $password );
474460
475461 $dbw = wfGetDB( DB_MASTER, 'CentralAuth' );
476 - $result = $dbr->update( 'globaluser',
 462+ $result = $dbr->update( self::tableName( 'globaluser' ),
477463 array(
478464 'gu_salt' => $salt,
479465 'gu_password' => $hash,
Index: trunk/extensions/CentralAuth/CentralAuth.php
@@ -1,5 +1,13 @@
22 <?php
33
 4+/**
 5+ * Database name you keep central auth data in.
 6+ *
 7+ * If this is not on the primary database connection, don't forget
 8+ * to also set up $wgDBservers to have an entry with a groupLoads
 9+ * setting for the 'CentralAuth' group.
 10+ */
 11+$wgCentralAuthDatabase = 'centralauth';
412
513 /**
614 * For making pretty HTTPS links to other wikis
Index: trunk/extensions/CentralAuth/migratePass1.php
@@ -8,7 +8,7 @@
99 function migratePassOne() {
1010 $dbBackground = wfGetDB( DB_SLAVE, 'CentralAuth' ); // fixme for large dbs
1111 $result = $dbBackground->select(
12 - 'localuser',
 12+ CentralAuthUser::tableName( 'localuser' ),
1313 array( 'lu_migrated_name' ),
1414 '',
1515 __METHOD__,