From c1d1561b2f4efcadc693e786ca3d87924191afeb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 18 Apr 2004 02:28:35 +0000 Subject: [PATCH] Added a user_real_name column to the user table, and added a patch SQL file 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 | 8 ++++++- includes/SpecialUserlogin.php | 19 ++++++++++++++--- includes/User.php | 22 +++++++++++++++++--- languages/Language.php | 7 +++---- maintenance/archives/patch-user-realname.sql | 5 +++++ maintenance/tables.sql | 1 + maintenance/updaters.inc | 11 ++++++++++ update.php | 1 + 8 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 maintenance/archives/patch-user-realname.sql diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index 7329c77418..46bd003209 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -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( "
+
diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 1d72bea053..793224e416 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -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 = ""; @@ -395,9 +400,17 @@ class LoginForm { $ye: - - - + + +   + + + $yrn: + + + + + $cambutton "); } diff --git a/includes/User.php b/includes/User.php index 8b01c75c2e..71b96ead6a 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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" ); diff --git a/languages/Language.php b/languages/Language.php index 1dbe0c6367..17db8dd338 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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.

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 index 0000000000..e7231200e8 --- /dev/null +++ b/maintenance/archives/patch-user-realname.sql @@ -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 diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 91df23e096..1db28daaf5 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -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 '', diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index e390903fb0..feb9e420b5 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -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 diff --git a/update.php b/update.php index fb954f4b8e..863a86e7ff 100644 --- a/update.php +++ b/update.php @@ -63,6 +63,7 @@ do_index_update(); do_linkscc_update(); do_hitcounter_update(); do_recentchanges_update(); +do_user_real_name_update(); initialiseMessages(); -- 2.20.1