Extension:SocialProfile/Developer information

From MediaWiki.org
Jump to: navigation, search

Overview[edit]

SocialProfile consists of 9 components:

  • SystemGifts — awards functionality
  • UserActivity — social recent changes, such as the feed of friends' recent activity, etc.
  • UserBoard — user-to-user messages
  • UserGifts — gifting functionality
  • UserProfile — social profile pages
  • UserRelationship — friend/foe relationships
  • UserStats — statistics, such as the User Levels system
  • UserSystemMessages — used to send "You have advanced to level [fill in this]" messages to users when User Levels is activated ($wgUserLevels is defined)
  • UserWelcome — <userWelcome/> parser hook for displaying social info on a wiki page

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.

Uploads[edit]

SocialProfile has three special pages, which are used to upload images that are used by SocialProfile:

  • Special:UploadAvatar (SocialProfile/UserProfile/SpecialUploadAvatar.php), which stores its files in $wgUploadPath/avatars, is used to upload users' avatars. This special page can be accessed via the social profile page by any user who has the 'upload' user right (any registered user by default).
  • Special:GiftManagerLogo (SocialProfile/UserGifts/SpecialGiftManagerLogo.php), which stores its files in $wgUploadPath/awards, is used to upload images associated with user-to-user gifts. This special page can be accessed via Special:GiftManager by any user with the 'giftmanager' user right (administrators and members of the staff group by default). If $wgMaxCustomUserGiftCount is greater than 0, then normal users (users without the 'giftmanager' user right) can access this special page, too.
  • Special:SystemGiftManagerLogo (SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php), which stores its files in $wgUploadPath/awards, is used to upload award (system gift) images. This special page can be accessed by users with the 'awardsmanage' user right (administrators and members of the staff group by default).

Files uploaded via these special pages are not treated as normal MediaWiki files.

Image file name formats:

  • user avatars: $wgDBname_USERID_SIZE.EXTENSION (i.e. testwiki_1_l.png; size can be l for large, ml for medium-large, s for small)
  • gift images: GIFTID_SIZE.EXTENSION (i.e. 4_m.gif)
  • award (system gift) images: sg_SYSTEMGIFTID_SIZE.EXTENSION (i.e. sg_15_s.jpg)

In the past, all of these special pages used ImageMagick to resize the images. Since r93067, PHP's GD library has been supported so SocialProfile's image uploads should function properly even on platforms where ImageMagick is not available.

Hooks[edit]

There are several hooks in the SocialProfile codebase which allow you to alter or inject data.

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. :-)

