r102624 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102623‎ | r102624 | r102625 >
Date:06:55, 10 November 2011
Author:dantman
Status:reverted (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -2029,6 +2029,10 @@
20302030 hashing method
20312031 &$hash: If the hook returns false, this String will be used as the hash
20322032
 2033+'UserDisplayName': Called in User::getDisplayName()
 2034+$user: The user object to fetch the display name for
 2035+&$displayName: The display name. Will be null. Set to a name to override default name.
 2036+
20332037 'UserEffectiveGroups': Called in User::getEffectiveGroups()
20342038 $user: User to get groups for
20352039 &$groups: Current effective groups
Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -76,6 +76,8 @@
7777 * The default user signature now contains a talk link in addition to the user link.
7878 * (bug 25306) Add link of old page title to MediaWiki:Delete_and_move_reason
7979 * Added hook BitmapHandlerCheckImageArea
 80+* (experimental) $wgRealNameInInterface can be enabled to display a user's
 81+ real name in some parts of the interface instead of a username.
8082
8183 === Bug fixes in 1.19 ===
8284 * $wgUploadNavigationUrl should be used for file redlinks if
Index: trunk/phase3/includes/SkinTemplate.php
@@ -175,6 +175,7 @@
176176 $this->thisquery = wfArrayToCGI( $query );
177177 $this->loggedin = $user->isLoggedIn();
178178 $this->username = $user->getName();
 179+ $this->userdisplayname = $user->getDisplayName();
179180
180181 if ( $user->isLoggedIn() || $this->showIPinHeader() ) {
181182 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
@@ -305,6 +306,7 @@
306307 $tpl->set( 'capitalizeallnouns', $this->getLang()->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
307308 $tpl->set( 'showjumplinks', $user->getOption( 'showjumplinks' ) );
308309 $tpl->set( 'username', $user->isAnon() ? null : $this->username );
 310+ $tpl->set( 'userdisplayname', $user->isAnon() ? null : $this->userdisplayname );
309311 $tpl->setRef( 'userpage', $this->userpage );
310312 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
311313 $tpl->set( 'userlang', $userlang );
@@ -558,7 +560,7 @@
559561 $returnto = wfArrayToCGI( $a );
560562 if( $this->loggedin ) {
561563 $personal_urls['userpage'] = array(
562 - 'text' => $this->username,
 564+ 'text' => $this->userdisplayname,
563565 'href' => &$this->userpageUrlDetails['href'],
564566 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
565567 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
@@ -653,7 +655,7 @@
654656 if( $this->showIPinHeader() ) {
655657 $href = &$this->userpageUrlDetails['href'];
656658 $personal_urls['anonuserpage'] = array(
657 - 'text' => $this->username,
 659+ 'text' => $this->userdisplayname,
658660 'href' => $href,
659661 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
660662 'active' => ( $pageurl == $href )
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2244,6 +2244,12 @@
22452245 $wgShowIPinHeader = true;
22462246
22472247 /**
 2248+ * Use a user's real name inside the user interface for display instead of the username
 2249+ * (experimental)
 2250+ */
 2251+$wgRealNameInInterface = true;
 2252+
 2253+/**
22482254 * Site notice shown at the top of each page
22492255 *
22502256 * MediaWiki:Sitenotice page, which will override this. You can also
Index: trunk/phase3/includes/User.php
@@ -199,7 +199,7 @@
200200 */
201201 var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mRights,
202202 $mBlockreason, $mEffectiveGroups, $mImplicitGroups, $mFormerGroups, $mBlockedGlobally,
203 - $mLocked, $mHideName, $mOptions;
 203+ $mLocked, $mHideName, $mOptions, $mDisplayName;
204204
205205 /**
206206 * @var WebRequest
@@ -1191,6 +1191,7 @@
11921192 $this->mEffectiveGroups = null;
11931193 $this->mImplicitGroups = null;
11941194 $this->mOptions = null;
 1195+ $this->mDisplayName = null;
11951196
11961197 if ( $reloadFrom ) {
11971198 $this->mLoadedItems = array();
@@ -2136,6 +2137,32 @@
21372138 }
21382139
21392140 /**
 2141+ * Return the name of this user we should used to display in the user interface
 2142+ * @return String The user's display name
 2143+ */
 2144+ public function getDisplayName() {
 2145+ global $wgRealNameInInterface;
 2146+ if ( is_null( $this->mDisplayName ) ) {
 2147+ $displayName = null;
 2148+
 2149+ // Allow hooks to set a display name
 2150+ wfRunHooks( 'UserDisplayName', array( $this, &$displayName ) );
 2151+
 2152+ if ( is_null( $displayName ) && $wgRealNameInInterface && $this->getRealName() ) {
 2153+ // If $wgRealNameInInterface is true use the real name as the display name if it's set
 2154+ $displayName = $this->getRealName();
 2155+ }
 2156+
 2157+ if ( is_null( $displayName ) ) {
 2158+ $displayName = $this->getName();
 2159+ }
 2160+
 2161+ $this->mDisplayName = $displayName;
 2162+ }
 2163+ return $this->mDisplayName;
 2164+ }
 2165+
 2166+ /**
21402167 * Get the user's current setting for a given option.
21412168 *
21422169 * @param $oname String The option to check

Sign-offs

UserFlagDate
Bawolfftested05:29, 20 December 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r104262Followup r102624...reedy00:32, 26 November 2011
r108581Revert r102624, r104262 (user display name stuff). Per CR there isn't consens...demon00:53, 11 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   09:44, 10 November 2011

Could this be made generic and work for all namespaces? There is this ambitious plan to use displaytitle prop everywhere.

#Comment by Dantman (talk | contribs)   18:34, 10 November 2011

In what way? This is related to usernames rather than titles, there's nothing really related to titles here.

Rather than the displaytitle prop when I tried to fix it so that IPod would display iPod throughout the entire user interface it included a schema change. The title was stored inside the database. The displaytitle really wouldn't work as a good idea outside of where it is right now.

) Actually this change might help with one of the issues I encountered in my title rewrite. getName() was being used for both comparison and display so I had issues with it. Now if we start using getDisplayName() that could be what's changed.
#Comment by Nikerabbit (talk | contribs)   20:10, 10 November 2011

Sorry I can't parse your sentence. Are you saying that using display title in page_props for title display is not good idea?

#Comment by Dantman (talk | contribs)   20:14, 10 November 2011

Yes, outside of stuff on the page itself. Most queries don't join on page_props, and it's possible in some cases for a page prop to not be present. So using displaytitle on say Special:Allpages requires either an extra join with some potentially complicated circumstances or it'll be inefficient as page_props would have to be repeatedly queried.

#Comment by Nikerabbit (talk | contribs)   20:34, 10 November 2011

I was not asking that. I was asking if there was some fundamental reason that it can't be done.

For the technical implementation we already have LinkBatch and Title::newFromRow that can be extended.

#Comment by Olivier Beaton (talk | contribs)   17:59, 10 November 2011

As a replacement in-core for Extension:Realnames, I think your choice of wg var is too simple. Before making my extension I looked at all the other extensions which did realname replacement (there are a few) and they all had different ways of display it. For example: Username - Realname or Realname [username] etc. Or wholesale replacement. I think you could reasily re-use the conf vars from Extension:Realnames to make a transition seamless. Of course they aren't all needed or wanted, but some of them could prove useful.

#Comment by Dantman (talk | contribs)   18:29, 10 November 2011

Oh... things like Dantman [Daniel Friesen] aren't going to be something simple like this rev. That's changing markup in a lot of places this is just a change to text, that's going to require a separate feature. And that's not something that'll work in a unified way. There will be places where a combined html display like that may not be simply possible.

#Comment by Olivier Beaton (talk | contribs)   18:49, 10 November 2011

I disagree. The more I think about it, the more getDisplayName() should actually use a mediawiki message with $ vars and replace on given elements. Username and Realname just being two. The user can then format how it outputs to their liking.

Or gut out all the "realname" stuff out of this feature complete and just add a hook for extensions to change the getDisplayName and do it themselves.

No point adding a half-baked feature.

#Comment by Olivier Beaton (talk | contribs)   18:51, 10 November 2011

Also, nobody is talking about making the 'Dantman' clickable and the '[Daniel Friesen]' not. Just wholesale replacement of the link text to some administrator-defined string. ala $wgRealnameStyle(s)

#Comment by Dantman (talk | contribs)   18:57, 10 November 2011

It already has a hook. $wgRealNameInInterface is just an extra config for the most common expected setup, a simple username to realname replacement.

#Comment by Olivier Beaton (talk | contribs)   22:05, 10 November 2011

My vote is to remove the $wgRealNameInInterface bit.

Your set of assumption are incorrect, the most common expected setup is 'Username — Realname' and this is what all current realname extensions currently do (except mine, which allows many different setups). This is inline with almost all public wikis where the username is meaningful, and the realname is added bonus.

The other use case (and the one the bug happens to be filed for) is likely a private wiki that is using other extensions to do external authentication (like LDAP). In this case the username is often a almost-meaningless auto-generated id, where wholesale replacement makes sense.

If you insist on providing in-core functionality, please provide as suggested a user-defined way to specify either an append or a replace (or a user defined replacement string).

#Comment by Olivier Beaton (talk | contribs)   18:02, 10 November 2011

Another thought is that really we should just add the ability to hook the display of a username, and then use an extension to do whatever an administrator wants. For example adding twitter or facebook icon shortcuts after names... whatever. Talk page everywhere... Although I admit a simple username -> realname or username + realname is the most likely scenario.

#Comment by Platonides (talk | contribs)   18:18, 10 November 2011

$this->userdisplayname ($this->username before this rev) will be null for IPs. What's the point of that entry in $personal_urls['anonuserpage'] ?

#Comment by Dantman (talk | contribs)   18:24, 10 November 2011

$tpl->data['userdisplayname'] may be null for IPs. $this->userdisplayname comes directly from $user->getDisplayName() it will be the ip address for anons. Of course anons don't have real names so usually there won't be any difference from $this->username, but I included it in the change in case someone decides they have a good idea for an extension that changes the display name of an anon user.

Status & tagging log