From 44ab4a944863100681d8ec58d69b66429e74437a Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Thu, 10 Nov 2011 06:55:21 +0000 Subject: [PATCH] Add a new User::getDisplayName() to return the name that should be displayed in the interface. Add a UserDisplayName hook to allow extensions to give custom display names for users. Add a $wgRealNameInInterface to use the real name of a user as the display name. To start of the first use of the display name functionality tweak SkinTemplate to declare the userdisplayname and use it inside of personal_urls. --- RELEASE-NOTES-1.19 | 2 ++ docs/hooks.txt | 4 ++++ includes/DefaultSettings.php | 6 ++++++ includes/SkinTemplate.php | 6 ++++-- includes/User.php | 29 ++++++++++++++++++++++++++++- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index ddeefd06fa..3184c4a30e 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -76,6 +76,8 @@ production. * The default user signature now contains a talk link in addition to the user link. * (bug 25306) Add link of old page title to MediaWiki:Delete_and_move_reason * Added hook BitmapHandlerCheckImageArea +* (experimental) $wgRealNameInInterface can be enabled to display a user's + real name in some parts of the interface instead of a username. === Bug fixes in 1.19 === * $wgUploadNavigationUrl should be used for file redlinks if diff --git a/docs/hooks.txt b/docs/hooks.txt index e7f37d2c0b..4b4c666bc3 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2029,6 +2029,10 @@ your own hashing method hashing method &$hash: If the hook returns false, this String will be used as the hash +'UserDisplayName': Called in User::getDisplayName() +$user: The user object to fetch the display name for +&$displayName: The display name. Will be null. Set to a name to override default name. + 'UserEffectiveGroups': Called in User::getEffectiveGroups() $user: User to get groups for &$groups: Current effective groups diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 41bb561eb4..dccd91c2ac 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2243,6 +2243,12 @@ $wgXhtmlNamespaces = array(); */ $wgShowIPinHeader = true; +/** + * Use a user's real name inside the user interface for display instead of the username + * (experimental) + */ +$wgRealNameInInterface = true; + /** * Site notice shown at the top of each page * diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 70ca9f70fd..8015523b68 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -175,6 +175,7 @@ class SkinTemplate extends Skin { $this->thisquery = wfArrayToCGI( $query ); $this->loggedin = $user->isLoggedIn(); $this->username = $user->getName(); + $this->userdisplayname = $user->getDisplayName(); if ( $user->isLoggedIn() || $this->showIPinHeader() ) { $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage ); @@ -305,6 +306,7 @@ class SkinTemplate extends Skin { $tpl->set( 'capitalizeallnouns', $this->getLang()->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' ); $tpl->set( 'showjumplinks', $user->getOption( 'showjumplinks' ) ); $tpl->set( 'username', $user->isAnon() ? null : $this->username ); + $tpl->set( 'userdisplayname', $user->isAnon() ? null : $this->userdisplayname ); $tpl->setRef( 'userpage', $this->userpage ); $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] ); $tpl->set( 'userlang', $userlang ); @@ -558,7 +560,7 @@ class SkinTemplate extends Skin { $returnto = wfArrayToCGI( $a ); if( $this->loggedin ) { $personal_urls['userpage'] = array( - 'text' => $this->username, + 'text' => $this->userdisplayname, 'href' => &$this->userpageUrlDetails['href'], 'class' => $this->userpageUrlDetails['exists'] ? false : 'new', 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ) @@ -653,7 +655,7 @@ class SkinTemplate extends Skin { if( $this->showIPinHeader() ) { $href = &$this->userpageUrlDetails['href']; $personal_urls['anonuserpage'] = array( - 'text' => $this->username, + 'text' => $this->userdisplayname, 'href' => $href, 'class' => $this->userpageUrlDetails['exists'] ? false : 'new', 'active' => ( $pageurl == $href ) diff --git a/includes/User.php b/includes/User.php index 18d65617e7..074eeecaf6 100644 --- a/includes/User.php +++ b/includes/User.php @@ -199,7 +199,7 @@ class User { */ var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mRights, $mBlockreason, $mEffectiveGroups, $mImplicitGroups, $mFormerGroups, $mBlockedGlobally, - $mLocked, $mHideName, $mOptions; + $mLocked, $mHideName, $mOptions, $mDisplayName; /** * @var WebRequest @@ -1191,6 +1191,7 @@ class User { $this->mEffectiveGroups = null; $this->mImplicitGroups = null; $this->mOptions = null; + $this->mDisplayName = null; if ( $reloadFrom ) { $this->mLoadedItems = array(); @@ -2135,6 +2136,32 @@ class User { $this->mRealName = $str; } + /** + * Return the name of this user we should used to display in the user interface + * @return String The user's display name + */ + public function getDisplayName() { + global $wgRealNameInInterface; + if ( is_null( $this->mDisplayName ) ) { + $displayName = null; + + // Allow hooks to set a display name + wfRunHooks( 'UserDisplayName', array( $this, &$displayName ) ); + + if ( is_null( $displayName ) && $wgRealNameInInterface && $this->getRealName() ) { + // If $wgRealNameInInterface is true use the real name as the display name if it's set + $displayName = $this->getRealName(); + } + + if ( is_null( $displayName ) ) { + $displayName = $this->getName(); + } + + $this->mDisplayName = $displayName; + } + return $this->mDisplayName; + } + /** * Get the user's current setting for a given option. * -- 2.20.1