Hook name Location Since Description
BasicProfileChanged UserProfile/SpecialUpdateProfile.php r85903 Arguments: $user (current User object; $wgUser for Special:UpdateProfile, but not necessarily for Special:EditProfile) and $basicProfileData (array of user profile data).
Called in SpecialUpdateProfile::saveProfileBasic() after performing the database query but before deleting the memcached entry.
PersonalInterestsChanged UserProfile/SpecialUpdateProfile.php r85903 Arguments: $user (current User object; $wgUser for Special:UpdateProfile, but not necessarily for Special:EditProfile) and $interestsData (array of user's personal interests data).
Called in SpecialUpdateProfile::saveProfilePersonal() after performing the database query but before deleting the memcached entry.
SpecialUpdateProfile::saveSettings_pref UserProfile/SpecialUpdateProfile.php r94639 Arguments: $updateProfile (instance of the SpecialUpdateProfile class), $request (the $wgRequest object).
Called in SpecialUpdateProfile::saveSettings_pref after the user's preferences have been saved via a call to User::saveSettings().
SpecialUpdateProfile::displayPreferencesForm UserProfile/SpecialUpdateProfile.php r94639 Arguments: $updateProfile (instance of the SpecialUpdateProfile class), &$form (the raw HTML of the preferences form).
Called in SpecialUpdateProfile::displayPreferencesForm, right before the div element with the class "profile-update" is closed. This hook can be used to add new checkboxes to the preferences form, Special:UpdateProfile/preferences.
NewAvatarUploaded UserProfile/SpecialUploadAvatar.php r85903 Arguments: $user ($wgUser object).
Called in SpecialUploadAvatar::execute() after a successful avatar upload has been completed.
UserProfileBeginLeft UserProfile/UserProfilePage.php the beginning Arguments: &$userProfilePage (current instance of UserProfilePage)
UserProfileEndLeft UserProfile/UserProfilePage.php the beginning Arguments: &$userProfilePage (current instance of UserProfilePage)
UserProfileBeginRight UserProfile/UserProfilePage.php the beginning Arguments: &$userProfilePage (current instance of UserProfilePage)
UserProfileRightSideAfterActivity UserProfile/UserProfilePage.php r92425 Called after UserProfilePage::getActivity() but before UserProfilePage::getCasualGames(); mainly used by the BlogPage extension. Arguments: &$userProfilePage (current instance of UserProfilePage)
UserProfileEndRight UserProfile/UserProfilePage.php the beginning Arguments: &$userProfilePage (current instance of UserProfilePage)
NewFriendAccepted UserRelationship/UserRelationshipClass.php r85903 Arguments: $ur_user_name_from (string) and $username (string).
Called in UserRelationship::addRelationship() after information about a new friend has been added to the database and caches have been purged, right before returning true from the function.
NewFoeAccepted UserRelationship/UserRelationshipClass.php r85903 Arguments: $ur_user_name_from (string) and $username (string).
Called in UserRelationship::addRelationship() after information about a new foe has been added to the database and caches have been purged, right before returning true from the function.
RelationshipRemovedByUserID UserRelationship/UserRelationshipClass.php r85903 Arguments: $user1 (integer, user ID of the first user involved in the relationship) and $user2 (integer, user ID of the second user involved in the relationship).
Called in UserRelationship::removeRelationshipByUserID() after relationship info has been deleted from the database and memcached, but before social statistics for both users have been updated.

Customization of Profile[edit]

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;
}

Example extension that uses UserProfile's hooks[edit]

The following piece of code adds a "Xbox Gamecard" section to social profile pages:

<?php
/**
 * XBoxGamerCardUserProfile extension
 *
 * @file
 * @ingroup Extensions
 * @author Aaron Wright
 * @author David Pean
 * @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 = '';

	$xboxId = strip_tags( $user_profile->profile_data['custom_1'] );

	if ( $xboxId ) {
		$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="visualClear"></div>
		</div>
		<div class="visualClear"></div>
		<div class="profile-info-container">
			<iframe src="http://gamercard.xbox.com/' . $xboxId . '.card" scrolling="no" frameBorder="0" height="140" width="204">'
				. $xboxId .
			'</iframe>
		</div>';

		$wgOut->addHTML( $output );
	}

	return true;
}


Social toolsSocial tools
SocialProfileExtension:SocialProfile OverviewExtension:SocialProfileDeveloper infoExtension:SocialProfile/For developersScreenshotsExtension:SocialProfile/ScreenshotsHistorySocial tools#History
Other social extensions Automatic Board WelcomeExtension:Automatic Board WelcomeBlogPageExtension:BlogPageChallengeExtension:ChallengeFanBoxesExtension:FanBoxesMiniInviteExtension:MiniInviteNewUsersListExtension:NewUsersListPictureGameExtension:PictureGamePollNYExtension:PollNYQuizGameExtension:QuizGameRandomFeaturedUserExtension:RandomFeaturedUserRandomGameUnitExtension:RandomGameUnitRandomUsersWithAvatarsExtension:RandomUsersWithAvatarsSiteMetricsExtension:SiteMetricsSiteScoutExtension:SiteScoutSportsTeamsExtension:SportsTeamsUserStatusExtension:UserStatusUserWelcomeExtension:UserWelcome
Other related extensions

(which do not depend on SocialProfile)

AnswersExtension:AnswersAJAXPollExtension:AJAXPollCommentsExtension:CommentsImageRatingExtension:ImageRatingLinkFilterExtension:LinkFilterMediaWikiChatExtension:MediaWikiChatNewSignupPageExtension:NewSignupPageTopListsExtension:TopListsVideoExtension:VideoVoteNYExtension:VoteNYWikiForumExtension:WikiForumWikiTextLoggedInOutExtension:WikiTextLoggedInOut