Added a user_real_name column to the user table, and added a patch SQL file
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Sun, 18 Apr 2004 02:28:35 +0000 (02:28 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Sun, 18 Apr 2004 02:28:35 +0000 (02:28 +0000)
to add this field.

User.php stores and fetches the field, and has accessors for it.

User login allows setting the field on account creation.

The Preferences page allows changing the real name.

The labels are available for the real name, and the explanation of the email
field on login has been expanded to include an explanation of the real name
field, too.

Update script checks for the field, and adds it if it's missing.

includes/SpecialPreferences.php
includes/SpecialUserlogin.php
includes/User.php
languages/Language.php
maintenance/archives/patch-user-realname.sql [new file with mode: 0644]
maintenance/tables.sql
maintenance/updaters.inc
update.php

index 7329c77..46bd003 100644 (file)
@@ -12,7 +12,7 @@ class PreferencesForm {
        var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
        var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
        var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
-       var $mReset, $mPosted, $mToggles, $mSearchNs;
+       var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName;
 
        function PreferencesForm( &$request ) { 
                global $wgLang;
@@ -28,6 +28,7 @@ class PreferencesForm {
                $this->mMath = $request->getVal( 'wpMath' );
                $this->mDate = $request->getVal( 'wpDate' );
                $this->mUserEmail = $request->getVal( 'wpUserEmail' );
+               $this->mRealName = $request->getVal( 'wpRealName' );
                $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 1 : 0;
                $this->mNick = $request->getVal( 'wpNick' );
                $this->mSearch = $request->getVal( 'wpSearch' );
@@ -144,6 +145,7 @@ class PreferencesForm {
                        $wgUser->setPassword( $this->mNewpass );
                }
                $wgUser->setEmail( $this->mUserEmail );
+               $wgUser->setRealName( $this->mRealName );
                $wgUser->setOption( "nickname", $this->mNick );
                $wgUser->setOption( "quickbar", $this->mQuickbar );
                $wgUser->setOption( "skin", $this->mSkin );
@@ -183,6 +185,7 @@ class PreferencesForm {
 
                $this->mOldpass = $this->mNewpass = $this->mRetypePass = "";
                $this->mUserEmail = $wgUser->getEmail();
+               $this->mRealName = $wgUser->getRealName();
                if ( 1 == $wgUser->getOption( "disablemail" ) ) { $this->mEmailFlag = 1; }
                else { $this->mEmailFlag = 0; }
                $this->mNick = $wgUser->getOption( "nickname" );
@@ -304,6 +307,7 @@ class PreferencesForm {
                $tzGuess = wfMsg( "guesstimezone" );
                $tzServerTime = wfMsg( "servertime" );
                $yem = wfMsg( "youremail" );
+               $yrn = wfMsg( "yourrealname" );
                $emf = wfMsg( "emailflag" );
                $ynn = wfMsg( "yournick" );
                $stt = wfMsg ( "stubthreshold" ) ;
@@ -413,6 +417,7 @@ class PreferencesForm {
                # Email, etc.
                #
                $this->mUserEmail = wfEscapeHTML( $this->mUserEmail );
+               $this->mRealName = wfEscapeHTML( $this->mRealName );
                $this->mNick = wfEscapeHTML( $this->mNick );
                if ( $this->mEmailFlag ) { $emfc = 'checked="checked"'; }
                else { $emfc = ""; }
@@ -420,6 +425,7 @@ class PreferencesForm {
                $ps = $this->namespacesCheckboxes();
 
                $wgOut->addHTML( "<fieldset>
+               <div><label>$yrn: <input type='text' name=\"wpRealName\" value=\"{$this->mRealName}\" size='20' /></label></div>
                <div><label>$yem: <input type='text' name=\"wpUserEmail\" value=\"{$this->mUserEmail}\" size='20' /></label></div>
                <div><label><input type='checkbox' $emfc value=\"1\" name=\"wpEmailFlag\" /> $emf</label></div>
                <div><label>$ynn: <input type='text' name=\"wpNick\" value=\"{$this->mNick}\" size='12' /></label></div>
index 1d72bea..793224e 100644 (file)
@@ -35,6 +35,7 @@ class LoginForm {
                $this->mAction = $request->getVal( 'action' );
                $this->mRemember = $request->getCheck( 'wpRemember' );
                $this->mEmail = $request->getText( 'wpEmail' );
+               $this->mRealName = $request->getText( 'wpRealName' );
                
                # When switching accounts, it sucks to get automatically logged out
                if( $this->mReturnto == $wgLang->specialPage( "Userlogout" ) ) {
@@ -154,6 +155,8 @@ class LoginForm {
                $u->addToDatabase();
                $u->setPassword( $this->mPassword );
                $u->setEmail( $this->mEmail );
+               $u->setRealName( $this->mRealName );
+
                if ( $this->mRemember ) { $r = 1; }
                else { $r = 0; }
                $u->setOption( "rememberpassword", $r );
@@ -310,6 +313,7 @@ class LoginForm {
                $ca = wfMsg( "createaccount" );
                $cam = wfMsg( "createaccountmail" );
                $ye = wfMsg( "youremail" );
+               $yrn = wfMsg( "yourrealname" );
                $efl = wfMsg( "emailforlost" );
                $mmp = wfMsg( "mailmypassword" );
                $endText = wfMsg( "loginend" );
@@ -355,6 +359,7 @@ class LoginForm {
                $encPassword = wfEscapeHTML( $this->mPassword );
                $encRetype = wfEscapeHTML( $this->mRetype );
                $encEmail = wfEscapeHTML( $this->mEmail );
+               $encRealName = wfEscapeHTML( $this->mRealName );
 
                if ($wgUser->getID() != 0) {
                        $cambutton = "<input tabindex='6' type='submit' name=\"wpCreateaccountMail\" value=\"{$cam}\" />";
@@ -395,9 +400,17 @@ class LoginForm {
        <tr>
        <td align='right'>$ye:</td>
        <td align='left'>
-       <input tabindex='5' type='text' name=\"wpEmail\" value=\"{$encEmail}\" size='20' />
-       </td><td align='left'>
-       <input tabindex='6' type='submit' name=\"wpCreateaccount\" value=\"{$ca}\" />
+       <input tabindex='6' type='text' name=\"wpEmail\" value=\"{$encEmail}\" size='20' />
+       </td>
+        <td>&nbsp;</td>
+        </tr>
+        <tr>
+       <td align='right'>$yrn:</td>
+       <td align='left'>
+       <input tabindex='6' type='text' name=\"wpRealName\" value=\"{$encRealName}\" size='20' />
+       </td>
+        <td align='left'>
+       <input tabindex='7' type='submit' name=\"wpCreateaccount\" value=\"{$ca}\" />
        $cambutton
        </td></tr>");
                }
index 8b01c75..71b96ea 100644 (file)
@@ -11,6 +11,7 @@ class User {
        /* private */ var $mBlockedby, $mBlockreason;
        /* private */ var $mTouched;
        /* private */ var $mCookiePassword;
+        /* private */ var $mRealName;
 
        function User()
        {
@@ -247,14 +248,15 @@ class User {
                } # the following stuff is for non-anonymous users only
 
                $sql = "SELECT user_name,user_password,user_newpassword,user_email," .
-                 "user_options,user_rights,user_touched FROM user WHERE user_id=" .
-                 "{$this->mId}";
+                 "user_real_name,user_options,user_rights,user_touched " . 
+                  " FROM user WHERE user_id=" . $this->mId;
                $res = wfQuery( $sql, DB_READ, "User::loadFromDatabase" );
 
                if ( wfNumRows( $res ) > 0 ) {
                        $s = wfFetchObject( $res );
                        $this->mName = $s->user_name;
                        $this->mEmail = $s->user_email;
+                       $this->mRealName = $s->user_real_name;
                        $this->mPassword = $s->user_password;
                        $this->mNewpassword = $s->user_newpassword;
                        $this->decodeOptions( $s->user_options );
@@ -366,6 +368,18 @@ class User {
                $this->mEmail = $str;
        }
 
+       function getRealName()
+       {
+               $this->loadFromDatabase();
+               return $this->mRealName;
+       }
+
+       function setRealName( $str )
+       {
+               $this->loadFromDatabase();
+               $this->mRealName = $str;
+       }
+
        function getOption( $oname )
        {
                $this->loadFromDatabase();
@@ -549,6 +563,7 @@ class User {
                  "user_name= '" . wfStrencode( $this->mName ) . "', " .
                  "user_password= '" . wfStrencode( $this->mPassword ) . "', " .
                  "user_newpassword= '" . wfStrencode( $this->mNewpassword ) . "', " .
+                 "user_real_name= '" . wfStrencode( $this->mRealName ) . "', " .
                  "user_email= '" . wfStrencode( $this->mEmail ) . "', " .
                  "user_options= '" . $this->encodeOptions() . "', " .
                  "user_rights= '" . wfStrencode( implode( ",", $this->mRights ) ) . "', " .
@@ -582,11 +597,12 @@ class User {
        function addToDatabase()
        {
                $sql = "INSERT INTO user (user_name,user_password,user_newpassword," .
-                 "user_email, user_rights, user_options) " .
+                 "user_email, user_real_name, user_rights, user_options) " .
                  " VALUES ('" . wfStrencode( $this->mName ) . "', '" .
                  wfStrencode( $this->mPassword ) . "', '" .
                  wfStrencode( $this->mNewpassword ) . "', '" .
                  wfStrencode( $this->mEmail ) . "', '" .
+                 wfStrencode( $this->mRealName ) . "', '" .
                  wfStrencode( implode( ",", $this->mRights ) ) . "', '" .
                  $this->encodeOptions() . "')";
                wfQuery( $sql, DB_WRITE, "User::addToDatabase" );
index 1dbe0c6..17db8dd 100644 (file)
@@ -655,11 +655,10 @@ Don't forget to change your {{SITENAME}} preferences.",
 "badretype"            => "The passwords you entered do not match.",
 "userexists"   => "The user name you entered is already in use. Please choose a different name.",
 "youremail"            => "Your email*",
+"yourrealname"         => "Your real name*",
 "yournick"             => "Your nickname (for signatures)",
-"emailforlost" => "* Entering an email address is optional.  But it enables people to
-contact you through the website without you having to reveal your 
-email address to them, and it also helps you if you forget your   
-password.",
+"emailforlost" => "Fields marked with a star (*) are optional.  Storing an email address enables people to contact you through the website without you having to reveal your 
+email address to them, and it can be used to send you a new password if you forget it.<br /><br />Your real name, if you choose to provide it, will be used for giving you attribution for your work.",
 "loginerror"   => "Login error",
 "nocookiesnew" => "The user account was created, but you are not logged in. {{SITENAME}} uses cookies to log in users. You have cookies disabled. Please enable them, then log in with your new username and password.",
 "nocookieslogin"       => "{{SITENAME}} uses cookies to log in users. You have cookies disabled. Please enable them and try again.",
diff --git a/maintenance/archives/patch-user-realname.sql b/maintenance/archives/patch-user-realname.sql
new file mode 100644 (file)
index 0000000..e723120
--- /dev/null
@@ -0,0 +1,5 @@
+-- Add a 'real name' field where users can specify the name they want
+-- used for author attribution or other places that real names matter.
+
+ALTER TABLE user 
+        ADD (user_real_name varchar(255) binary NOT NULL default '');
\ No newline at end of file
index 91df23e..1db28da 100644 (file)
@@ -7,6 +7,7 @@
 CREATE TABLE user (
   user_id int(5) unsigned NOT NULL auto_increment,
   user_name varchar(255) binary NOT NULL default '',
+  user_real_name varchar(255) binary NOT NULL default '',
   user_rights tinyblob NOT NULL default '',
   user_password tinyblob NOT NULL default '',
   user_newpassword tinyblob NOT NULL default '',
index e390903..feb9e42 100644 (file)
@@ -123,4 +123,15 @@ function do_recentchanges_update() {
        }
 }
 
+function do_user_real_name_update() {
+       global $wgDatabase;
+       if ( $wgDatabase->fieldExists( "user", "user_real_name" ) ) {
+               echo "...have user_real_name field in user table.\n";
+        } else {
+               echo "Adding user_real_name field to table user...";
+               dbsource( "maintenance/archives/patch-user-realname.sql" , $wgDatabase );
+               echo "ok\n";
+       }
+}
+
 ?>
\ No newline at end of file
index fb954f4..863a86e 100644 (file)
@@ -63,6 +63,7 @@ do_index_update();
 do_linkscc_update();
 do_hitcounter_update();
 do_recentchanges_update();
+do_user_real_name_update();
 
 initialiseMessages();