Make User::newFromName set the user object's ID attribute, so it can
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 29 Nov 2004 17:58:28 +0000 (17:58 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 29 Nov 2004 17:58:28 +0000 (17:58 +0000)
be used for other methods and lazy loading. Previously, you had to use
the class method idForName and assign its value using setId(). Since
all the code that was using newFromName was doing this, it seems like
client programs want a "real" User returned from newFromName. Replaced
client code that was doing newFromName, idForName, setId with just
newFromName. This doesn't seem to break newFromName's semantics; it
seems intuitive (to me) that the user object returned from newFromName
should be usable as returned.

includes/Article.php
includes/SpecialEmailuser.php
includes/SpecialUserlevels.php
includes/SpecialUserlogin.php
includes/User.php

index 13b42ef..ae99a95 100644 (file)
@@ -1877,7 +1877,6 @@ class Article {
                                $shortTitle != $wgUser->getName())
                        {
                                $other = User::newFromName($shortTitle);
-                               $other->setID(User::idFromName($shortTitle));
                                $other->setNewtalk(1);
                                $other->saveNewtalk();
                        }
index 5da20d8..6006b25 100644 (file)
@@ -40,13 +40,12 @@ function wfSpecialEmailuser( $par ) {
                return;
        }
        $nu = User::newFromName( $nt->getText() );
-       $id = $nu->idForName();
 
-       if ( 0 == $id ) {
+       if ( 0 == $nu->getID() ) {
                $wgOut->errorpage( "noemailtitle", "noemailtext" );
                return;
        }
-       $nu->setID( $id );
+
        $address = $nu->getEmail();
 
        if ( ( false === strpos( $address, "@" ) ) ||
index 87a7abb..78581d0 100644 (file)
@@ -115,12 +115,11 @@ class UserlevelsForm extends HTMLForm {
                        $wgOut->addHTML('<p>'.wfMsg('nosuchusershort',$username).'</p>');
                        return;
                }
-               $id = $u->idForName();
-               if($id == 0) {
+
+               if($u->getID() == 0) {
                        $wgOut->addHTML('<p>'.wfMsg('nosuchusershort',$username).'</p>');
                        return;
                }               
-               $u->setID( $id );
 
                $groups = $u->getGroups();
                $logcomment = ' ';
@@ -214,12 +213,11 @@ class UserlevelsForm extends HTMLForm {
                        $wgOut->addHTML('<p>'.wfMsg('nosuchusershort',$username).'</p>');
                        return;
                }
-               $id = $user->idForName();
-               if($id == 0) {
+
+               if($user->getID() == 0) {
                        $wgOut->addHTML('<p>'.wfMsg('nosuchusershort',$username).'</p>');
                        return;
                }               
-               $user->setID( $id );
                
                $groups = $user->getGroups();
 
index 0a913cf..87c004c 100644 (file)
@@ -240,8 +240,7 @@ class LoginForm {
                        $this->mainLoginForm( wfMsg( 'noname' ) );
                        return;
                }
-               $id = $u->idForName();
-               if ( 0 == $id ) {
+               if ( 0 == $u->getID() ) {
                        global $wgAuth;
                        /**
                         * If the external authentication plugin allows it,
@@ -257,7 +256,6 @@ class LoginForm {
                                return;
                        }
                } else {
-                       $u->setId( $id );
                        $u->loadFromDatabase();
                }
                if (!$u->checkPassword( $this->mPassword )) {
@@ -302,12 +300,11 @@ class LoginForm {
                        $this->mainLoginForm( wfMsg( 'noname' ) );
                        return;
                }
-               $id = $u->idForName();
-               if ( 0 == $id ) {
+               if ( 0 == $u->getID() ) {
                        $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
                        return;
                }
-               $u->setId( $id );
+
                $u->loadFromDatabase();
 
                $error = $this->mailPasswordInternal( $u );
index 07d0227..d9aa940 100644 (file)
@@ -55,6 +55,7 @@ class User {
                        return NULL;
                } else {
                        $u->setName( $t->getText() );
+                       $u->setId( $u->idFromName( $t->getText() ) );
                        return $u;
                }
        }