Extension:ShowRealUsernames/ShowRealUsernames.php
From MediaWiki.org
<?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 * @license public domain (given on http://www.mediawiki.org/wiki/Extension:ShowRealUsernames) * @author Paul Lustgarten, modified by John Erling Blad * @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.1.1', 'author' => array('Paul Lustgarten','John Erling Blad'), 'description' => 'Extend the Special:Listusers page to show the real name of each user.', 'url' => 'http://www.mediawiki.org/wiki/Extension:ShowRealUsernames' ); $dir = dirname(__FILE__) . '/'; $wgExtensionFunctions[] = 'SRUSetup'; $wgHooks['SpecialListusersQueryInfo'][] = 'SRUquery'; $wgHooks['SpecialListusersFormatRow'][] = 'SRUrow'; $wgExtensionMessagesFiles['ShowRealUsernames'] = $dir . 'ShowRealUsernames.i18n.php'; # Setup the message catalog function SRUSetup() { global $wgParser; wfLoadExtensionMessages('ShowRealUsernames'); return true; } # Augment the DB query for each user to also fetch their real name. # 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 # $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. # 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 # &$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 ) { global $wgShowRealUsernamesInline; $realName = htmlspecialchars( trim( $row->user_real_name ) ); if ( $realName == "" ) return true; # nothing to do $m = array(); if(preg_match('/^(.*?<a\b[^>]*>)([^<]*)(<\/a\b[^>]*>)(.*)$/',$item,$m)) { if ($wgShowRealUsernamesInline) $item = $m[1] . wfMsg( 'sru-realname-inline', $realName ) . $m[3] . $m[4]; else $item = $m[1] . $m[2] . $m[3] . wfMsg( 'sru-realname-append', $realName ) . $m[4]; } return true; }
