Extension:ShowRealUsernames
|
ShowRealUsernames Release status: beta |
|||
|---|---|---|---|
| Implementation | Special page | ||
| Description | Extend Special:ListUsers to also show each user's real name. | ||
| Author(s) | Paul Lustgarten (PlustgartenTalk) | ||
| Last version | 1.1 (17-Dez-09) | ||
| MediaWiki | 1.13.0 | ||
| License | Public domain | ||
| Download | ShowRealUsernames.php, ShowRealUsernames.i18n.php | ||
|
|||
|
Check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
The SpecialListusersFormatRow extension extends the user listings produced by Special:ListUsers to include the registered real name of each user, displayed immediately following the wiki user name.
[edit] Usage
This extension operates automatically whenever the Special:ListUsers page is displayed.
[edit] Download instructions
Please cut and paste the code found below and place it in $IP/extensions/ShowRealUsernames/ShowRealUsernames.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
[edit] Installation
To install this extension, add the following to LocalSettings.php:
require_once("$IP/extensions/ShowRealUsernames/ShowRealUsernames.php");
Also, if desired, modify the given SRUlink() function to wrap the real name appropriately to link it to an entry in your corporate directory (e.g., if your wiki user names are aligned with some index into that corporate directory).
[edit] See also
- Extension:Realnames to display realnames on all pages
- Extension:PageHistoryRealnames
- Extension:SearchRealnames
- Extension:LandingPage
[edit] Code (old version)
- Use /ShowRealUsernames.php and /ShowRealUsernames.i18n.php for newer versions.
<?php /** * ShowRealUsernames MediaWiki extension; MediaWiki version 1.13.3 * * To activate this extension, add the following into your LocalSettings.php file: * require_once('$IP/extensions/ShowRealUsernames/ShowRealUsernames.php'); * * @file * @ingroup Extensions * @version 1.0 * @author Paul Lustgarten * @link http://www.mediawiki.org/wiki/Extension:ShowRealUsernames */ # Not a valid entry point, skip unless MEDIAWIKI is defined if( !defined( 'MEDIAWIKI' ) ) { echo "ShowRealUsernames: This is an extension to the MediaWiki package and cannot be run standalone.\n"; die( -1 ); } # Extension credits that will show up on Special:Version $wgExtensionCredits['other'][] = array( 'name' => 'ShowRealUsernames', 'version' => '1.0', 'author' => 'Paul Lustgarten', 'description' => 'Extend the Special:Listusers page to show the real name of each user.', 'url' => 'http://www.mediawiki.org/wiki/Extension:ShowRealUsernames' ); # Include retrieval of the real name in the DB query for each user. # Called near the end of UsersPager::getQueryInfo() of SpecialListusers.php (line 85 in version 1.13.3) # Ref: http://www.mediawiki.org/wiki/Manual:Hooks/SpecialListusersQueryInfo $wgHooks['SpecialListusersQueryInfo'][] = 'SRUquery'; # Include the real name in the formatted row. # Called near the end of UsersPager::getDefaultQuery() of SpecialListusers.php (line 105 in version 1.13.3) # Ref: http://www.mediawiki.org/wiki/Manual:Hooks/SpecialListusersFormatRow $wgHooks['SpecialListusersFormatRow'][] = 'SRUrow'; # Augment the DB query for each user to also fetch their real name. # $pager: The UsersPager instance # &query: The query array to be returned function SRUquery( &$pager, &$query ) { $query['fields'][] = 'user_real_name'; # append desired field name return true; } # Augment the display of a row to include the user's real name. # &$item: HTML to be returned. Will be wrapped in <li></li> after the hook finishes. # We assume that $item is non-null and begins with a hyperlink section (<a ...> ... </a>). # $row: Database row object. function SRUrow( &$item, $row ) { $realName = htmlspecialchars( trim( $row->user_real_name ) ); if ( $realName == "" ) return true; # nothing to do $endBase = strpos( $item, '</a>' ); $endTag = strpos( $item, '>' ); if ( $endBase === false || $endTag === false ) { return true; # should never happen; leave $item alone } $namePos = $endTag + 1; $userName = substr( $item, $namePos, $endBase - $namePos ); $realNameLink = SRUlink( $realName, $userName ); $endBase += strlen( '</a>' ); if ( strlen( $item ) <= $endBase) { $item .= ' - ' . $realNameLink; } else { $item = substr( $item, 0, $endBase ) . ' - ' . $realNameLink . ' ' . substr( $item, $endBase ); } return true; } # Generate a (possibly) linked rendering of the given user real name. # $realName: the user's real name, as retrieved from the wiki's DB # $userName: the raw wiki username # returns an HTML string to render the real name # # Modify this function for your local installation. # For example, if the $userName or $realName can be used to link into a corporate directory, # wrap that link around the $realName. function SRUlink( $realName, $userName ) { # if the $userName doesn't look like a corporate ID, just display the realName plainly # if ( strlen( $userName ) != 6 ) { return $realName; # } # otherwise, link it to the corporate directory # return '<a href="http://corpdir.corp.com/cgi-bin/displayscript?id=' . $userName # . '" class="external text" title="CorpDir entry for ' . $realName . '" rel="nofollow">' # . $realName . '</a>'; } ?>
