Extension:SocialProfile/For developers

From MediaWiki.org

Jump to: navigation, search

Contents

[edit] Overview

SocialProfile consists of 8 components:

  • SystemGifts — awards functionality
  • UserBoard — user-to-user messages
  • UserGifts — gifting functionality
  • UserProfile — social profile pages
  • UserRelationship — friend/foe relationships
  • UserStats — statistics, such as the User Levels system
  • UserWelcome — <userWelcome/> parser hook for displaying social info on a wiki page
  • YUI — JavaScript library which is required by SocialProfile. See Wikipedia's article on YUI for more info.

Of these, UserWelcome is not enabled by default.

If you want to become a SocialProfile developer, feel free to drop Jack Phoenix a line and then apply for commit access (procedure is described in-depth on that page).

[edit] Customization of Profile

The user profile allows several custom hooks to inject custom data into the profile. You can add anything above and below both columns of the profile by the following hooks:

$wgHooks['UserProfileBeginLeft'][] = 'wfUserProfileBeginTest';
function wfUserProfileBeginTest( $user_profile ) {
	global $wgOut;
	$wgOut->addHTML("this was inserted at the left beginning from the hook [profile:{$user_profile->user_name}]");
	return true;
}
 
$wgHooks['UserProfileEndLeft'][] = 'wfUserProfileBeginTest2';
function wfUserProfileBeginTest2( $user_profile ) {
	global $wgOut;
	$wgOut->addHTML("this was inserted at the left end from the hook [profile:{$user_profile->user_name}]");
	return true;
}
 
$wgHooks['UserProfileBeginRight'][] = 'wfUserProfileBeginTest3';
function wfUserProfileBeginTest3( $user_profile ) {
	global $wgOut;
	$wgOut->addHTML("this was inserted at the right beginning from the hook [profile:{$user_profile->user_name}]");
	return true;
}
 
$wgHooks['UserProfileEndRight'][] = 'wfUserProfileBeginTest4';
function wfUserProfileBeginTest4( $user_profile ) {
	global $wgOut;
	$wgOut->addHTML("this was inserted at the right end from the hook [profile:{$user_profile->user_name}]");
	return true;
}

If you need more hooks added to the core of SocialProfile, please discuss with Jack Phoenix about it, preferrably providing a good reason why a new hook should be added. :-)

[edit] Example extension that uses UserProfile's hooks

The following piece of code adds a "Xbox Gamecard" section to social profile pages, as seen on Halopedia:

<?php
/**
 * XBoxGamerCardUserProfile extension
 *
 * @file
 * @ingroup Extensions
 * @author Wikia New York Team
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 */
$wgHooks['UserProfileBeginLeft'][] = 'wfUserProfileXboxGamerCard';
 
function wfUserProfileXboxGamerCard( $user_profile ){
	global $wgOut;
 
	$output = '';
 
	$xbox_id = strip_tags( $user_profile->profile_data['custom_1'] );
 
	if( $xbox_id ){
		$output .= '<div class="user-section-heading">
			<div class="user-section-title">Xbox Gamecard</div>
			<div class="user-section-actions">
				<div class="action-right"></div>
				<div class="action-left"></div>
			</div>
			<div class="cleared"></div>
		</div>
		<div class="cleared"></div>
		<div class="profile-info-container">
			<iframe src="http://gamercard.xbox.com/'.$xbox_id.'.card" scrolling="no" frameBorder="0" height="140" width="204">'.$xbox_id.'</iframe>
		</div>';
 
		$wgOut->addHTML( $output );
	}
	return true;
}

[edit] Translations

Notice that your language isn't translated at all or that the translation is incomplete? Internationalization patches are always welcome. See How to become a MediaWiki hacker#Posting a patch for info about how to generate a patch file. After you've finished your patch, please email it to Jack Phoenix (jack(at)countervandalism.net).