function fnAddFavoriteTeam( $user ) {
	if ( isset( $_COOKIE['sports_sid'] ) ) {
		$sport_id = $_COOKIE['sports_sid'];
		$team_id = $_COOKIE['sports_tid'];
		$thought = $_COOKIE['thought'];

		if( !$team_id ) {
			$team_id = 0;
		}

		if( $sport_id != 0 ) {
			$s = new SportsTeams();
			$s->addFavorite( $user->getID(), $sport_id, $team_id );

			if( $thought ) {
				$b = new UserStatus();
				$m = $b->addStatus( $sport_id, $team_id, $thought );
			}
		}
	}

	return true;
}
/**
 * This function appears to be unused...I think it was used in ancient history.
 */
function wfGetUserStatusProfile( $user_id, $num ) {
	global $wgScriptPath;

	$s = new UserStatus();

	$update = $s->getStatusMessages( $user_id, 0, 0, 1, $num );
	$update = $update[0];

	return SportsTeams::getLogo( $update['sport_id'], $update['team_id'], 's' ) .
		"<img src=\"{$wgScriptPath}/extensions/UserStatus/quoteIcon.png\" border=\"0\" style=\"margin-left:5px;\" alt=\"\" />
		{$update['text']}
		<img src=\"{$wgScriptPath}/extensions/UserStatus/endQuoteIcon.png\" border=\"0\" alt=\"\" />
		<span class=\"user-status-date\">" . 
			wfMsg( 'userstatus-ago', UserStatus::getTimeAgo( $update['timestamp'] ) ) .
		'</span>';
}
function wfUserProfileLatestThought( $user_profile ) {
	global $wgUser, $wgOut;

	$user_id = $user_profile->user_id;
	$s = new UserStatus();
	$user_update = $s->getStatusMessages( $user_id, 0, 0, 1, 1 );
	$user_update = ( !empty( $user_update[0] ) ? $user_update[0] : array() );

	// Safe URLs
	$more_thoughts_link = SpecialPage::getTitleFor( 'UserStatus' );
	$thought_link = SpecialPage::getTitleFor( 'ViewThought' );

	$output = '';
	if ( $user_update ) {
		$output .= '<div class="user-section-heading">
			<div class="user-section-title">' .
				wfMsg( 'sportsteams-profile-latest-thought' ) .
			'</div>
			<div class="user-section-actions">
				<div class="action-right">
					<a href="' . $more_thoughts_link->escapeFullURL( 'user='******'" rel="nofollow">' . wfMsg( 'sportsteams-profile-view-all' ) . '</a>
				</div>
				<div class="cleared"></div>
			</div>
		</div>';

		$vote_count = $vote_link = '';
		// If someone agrees with the most recent status update, show the count
		// next to the timestamp to the owner of the status update
		// After all, there's no point in showing "0 people agree with this"...
		if(
			$wgUser->getName() == $user_update['user_name'] &&
			$user_update['plus_count'] > 0
		)
		{
			$vote_count = wfMsgExt(
				'sportsteams-profile-num-agree',
				'parsemag',
				$user_update['plus_count']
			);
		}

		$view_thought_link = '<a href="' . $thought_link->escapeFullURL( "id={$user_update['id']}" ) .
			"\" rel=\"nofollow\">{$vote_count}</a>";

		// Allow registered users who are not owners of this status update to
		// vote for it unless they've already voted; if they have voted, show
		// the amount of people who agree with the status update
		if( $wgUser->isLoggedIn() && $wgUser->getName() != $user_update['user_name'] ) {
			if( !$user_update['voted'] ) {
				$vote_link = "<a href=\"javascript:void(0);\" onclick=\"SportsTeamsUserProfile.voteStatus({$user_update['id']},1)\" rel=\"nofollow\">" .
					wfMsg( 'sportsteams-profile-do-you-agree' ) . '</a>';
			} else {
				$vote_count = wfMsgExt(
					'sportsteams-profile-num-agree',
					'parsemag',
					$user_update['plus_count']
				);
			}
		}

		$output .= '<div class="status-container" id="status-update">
			<div id="status-update" class="status-message">' .
				SportsTeams::getLogo( $user_update['sport_id'], $user_update['team_id'], 's' ) .
				"{$user_update['text']}
			</div>
			<div class=\"user-status-profile-vote\">
				<span class=\"user-status-date\">" .
					wfMsg( 'sportsteams-profile-ago', SportsTeams::getTimeAgo( $user_update['timestamp'] ) ) .
				"</span>
				{$vote_link} {$view_thought_link}
			</div>
		</div>";
	} else {
		$output .= "<script type=\"text/javascript\">var __thoughts_text__ = \"" .
			wfMsg( 'sportsteams-profile-latest-thought' ) . '";
		var __view_all__ = "' . wfMsg( 'sportsteams-profile-view-all' ) . '";
		var __more_thoughts_url__ = "' . $more_thoughts_link->escapeFullURL( 'user='******'";</script>';
	}

	$wgOut->addHTML( $output );
	return true;
}
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgRequest, $wgOut, $wgUser, $wgScriptPath;

		$messages_show = 25;
		$output = '';
		$us_id = $wgRequest->getInt( 'id', $par );
		$page = $wgRequest->getInt( 'page', 1 );

		// No ID? Show an error message then.
		if( !$us_id || !is_numeric( $us_id ) ) {
			$wgOut->addHTML( wfMsg( 'userstatus-invalid-link' ) );
			return false;
		}

		/**
		 * Config for the page
		 */
		$per_page = $messages_show;

		$s = new UserStatus();
		$message = $s->getStatusMessage( $us_id );
		$user_name = $message['user_name'];
		$user = Title::makeTitle( NS_USER, $user_name );

		// Different page title, depending on whose status updates we're
		// viewing
		if ( !( $wgUser->getName() == $user_name ) ) {
			$wgOut->setPageTitle( wfMsg( 'userstatus-user-thoughts', $user_name ) );
		} else {
			$wgOut->setPageTitle( wfMsg( 'userstatus-your-thoughts' ) );
		}

		// Add CSS
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
			$wgOut->addModuleStyles( 'ext.userStatus.viewThought' );
		} else {
			$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/UserStatus/ViewThought.css' );
		}

		$output .= "<div class=\"view-thought-links\">
			<a href=\"{$user->getFullURL()}\">" .
				wfMsg( 'userstatus-user-profile', $user_name ) .
			'</a>
		</div>';
		$output .= '<div class="user-status-container">';
		$output .= '<div class="user-status-row">

				<div class="user-status-logo">

					<a href="' . SportsTeams::getNetworkURL( $message['sport_id'], $message['team_id'] ) . '">' .
						SportsTeams::getLogo( $message['sport_id'], $message['team_id'], 'm' ) .
					"</a>

				</div>

				<div class=\"user-status-message\">

					{$message['text']}

					<div class=\"user-status-date\">" .
						wfMsg( 'userstatus-ago', UserStatus::getTimeAgo( $message['timestamp'] ) ) .
					'</div>

				</div>

				<div class="cleared"></div>

		</div>
		</div>';

		$output .= '<div class="who-agrees">';
		$output .= '<h1>' . wfMsg( 'userstatus-who-agrees' ) . '</h1>';
		$voters = $s->getStatusVoters( $us_id );
		// Get the people who agree with this status update, if any
		if( $voters ) {
			foreach ( $voters as $voter ) {
				$user = Title::makeTitle( NS_USER, $voter['user_name'] );
				$avatar = new wAvatar( $voter['user_id'], 'm' );

				$output .= "<div class=\"who-agrees-row\">
					<a href=\"{$user->getFullURL()}\">{$avatar->getAvatarURL()}</a>
					<a href=\"{$user->getFullURL()}\">{$voter['user_name']}</a>
				</div>";
			}
		} else {
			$output .= '<p>' . wfMsg( 'userstatus-nobody-agrees' ) . '</p>';
		}

		$output .= '</div>';

		$wgOut->addHTML( $output );
	}
Пример #5
0
    /**
     * Gets the recent social activity for a given user.
     *
     * @param $user_name String: name of the user whose activity we want to fetch
     */
    function getEditingActivity($user_name)
    {
        global $wgUser, $wgUserProfileDisplay, $wgExtensionAssetsPath, $wgUploadPath;
        // If not enabled in site settings, don't display
        if ($wgUserProfileDisplay['activity'] == false) {
            return '';
        }
        $output = '';
        $limit = 8;
        $rel = new UserActivity($user_name, 'user', $limit);
        $rel->setActivityToggle('show_votes', 0);
        $rel->setActivityToggle('show_edits', 1);
        $rel->setActivityToggle('show_comments', 1);
        $rel->setActivityToggle('show_relationships', 0);
        $rel->setActivityToggle('show_system_gifts', 0);
        $rel->setActivityToggle('show_system_messages', 0);
        $rel->setActivityToggle('show_messages_sent', 0);
        $rel->setActivityToggle('show_user_user_follows', 0);
        $rel->setActivityToggle('show_user_site_follows', 0);
        $rel->setActivityToggle('show_user_update_status', 0);
        $rel->setActivityToggle('show_gifts_sent', 0);
        $rel->setActivityToggle('show_gifts_rec', 0);
        $rel->setActivityToggle('show_domain_creations', 1);
        $rel->setActivityToggle('show_image_uploads', 0);
        /**
         * Get all relationship activity
         */
        $activity = $rel->getActivityList();
        if ($activity) {
            $output .= '<div class="panel panel-default"><div class="user-section-heading panel-heading">
				<div class="user-section-title">' . wfMessage('user-recent-local-activity-title')->escaped() . '</div>
				<div class="user-section-actions">
					<div class="action-right">
					</div>
					<div class="cleared"></div>
				</div>
			</div>
			<div class="cleared"></div>
			<div class="panel-body">';
            $x = 1;
            if (count($activity) < $limit) {
                $style_limit = count($activity);
            } else {
                $style_limit = $limit;
            }
            foreach ($activity as $item) {
                $item_html = '';
                $title = Title::makeTitle($item['namespace'], $item['pagetitle'], '', $item['prefix']);
                $user_title = Title::makeTitle(NS_USER, $item['username']);
                $user_title_2 = Title::makeTitle(NS_USER, $item['comment']);
                if ($user_title_2) {
                    $user_link_2 = '<a href="' . htmlspecialchars($user_title_2->getFullURL()) . '" rel="nofollow">' . $item['comment'] . '</a>';
                }
                $comment_url = '';
                if ($item['type'] == 'comment') {
                    $comment_url = "#comment-{$item['id']}";
                }
                $page_link = '<b><a href="' . htmlspecialchars($title->getFullURL()) . "{$comment_url}\">" . $title->getText() . '</a></b> ';
                $b = new UserBoard();
                // Easier than porting the time-related functions here
                $item_time = '<span class="item-small">' . wfMessage('user-time-ago', $b->getTimeAgo($item['timestamp']))->escaped() . '</span>';
                if ($x < $style_limit) {
                    $item_html .= '<div class="activity-item">' . UserActivity::getTypeIcon($item['type']);
                } else {
                    $item_html .= '<div class="activity-item-bottom">' . UserActivity::getTypeIcon($item['type']);
                }
                $viewGift = SpecialPage::getTitleFor('ViewGift');
                switch ($item['type']) {
                    case 'edit':
                        $item_html .= wfMessage('user-recent-activity-edit')->escaped() . " {$page_link} {$item_time}\n\t\t\t\t\t\t\t<div class=\"item\">";
                        if ($item['comment']) {
                            $item_html .= "\"{$item['comment']}\"";
                        }
                        $item_html .= '</div>';
                        break;
                    case 'vote':
                        $item_html .= wfMessage('user-recent-activity-vote')->escaped() . " {$page_link} {$item_time}";
                        break;
                    case 'comment':
                        $item_html .= wfMessage('user-recent-activity-comment')->escaped() . " {$page_link} {$item_time}\n\t\t\t\t\t\t\t<div class=\"item\">\n\t\t\t\t\t\t\t\t\"{$item['comment']}\"\n\t\t\t\t\t\t\t</div>";
                        break;
                    case 'gift-sent':
                        $gift_image = "<img src=\"{$wgUploadPath}/awards/" . Gifts::getGiftImage($item['namespace'], 'm') . '" border="0" alt="" />';
                        $item_html .= wfMessage('user-recent-activity-gift-sent')->escaped() . " {$user_link_2} {$item_time}\n\t\t\t\t\t\t<div class=\"item\">\n\t\t\t\t\t\t\t<a href=\"" . htmlspecialchars($viewGift->getFullURL("gift_id={$item['id']}")) . "\" rel=\"nofollow\">\n\t\t\t\t\t\t\t\t{$gift_image}\n\t\t\t\t\t\t\t\t{$item['pagetitle']}\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t</div>";
                        break;
                    case 'gift-rec':
                        $gift_image = "<img src=\"{$wgUploadPath}/awards/" . Gifts::getGiftImage($item['namespace'], 'm') . '" border="0" alt="" />';
                        $item_html .= wfMessage('user-recent-activity-gift-rec')->escaped() . " {$user_link_2} {$item_time}</span>\n\t\t\t\t\t\t\t\t<div class=\"item\">\n\t\t\t\t\t\t\t\t\t<a href=\"" . htmlspecialchars($viewGift->getFullURL("gift_id={$item['id']}")) . "\" rel=\"nofollow\">\n\t\t\t\t\t\t\t\t\t\t{$gift_image}\n\t\t\t\t\t\t\t\t\t\t{$item['pagetitle']}\n\t\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\t</div>";
                        break;
                    case 'system_gift':
                        $gift_image = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($item['namespace'], 'm') . '" border="0" alt="" />';
                        $viewSystemGift = SpecialPage::getTitleFor('ViewSystemGift');
                        $item_html .= wfMessage('user-recent-system-gift')->escaped() . " {$item_time}\n\t\t\t\t\t\t\t\t<div class=\"user-home-item-gift\">\n\t\t\t\t\t\t\t\t\t<a href=\"" . htmlspecialchars($viewSystemGift->getFullURL("gift_id={$item['id']}")) . "\" rel=\"nofollow\">\n\t\t\t\t\t\t\t\t\t\t{$gift_image}\n\t\t\t\t\t\t\t\t\t\t{$item['pagetitle']}\n\t\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\t</div>";
                        break;
                    case 'friend':
                        $item_html .= wfMessage('user-recent-activity-friend')->escaped() . " <b>{$user_link_2}</b> {$item_time}";
                        break;
                    case 'foe':
                        $item_html .= wfMessage('user-recent-activity-foe')->escaped() . " <b>{$user_link_2}</b> {$item_time}";
                        break;
                    case 'system_message':
                        $item_html .= "{$item['comment']} {$item_time}";
                        break;
                    case 'user_message':
                        $item_html .= wfMessage('user-recent-activity-user-message')->escaped() . " <b><a href=\"" . UserBoard::getUserBoardURL($user_title_2->getText()) . "\" rel=\"nofollow\">{$item['comment']}</a></b>  {$item_time}\n\t\t\t\t\t\t\t\t<div class=\"item\">\n\t\t\t\t\t\t\t\t\"{$item['namespace']}\"\n\t\t\t\t\t\t\t\t</div>";
                        break;
                    case 'network_update':
                        $network_image = SportsTeams::getLogo($item['sport_id'], $item['team_id'], 's');
                        $item_html .= wfMessage('user-recent-activity-network-update')->escaped() . '<div class="item">
									<a href="' . SportsTeams::getNetworkURL($item['sport_id'], $item['team_id']) . "\" rel=\"nofollow\">{$network_image} \"{$item['comment']}\"</a>\n\t\t\t\t\t\t\t\t</div>";
                        break;
                    case 'domain_creation':
                        $domainLink = '<b><a href="' . htmlspecialchars($title->getFullURL()) . "\">" . $item['domainname'] . '</a></b> ';
                        $item_html .= wfMessage('user-recent-activity-domain-creation')->escaped() . "{$domainLink} {$item_time}" . '<div class="item">
									<p>' . $item['comment'] . "</p>\n\t\t\t\t\t\t\t\t</div>";
                        break;
                }
                $item_html .= '</div>';
                if ($x <= $limit) {
                    $items_html_type['all'][] = $item_html;
                }
                $items_html_type[$item['type']][] = $item_html;
                $x++;
            }
            $by_type = '';
            foreach ($items_html_type['all'] as $item) {
                $by_type .= $item;
            }
            $output .= "<div id=\"recent-all\">{$by_type}</div></div></div>";
        }
        return $output;
    }
	function displayForm( $id ) {
		global $wgUser, $wgRequest, $wgUploadPath;

		$form = '<div><b><a href="' . $this->getTitle()->escapeFullURL( 'sport_id=' . $wgRequest->getInt( 'sport_id' ) ) . '">' .
			wfMsg( 'sportsteams-team-manager-view-teams' ) . '</a></b></div><p>';

		if( $id ) {
			$team = SportsTeams::getTeam( $id );
		} else {
			$team = array( 'id' => '', 'name' => '' ); // prevent notices
		}

		// @todo FIXME: rename the form from gift to something else and update line 225 accordingly
		$form .= '<form action="" method="post" enctype="multipart/form-data" name="gift">';

		$form .= '<table border="0" cellpadding="5" cellspacing="0" width="500">';

		$form .= '

			<tr>
			<td width="200" class="view-form">' . wfMsg( 'sportsteams-team-manager-sport' ) . '</td>
			<td width="695">
				<select name="s_id">';
		$sports = SportsTeams::getSports();
		foreach( $sports as $sport ) {
			$selected = '';
			if (
				$wgRequest->getInt( 'sport_id' ) == $sport['id'] ||
				$sport['id'] == $team['sport_id']
			)
			{
				$selected = ' selected';
			}
			$form .= "<option{$selected} value=\"{$sport['id']}\">{$sport['name']}</option>";
		}
		$form .= '</select>

			</tr>
			<tr>
				<td width="200" class="view-form">' .
					wfMsg( 'sportsteams-team-manager-teamname' ) .
				'</td>
				<td width="695">
					<input type="text" size="45" class="createbox" name="team_name" value="' . $team['name'] . '" />
				</td>
			</tr>
			';

		if( $id ) {
			$team_image = "<img src=\"{$wgUploadPath}/team_logos/" .
				SportsTeams::getTeamLogo( $id, 'l' ) .
				'" border="0" alt="logo" />';
			$form .= '<tr>
					<td width="200" class="view-form" valign="top">' .
						wfMsg( 'sportsteams-team-manager-team' ) .
					'</td>
					<td width="695">' . $team_image . '
						<p>
						<a href="' . SpecialPage::getTitleFor( 'SportsTeamsManagerLogo' )->escapeFullURL( "id={$id}" ) . '">' .
							wfMsg( 'sportsteams-team-manager-add-replace-logo' ) .
						'</a>
					</td>
				</tr>';
			}

		if ( $id ) {
			$msg = wfMsg( 'sportsteams-team-manager-edit' );
		} else {
			$msg = wfMsg( 'sportsteams-team-manager-add-team' );
		}

		$form .= '<tr>
				<td colspan="2">
					<input type="hidden" name="id" value="' . $id . '" />
					<input type="button" class="site-button" value="' . $msg . '" size="20" onclick="document.gift.submit()" />
					<input type="button" class="site-button" value="' . wfMsg( 'cancel' ) . '" size="20" onclick="history.go(-1)" />
				</td>
			</tr>
		</table>

		</form>';
		return $form;
	}
	/**
	 * Displays the main upload form, optionally with a highlighted
	 * error message up at the top.
	 *
	 * @param $msg String: error message as HTML
	 * @access private
	 */
	function mainUploadForm( $msg = '' ) {
		global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest;
		global $wgUseCopyrightUpload, $wgUploadPath;

		$cols = intval( $wgUser->getOption( 'cols' ) );
		$ew = $wgUser->getOption( 'editwidth' );
		if ( $ew ) {
			$ew = ' style="width:100%"';
		} else {
			$ew = '';
		}

		if ( $msg != '' ) {
			$sub = wfMsg( 'uploaderror' );
			$wgOut->addHTML( "<h2>{$sub}</h2>\n" .
				"<h4 class=\"error\">{$msg}</h4>\n" );
		}

		$sk = $wgUser->getSkin();

		$sourcefilename = wfMsg( 'sourcefilename' );
		$destfilename = wfMsg( 'destfilename' );

		$fd = wfMsg( 'filedesc' );
		$ulb = wfMsg( 'uploadbtn' );

		$iw = wfMsg( 'ignorewarning' );

		$titleObj = SpecialPage::getTitleFor( 'Upload' );
		$action = $titleObj->escapeLocalURL();

		$encDestFile = htmlspecialchars( $this->mDestFile );
		$source = null;

		if ( $wgUseCopyrightUpload ) {
			$source = "
	<td align='right' nowrap='nowrap'>" . wfMsg( 'filestatus' ) . ":</td>
	<td><input tabindex='3' type='text' name=\"wpUploadCopyStatus\" value=\"" .
	htmlspecialchars( $this->mUploadCopyStatus ). "\" size='40' /></td>
	</tr><tr>
	<td align='right'>" . wfMsg ( 'filesource' ) . ":</td>
	<td><input tabindex='4' type='text' name='wpUploadSource' value=\"" .
	htmlspecialchars( $this->mUploadSource ). "\" style='width:100px' /></td>
	" ;
		}

		$watchChecked = $wgUser->getOption( 'watchdefault' )
			? 'checked="checked"'
			: '';

		$team_logo = SportsTeams::getSportLogo( $this->team_id, 'l' );
		if( $team_logo != '' ) {
			$output = '<table><tr><td style="color:#666666;font-weight:800">' .
				wfMsg( 'sportsteams-logo-current-image' ) . '</td></tr>';
			$output .= '<tr><td><img src="' . $wgUploadPath . '/sport_logos/' .
				$team_logo . '" border="0" alt="no logo" /></td></tr></table><br />';
		}
		$wgOut->addHTML( $output );

		$wgOut->addHTML( "
	<form id='upload' method='post' enctype='multipart/form-data' action=\"\">
	<table border='0'><tr>

	<td style='color:#666666;font-weight:800'>" . wfMsg( 'sportsteams-logo-image-instructions' ) . "<br />
	<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' style='width:100px' />
	</td></tr><tr>
	{$source}
	</tr>
	<tr><td>
	<input tabindex='5' type='submit' name='wpUpload' value=\"{$ulb}\" />
	</td></tr></table></form>\n" );
	}
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgScriptPath;

		$output = '';

		/**
		 * Get query string variables
		 */
		$sport_id = $wgRequest->getInt( 'sport_id' );
		$team_id = $wgRequest->getInt( 'team_id' );

		// Add CSS
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
			$wgOut->addModuleStyles( 'ext.sportsTeams' );
		} else {
			$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SportsTeams/SportsTeams.css' );
		}

		/**
		 * Error message for URL with no team and sport specified
		 */
		if( !$team_id && !$sport_id ) {
			$wgOut->setPageTitle( wfMsg( 'sportsteams-network-woops-title' ) );
			$out = '<div class="relationship-request-message">' .
				wfMsg( 'sportsteams-network-woops-text' ) . '</div>';
			$out .= '<div class="relationship-request-buttons">';
			$out .= '<input type="button" class="site-button" value="' .
				wfMsg( 'sportsteams-network-main-page' ) . "\" onclick=\"window.location='" .
				Title::newMainPage()->escapeFullURL() . "'\"/>";
			if ( $wgUser->isLoggedIn() ) {
				$out .= ' <input type="button" class="site-button" value="' .
					wfMsg( 'sportsteams-network-your-profile' ) .
					"\" onclick=\"window.location='" .
					Title::makeTitle( NS_USER, $wgUser->getName() )->escapeFullURL() . "'\"/>";
			}
			$out .= '</div>';
			$wgOut->addHTML( $out );
			return false;
		}

		// If the database is in read-only mode, bail out
		if( wfReadOnly() ) {
			$wgOut->readOnlyPage();
			return true;
		}

		if( $team_id ) {
			$team = SportsTeams::getTeam( $team_id );
			$name = $team['name'];
		} else {
			$sport = SportsTeams::getSport( $sport_id );
			$name = $sport['name'];
		}

		if( $wgRequest->wasPosted() ) {
			$s = new SportsTeams();
			$s->removeFavorite(
				$wgUser->getID(),
				$wgRequest->getVal( 's_id' ),
				$wgRequest->getVal( 't_id' )
			);

			$wgOut->setPageTitle( wfMsg( 'sportsteams-network-no-longer-member', $name ) );
			$output .= '<div class="give-gift-message">
				<input type="button" class="site-button" value="' .
					wfMsg( 'sportsteams-network-main-page' ) .
					"\" onclick=\"window.location='" .
					Title::newMainPage()->escapeFullURL() . "'\"/>
				<input type=\"button\" class=\"site-button\" value=\"" .
					wfMsg( 'sportsteams-network-your-profile' ) .
					"\" onclick=\"window.location='" .
					Title::makeTitle( NS_USER, $wgUser->getName() )->escapeFullURL() . "'\"/>
			</div>";
		} else {
			/**
			 * Error message if the user is not a fan
			 */
			if( !SportsTeams::isFan( $wgUser->getID(), $sport_id, $team_id ) == true ) {
				$wgOut->setPageTitle( wfMsg( 'sportsteams-network-not-member', $name ) );
				//out .= '<div class="relationship-request-message">' . wfMsg( 'sportsteams-network-no-need-join' ) . '</div>';
				$out .= '<div class="relationship-request-buttons">';
				$out .= '<input type="button" class="site-button" value="' .
					wfMsg( 'sportsteams-network-main-page' ) .
					"\" onclick=\"window.location='" .
					Title::newMainPage()->escapeFullURL() . "'\"/>";
				if ( $wgUser->isLoggedIn() ) {
					$out .= ' <input type="button" class="site-button" value="' .
						wfMsg( 'sportsteams-network-your-profile' ) .
						"\" onclick=\"window.location='" .
						Title::makeTitle( NS_USER, $wgUser->getName() )->escapeFullURL() . "'\"/>";
				}
				$out .= '</div>';
				$wgOut->addHTML( $out );
				return false;
			}
			$wgOut->setPageTitle( wfMsg( 'sportsteams-network-leave', $name ) );

			$output .= '<form action="" method="post" enctype="multipart/form-data" name="form1">

				<div class="give-gift-message" style="margin:0px 0px 0px 0px;">' .
					wfMsg( 'sportsteams-network-leave-are-you-sure', $name ) .
				"</div>

				<div class=\"cleared\"></div>
				<div class=\"give-gift-buttons\">
					<input type=\"hidden\" name=\"s_id\" value=\"{$sport_id}\" />
					<input type=\"hidden\" name=\"t_id\" value=\"{$team_id}\" />
					<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'sportsteams-network-remove-me' ) . "\" size=\"20\" onclick=\"document.form1.submit()\" />
					<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"history.go(-1)\" />
				</div>
			</form>";
		}

		$wgOut->addHTML( $output );
	}
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgUser, $wgOut, $wgRequest, $wgScriptPath, $wgUploadPath;

		$output = '';

		/**
		 * Get query string variables
		 */
		$page = $wgRequest->getInt( 'page', 1 );
		$sport_id = $wgRequest->getVal( 'sport_id' );
		$team_id = $wgRequest->getVal( 'team_id' );

		/**
		 * Error message for teams/sports that do not exist (from URL)
		 */
		if( !$team_id && !$sport_id ) {
			$wgOut->setPageTitle( wfMsg( 'sportsteams-network-woops-title' ) );
			$out = '<div class="relationship-request-message">' .
				wfMsg( 'sportsteams-network-woops-text' ) . '</div>';
			$out .= '<div class="relationship-request-buttons">';
			$out .= '<input type="button" class="site-button" value="' .
				wfMsg( 'sportsteams-network-main-page' ) .
				"\" onclick=\"window.location='" .
				Title::newMainPage()->escapeFullURL() . "'\"/>";
			if ( $wgUser->isLoggedIn() ) {
				$out .= ' <input type="button" class="site-button" value="' .
					wfMsg( 'sportsteams-network-your-profile' ) .
					"\" onclick=\"window.location='" .
					Title::makeTitle( NS_USER, $wgUser->getName() )->escapeFullURL() . "'\"/>";
			}
		  	$out .= '</div>';
			$wgOut->addHTML( $out );
			return false;
		}

		// Add CSS
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
			$wgOut->addModuleStyles( 'ext.sportsTeams' );
		} else {
			$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SportsTeams/SportsTeams.css' );
		}

		$relationships = array();
		$friends = array();
		$foes = array();
		if( $wgUser->isLoggedIn() ) {
			$friends = $this->getRelationships( 1 );
			$foes = $this->getRelationships( 2 );
			$relationships = array_merge( $friends, $foes );
		}

		/**
		 * Set up config for page / default values
		 */
		$per_page = 50;
		$per_row = 2;

		if( $team_id ) {
			$team = SportsTeams::getTeam( $team_id );
			$this->network = $team['name'];
			$team_image = "<img src=\"{$wgUploadPath}/team_logos/" .
				SportsTeams::getTeamLogo( $team_id, 'l' ) .
				'" border="0" alt="' . wfMsg( 'sportsteams-network-alt-logo' ) . '" />';
		} else {
			$sport = SportsTeams::getSport( $sport_id );
			$this->network = $team['name'];
			$team_image = "<img src=\"{$wgUploadPath}/team_logos/" .
				SportsTeams::getSportLogo( $sport_id, 'l' ) .
				'" border="0" alt="' . wfMsg( 'sportsteams-network-alt-logo' ) . '" />';
		}
		$homepage_title = SpecialPage::getTitleFor( 'FanHome' );

		$total = SportsTeams::getUserCount( $sport_id, $team_id );

		/* Get all fans */
		$fans = SportsTeams::getUsersByFavorite(
			$sport_id, $team_id, $per_page, $page
		);

		$wgOut->setPageTitle( wfMsg( 'st-network-network-fans', $this->network ) );

		$output .= '<div class="friend-links">';
		$output .= "<a href=\"". $homepage_title->getFullURL(
			"sport_id={$sport_id}&team_id={$team_id}"
		) . '">' . wfMsg( 'sportsteams-network-back-to-network', $this->network ) . '</a>';
		$output .= '</div>';

		/* Show total fan count */
		$output .= '<div class="friend-message">' .
			wfMsgExt(
				'sportsteams-network-num-fans',
				'parsemag',
				$this->network,
				$total,
				SpecialPage::getTitleFor( 'InviteContacts' )->escapeFullURL()
			);
		$output .= '</div>';

		if( $fans ) {
			$x = 1;

			foreach ( $fans as $fan ) {
				$user = Title::makeTitle( NS_USER, $fan['user_name'] );
				$avatar = new wAvatar( $fan['user_id'], 'l' );
				$avatar_img = $avatar->getAvatarURL();

				$output .= "<div class=\"relationship-item\">
						<div class=\"relationship-image\"><a href=\"{$user->getFullURL()}\">{$avatar_img}</a></div>
						<div class=\"relationship-info\">
						<div class=\"relationship-name\">
							<a href=\"{$user->getFullURL()}\">{$fan['user_name']}</a>";

				$output .= '</div>
					<div class="relationship-actions">';
				if( in_array( $fan['user_id'], $friends ) ) {
					$output .= '	<span class="profile-on">' . wfMsg( 'sportsteams-your-friend' ) . '</span> ';
				}
				if( in_array( $fan['user_id'], $foes ) ) {
					$output .= '	<span class="profile-on">' . wfMsg( 'sportsteams-your-foe' ) . '</span> ';
				}
				if( $fan['user_name'] != $wgUser->getName() ) {
					if( !in_array( $fan['user_id'], $relationships ) ) {
						$ar = SpecialPage::getTitleFor( 'AddRelationship' );
						$output .= '<a href="' . $ar->escapeFullURL( "user={$fan['user_name']}&rel_type=1" ) . '">' .
							wfMsg( 'sportsteams-add-as-friend' ) . '</a> | ';
						$output .= '<a href="' . $ar->escapeFullURL( "user={$fan['user_name']}&rel_type=2" ) . '">' .
							wfMsg( 'sportsteams-add-as-foe' ) . '</a> | ';
					}
					$output .= '<a href="' . SpecialPage::getTitleFor( 'GiveGift' )->escapeFullURL( "user={$fan['user_name']}" ) . '">' .
						wfMsg( 'sportsteams-give_a_gift' ) . '</a> ';
					//$output .= "<p class=\"relationship-link\"><a href=\"index.php?title=Special:ChallengeUser&user={$fan['user_name']}\"><img src=\"images/common/challengeIcon.png\" border=\"0\" alt=\"issue challenge\"/> issue challenge</a></p>";
					$output .= '<div class="cleared"></div>';
				}
				$output .= '</div>';

				$output .= '<div class="cleared"></div></div>';

				$output .= '</div>';
				if( $x == count( $fans ) || $x != 1 && $x % $per_row == 0 ) {
					$output .= '<div class="cleared"></div>';
				}
				$x++;
			}
		}

		/**
		 * Build next/prev navigation
		 */
		$numofpages = $total / $per_page;

		if ( $numofpages > 1 ) {
			$output .= '<div class="page-nav">';
			if( $page > 1 ) {
				$output .= '<a href="' . $this->getTitle()->escapeFullURL(
					'page=' . ( $page - 1 ) . "&sport_id={$sport_id}&team_id={$team_id}"
				) . '">' . wfMsg( 'sportsteams-prev' ) . '</a> ';
			}

			if( ( $total % $per_page ) != 0 ) {
				$numofpages++;
			}
			if( $numofpages >= 9 ) {
				$numofpages = 9 + $page;
			}

			for( $i = 1; $i <= $numofpages; $i++ ) {
				if( $i == $page ) {
				    $output .= ( $i . ' ' );
				} else {
				    $output .= '<a href="' . $this->getTitle()->escapeFullURL(
						'page=' . ( $i ) . "&sport_id={$sport_id}&team_id={$team_id}"
					) . "\">$i</a> ";
				}
			}

			if( ( $total - ( $per_page * $page ) ) > 0 ) {
				$output .= ' <a href="' . $this->getTitle()->escapeFullURL(
					'page=' . ( $page + 1 ) . "&sport_id={$sport_id}&team_id={$team_id}"
				) . '">' . wfMsg( 'sportsteams-next' ) . '</a>';
			}
			$output .= '</div>';
		}

		$wgOut->addHTML( $output );
	}
	public function updateUserCache( $text, $sport_id, $team_id = 0 ) {
		global $wgUser, $wgMemc;
		$key = wfMemcKey( 'user', 'status-last-update', $wgUser->getID() );

		$data['text'] = $this->formatMessage( $text );
		$data['sport_id'] = $sport_id;
		$data['team_id'] = $team_id;
		$data['timestamp'] = time();
		if( $team_id ) {
			$team = SportsTeams::getTeam( $team_id );
			$data['network'] = $team['name'];
		} else {
			$sport = SportsTeams::getSport( $sport_id );
			$data['network'] = $sport['name'];
		}
		$wgMemc->set( $key, $data );
	}
	/**
	 * Get the full <img> tag for the given sport team's logo image.
	 *
	 * @param $sport_id Integer: sport ID number
	 * @param $team_id Integer: team ID number, 0 by default
	 * @param $size String: 's' for small, 'm' for medium, 'ml' for
	 *                      medium-large and 'l' for large
	 * @return String: full <img> tag
	 */
	static function getLogo( $sport_id, $team_id = 0, $size ) {
		global $wgUploadPath;

		if( $sport_id > 0 && $team_id == 0 ) {
			$logoTag = '<img src="' . $wgUploadPath . '/sport_logos/' .
				SportsTeams::getSportLogo( $sport_id, $size ) .
				'" border="0" alt="" />';
		} else {
			$logoTag = '<img src="' . $wgUploadPath . '/team_logos/' .
				SportsTeams::getTeamLogo( $team_id, $size ) .
				'" border="0" alt="" />';
		}

		return $logoTag;
	}
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgOut, $wgRequest, $wgScriptPath, $wgUser;

		if( !$wgUser->isLoggedIn() ) {
			$wgOut->setPageTitle( wfMsg( 'user-profile-sports-notloggedintitle' ) );
			$wgOut->addHTML( wfMsg( 'user-profile-sports-notloggedintitle' ) );
			return;
		}

		// If the database is in read-only mode, bail out
		if( wfReadOnly() ) {
			$wgOut->readOnlyPage();
			return true;
		}

		$sports = $this->getSports();
		// Error message when there are no sports in the database
		if ( empty( $sports ) ) {
			$wgOut->setPageTitle( wfMsg( 'sportsteams-error-no-sports-title' ) );
			$wgOut->addWikiMsg( 'sportsteams-error-no-sports-message' );
			return;
		}

		// Set the page title
		$wgOut->setPageTitle( wfMsg( 'user-profile-sports-title' ) );

		// Add CSS and JS
		$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserProfile/UserProfile.css' );

		// This JS file was originally in its own directory (it was and is used
		// only by this special page and the LoginReg extension)...how silly.
		$wgOut->addScriptFile( $wgScriptPath . '/extensions/SportsTeams/DoubleCombo.js' );

		// This JS file originally didn't even exist
		$wgOut->addScriptFile( $wgScriptPath . '/extensions/SportsTeams/UpdateFavoriteTeams.js' );

		// This is annoying so I took it out for now.
		//$output = '<h1>' . wfMsg( 'user-profile-sports-title' ) . '</h1>';

		// Build the top navigation tabs
		// @todo CHECKME: there should be a UserProfile method for building all
		// this, I think
		$output = '<div class="profile-tab-bar">';
		$output .= '<div class="profile-tab">';
		$output .= '<a href="' . SpecialPage::getTitleFor( 'UpdateProfile', 'basic' )->escapeFullURL() . '">' .
			wfMsg( 'user-profile-section-personal' ) . '</a>';
		$output .= '</div>';
		$output .= '<div class="profile-tab-on">';
		$output .= wfMsg( 'user-profile-section-sportsteams' );
		$output .= '</div>';
		$output .= '<div class="profile-tab">';
		$output .= '<a href="' . SpecialPage::getTitleFor( 'UpdateProfile', 'custom' )->escapeFullURL() . '">' .
			/*wfMsg( 'user-profile-section-sportstidbits' )*/wfMsg( 'custom-info-title' ) . '</a>';
		$output .= '</div>';
		$output .= '<div class="profile-tab">';
		$output .= '<a href="' . SpecialPage::getTitleFor( 'UpdateProfile', 'personal' )->escapeFullURL() . '">' .
			wfMsg( 'user-profile-section-interests' ) . '</a>';
		$output .= '</div>';
		$output .= '<div class="profile-tab">';
		$output .= '<a href="' . SpecialPage::getTitleFor( 'UploadAvatar' )->escapeFullURL() . '">' .
			wfMsg( 'user-profile-section-picture' ) . '</a>';
		$output .= '</div>';
		$output .= '<div class="profile-tab">';
		$output .= '<a href="' . SpecialPage::getTitleFor( 'UpdateProfile', 'preferences' )->escapeFullURL() . '">' .
			wfMsg( 'user-profile-section-preferences' ) . '</a>';
		$output .= '</div>';

		$output .= '<div class="cleared"></div>';
		$output .= '</div>';

		$output .= '<div class="profile-info">';

		// If the request was POSTed, add/delete teams accordingly
		if( $wgRequest->wasPosted() ) {
			if( $wgRequest->getVal( 'action' ) == 'delete' ) {
				SportsTeams::removeFavorite(
					$wgUser->getId(),
					$wgRequest->getVal( 's_id' ),
					$wgRequest->getVal( 't_id' )
				);
				SportsTeams::clearUserCache( $wgUser->getId() );
				$wgOut->addHTML(
					'<br /><br /><span class="profile-on">' .
						wfMsg( 'user-profile-sports-teamremoved' ) .
					'</span><br /><br />'
				);
			}

			if( $wgRequest->getVal( 'favorites' ) ) {
				// Clear user cache
				SportsTeams::clearUserCache( $wgUser->getId() );

				$dbw = wfGetDB( DB_MASTER );
				// Reset old favorites
				$res = $dbw->delete(
					'sport_favorite',
					array( 'sf_user_id' => $wgUser->getId() ),
					__METHOD__
				);

				$items = explode( '|', $wgRequest->getVal( 'favorites' ) );
				foreach( $items as $favorite ) {
					if( $favorite ) {
						$atts = explode( ',', $favorite );
						$sport_id = $atts[0];
						$team_id = $atts[1];

						if( !$team_id ) {
							$team_id = 0;
						}
						$s = new SportsTeams();
						$s->addFavorite( $wgUser->getId(), $sport_id, $team_id );
					}
				}
				$wgOut->addHTML(
					'<br /><br /><span class="profile-on">' .
						wfMsg( 'user-profile-sports-teamsaved' ) .
					'</span><br /><br />'
				);
			}
		}

		$favorites = $this->getFavorites();
		foreach( $favorites as $favorite ) {
			$output .= $this->getSportsDropdown(
				$favorite['sport_id'],
				$favorite['team_id']
			);
		}

		$output .= '<div>';
		if( count( $favorites ) > 0 ) {
			$output .= '<div style="display: block" id="add_more"></div>';
		}

		for( $x = 0; $x <= ( 20 - count( $favorites ) ); $x++ ) {
			$output .= $this->getSportsDropdown();
		}

		$output .= '<form action="" name="sports" method="post">
			<input type="hidden" value="" name="favorites" />
			<input type="hidden" value="save" name="action" />';

		if( count( $favorites ) > 0 ) {
			$output .= '<input type="button" class="profile-update-button" onclick="UpdateFavoriteTeams.showNext()" value="' .
				wfMsg( 'user-profile-sports-addmore' ) . '" />';
		}

		$output .= '<input type="button" class="profile-update-button" value="' .
			wfMsg( 'user-profile-update-button' ) . '" onclick="UpdateFavoriteTeams.saveTeams()" id="update-favorite-teams-save-button" />
			</form>
			<form action="" name="sports_remove" method="post">
				<input type="hidden" value="delete" name="action" />
				<input type="hidden" value="" name="s_id" />
				<input type="hidden" value="" name="t_id" />
			</form>
			<script>
				UpdateFavoriteTeams.fav_count = ' . ( ( count( $favorites ) ) ? count( $favorites ) : 1 ) . ';
			</script>
			</div>
		</div>';

		$wgOut->addHTML( $output );
	}
Пример #13
0
    /**
     * Get recent status updates (but only if the SportsTeams extension is
     * installed) and set them in the appropriate class member variables.
     */
    private function setNetworkUpdates()
    {
        global $wgLang;
        if (!class_exists('SportsTeams')) {
            return;
        }
        $dbr = wfGetDB(DB_SLAVE);
        $where = $this->where('us_user_id');
        $option = $this->option('us_id');
        $res = $dbr->select('user_status', array('us_id', 'us_user_id', 'us_user_name', 'us_text', 'UNIX_TIMESTAMP(us_date) AS item_date', 'us_sport_id', 'us_team_id'), $where, __METHOD__, $option);
        foreach ($res as $row) {
            if ($row->us_team_id) {
                $team = SportsTeams::getTeam($row->us_team_id);
                $network_name = $team['name'];
            } else {
                $sport = SportsTeams::getSport($row->us_sport_id);
                $network_name = $sport['name'];
            }
            $this->items[] = array('id' => $row->us_id, 'type' => 'network_update', 'timestamp' => $row->item_date, 'pagetitle' => '', 'namespace' => '', 'username' => $row->us_user_name, 'userid' => $row->us_user_id, 'comment' => $row->us_text, 'sport_id' => $row->us_sport_id, 'team_id' => $row->us_team_id, 'network' => $network_name);
            $user_title = Title::makeTitle(NS_USER, $row->us_user_name);
            $user_name_short = $wgLang->truncate($row->us_user_name, 15);
            $page_link = '<a href="' . SportsTeams::getNetworkURL($row->us_sport_id, $row->us_team_id) . "\" rel=\"nofollow\">{$network_name}</a>";
            $network_image = SportsTeams::getLogo($row->us_sport_id, $row->us_team_id, 's');
            $html = wfMessage('useractivity-network-thought', $row->us_user_name, $user_name_short, $page_link, htmlspecialchars($user_title->getFullURL()))->text() . '<div class="item">
						<a href="' . SportsTeams::getNetworkURL($row->us_sport_id, $row->us_team_id) . "\" rel=\"nofollow\">\n\t\t\t\t\t\t\t{$network_image}\n\t\t\t\t\t\t\t\"{$row->us_text}\"\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</div>";
            $this->activityLines[] = array('type' => 'network_update', 'timestamp' => $row->item_date, 'data' => $html);
        }
    }
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgRequest, $wgOut, $wgUser, $wgScriptPath;

		$messages_show = 25;
		$output = '';
		$user_name = $wgRequest->getVal( 'user', $par );
		$page = $wgRequest->getInt( 'page', 1 );

		/**
		 * Redirect Non-logged in users to Login Page
		 * It will automatically return them to their Status page
		 */
		if( $wgUser->getID() == 0 && $user_name == '' ) {
			$wgOut->setPageTitle( wfMsg( 'userstatus-woops' ) );
			$login = SpecialPage::getTitleFor( 'Userlogin' );
			$wgOut->redirect( $login->getFullURL( 'returnto=Special:UserStatus' ) );
			return false;
		}

		/**
		 * If no user is set in the URL, we assume its the current user
		 */
		if( !$user_name ) {
			$user_name = $wgUser->getName();
		}
		$user_id = User::idFromName( $user_name );
		$user = Title::makeTitle( NS_USER, $user_name );

		/**
		 * Error message for username that does not exist (from URL)
		 */
		if( $user_id == 0 ) {
			$wgOut->setPageTitle( wfMsg( 'userstatus-woops' ) );
			$wgOut->addHTML( wfMsg( 'userstatus-no-user' ) );
			return false;
		}

		/**
		 * Config for the page
		 */
		$per_page = $messages_show;

		$stats = new UserStats( $user_id, $user_name );
		$stats_data = $stats->getUserStats();
		$total = $stats_data['user_status_count'];

		$s = new UserStatus();
		$messages = $s->getStatusMessages( $user_id, 0, 0, $messages_show, $page );

		if ( !( $wgUser->getName() == $user_name ) ) {
			$wgOut->setPageTitle( wfMsg( 'userstatus-user-thoughts', $user_name ) );
		} else {
			$wgOut->setPageTitle( wfMsg( 'userstatus-your-thoughts' ) );
		}

		$output .= '<div class="gift-links">';
		if ( !( $wgUser->getName() == $user_name ) ) {
			$output .= "<a href=\"{$user->getFullURL()}\">" .
				wfMsg( 'userstatus-back-user-profile', $user_name ) . '</a>';
		} else {
			$output .= '<a href="' . $wgUser->getUserPage()->getFullURL() . '">' .
				wfMsg( 'userstatus-back-your-profile' ) . '</a>';
		}
		$output .= '</div>';

		if( $page == 1 ) {
			$start = 1;
		} else {
			$start = ( $page - 1 ) * $per_page + 1;
		}

		$end = $start + ( count( $messages ) ) - 1;
		wfDebug( "total = {$total}" );

		if( $total ) {
			$output .= '<div class="user-page-message-top">
				<span class="user-page-message-count" style="font-size: 11px; color: #666666;">' .
					wfMsgExt( 'userstatus-showing-thoughts', 'parsemag', $start, $end, $total ) .
				'</span>
			</div>';
		}

		/**
		 * Build next/prev navigation
		 */
		$numofpages = $total / $per_page;

		if( $numofpages > 1 ) {
			$output .= '<div class="page-nav">';
			if( $page > 1 ) {
				$output .= '<a href="' . $this->getTitle()->getFullURL( array(
					'user' => $user_name, 'page' => ( $page - 1 ) ) ) . '">' .
					wfMsg( 'userstatus-prev' ) . '</a> ';
			}

			if( ( $total % $per_page ) != 0 ) {
				$numofpages++;
			}
			if( $numofpages >= 9 && $page < $total ) {
				$numofpages = 9 + $page;
				if( $numofpages >= ( $total / $per_page ) ) {
					$numofpages = ( $total / $per_page ) + 1;
				}
			}

			for( $i = 1; $i <= $numofpages; $i++ ) {
				if( $i == $page ) {
					$output .= ( $i . ' ' );
				} else {
					$output .= '<a href="' . $this->getTitle()->getFullURL(
						array( 'user' => $user_name, 'page' => $i ) ) .
						"\">$i</a> ";
				}
			}

			if( ( $total - ( $per_page * $page ) ) > 0 ) {
				$output .= ' <a href="' . $this->getTitle()->getFullURL( array(
					'user' => $user_name, 'page' => ( $page + 1 ) ) ) . '">' .
					wfMsg( 'userstatus-next' ) . '</a>';
			}
			$output .= '</div><p>';
		}

		// Add CSS & JS
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
			$wgOut->addModuleStyles( 'ext.userStatus' );
			$wgOut->addModuleScripts( 'ext.userStatus' );
		} else {
			$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/UserStatus/UserStatus.css' );
			$wgOut->addScriptFile( $wgScriptPath . '/extensions/UserStatus/UserStatus.js' );
		}

		$output .= '<div class="user-status-container">';
		$thought_link = SpecialPage::getTitleFor( 'ViewThought' );
		if( $messages ) {
			foreach ( $messages as $message ) {
				$user = Title::makeTitle( NS_USER, $message['user_name'] );
				$avatar = new wAvatar( $message['user_id'], 'm' );

				$network_link = '<a href="' . SportsTeams::getNetworkURL( $message['sport_id'], $message['team_id'] ) . '">' .
					wfMsg( 'userstatus-all-team-updates', SportsTeams::getNetworkName( $message['sport_id'], $message['team_id'] ) ) .
				'</a>';

				$delete_link = '';
				if( $wgUser->getName() == $message['user_name'] ) {
					$delete_link = "<span class=\"user-board-red\">
						<a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" .
						wfMsg( 'userstatus-delete-thought-text' ) ."</a>
					</span>";
				}

				$message_text = preg_replace_callback(
					'/(<a[^>]*>)(.*?)(<\/a>)/i',
					array( 'UserStatus', 'cutLinkText' ),
					$message['text']
				);
				$vote_count = wfMsgExt( 'userstatus-num-agree', 'parsemag', $message['plus_count'] );

				$vote_link = '';
				if( $wgUser->isLoggedIn() && $wgUser->getName() != $message['user_name'] ) {
					if( !$message['voted'] ) {
						$vote_link = "<a href=\"javascript:void(0);\" onclick=\"vote_status({$message['id']},1)\">[" .
							wfMsg( 'userstatus-_agree' ) . "]</a>";
					} else {
						$vote_link = $vote_count;
					}
				}

				$view_thought_link = '<a href="' . $thought_link->getFullURL( "id={$message['id']}" ) . '">[' .
					wfMsg( 'userstatus-see-who-agrees' ) . ']</a>';

				$output .= '<div class="user-status-row">

					<div class="user-status-logo">

						<a href="' . SportsTeams::getNetworkURL( $message['sport_id'], $message['team_id'] ) . '">' .
							SportsTeams::getLogo( $message['sport_id'], $message['team_id'], 'm' ) .
						"</a>

					</div>

					<div class=\"user-status-message\">

						{$message_text}

						<div class=\"user-status-date\">" . 
							wfMsg( 'userstatus-ago', UserStatus::getTimeAgo( $message['timestamp'] ) ) .
							"<span class=\"user-status-vote\" id=\"user-status-vote-{$message['id']}\">
								{$vote_link}
							</span>
							{$view_thought_link}
							<span class=\"user-status-links\">
								{$delete_link}
							</span>
						</div>

					</div>

					<div class=\"cleared\"></div>

				</div>";
			}
		} else {
			$output .= '<p>' . wfMsg( 'userstatus-no-updates' ) . '</p>';
		}

		$output .= '</div>';

		$wgOut->addHTML( $output );
	}
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgOut, $wgRequest, $wgScriptPath, $wgUploadPath;

		// Variables
		$output = '';
		$direction = $wgRequest->getVal( 'direction' );
		$type = $wgRequest->getVal( 'type' );
		$sport = $wgRequest->getInt( 'sport' );

		// Direction
		if ( $direction == 'worst' ) {
			$order = 'ASC';
			$adj = 'least';
		} else {
			$order = 'DESC';
			$adj = 'most';
		}

		// Type
		if ( $type == 'sport' ) {
			$type_title = 'sports';
		} else {
			$type_title = 'teams';
		}

		// Sport
		$where = array();
		if ( $sport ) {
			$where['team_sport_id'] = $sport;
		}

		// Set the page title
		// For grep: sportsteams-top-network-team-title-least-sports,
		// sportsteams-top-network-team-title-least-teams,
		// sportsteams-top-network-team-title-most-sports,
		// sportsteams-top-network-team-title-most-teams
		$wgOut->setPageTitle( wfMsg( 'sportsteams-top-network-team-title-' . $adj . '-' . $type_title ) );

		// Add CSS
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
			$wgOut->addModuleStyles( 'ext.sportsTeams' );
		} else {
			$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SportsTeams/SportsTeams.css' );
		}

		// Database handler
		$dbr = wfGetDB( DB_MASTER );

		// Teams
		$res = $dbr->select(
			array( 'sport_favorite', 'sport_team' ),
			array(
				'COUNT(sf_team_id) AS network_user_count',
				'sf_team_id', 'team_name', 'team_sport_id'
			),
			$where,
			__METHOD__,
			array(
				'GROUP BY' => 'team_id',
				'ORDER BY' => "network_user_count {$order}",
				'LIMIT' => 50
			),
			array(
				'sport_team' => array( 'INNER JOIN', 'sf_team_id = team_id' )
			)
		);

		// Sports
		$res_sport = $dbr->select(
			array( 'sport_favorite', 'sport' ),
			array(
				'COUNT(sf_sport_id) AS sport_count', 'sf_sport_id',
				'sport_name'
			),
			array(),
			__METHOD__,
			array(
				'GROUP BY' => 'sf_sport_id',
				'ORDER BY' => "sport_count {$order}",
				'LIMIT' => 50
			),
			array( 'sport' => array( 'INNER JOIN', 'sf_sport_id = sport_id' ) )
		);

		// Navigation
		$res_sport_nav = $dbr->select(
			array( 'sport', 'sport_team' ),
			array( 'sport_id', 'sport_name', 'team_sport_id' ),
			array(),
			__METHOD__,
			array(
				'GROUP BY' => 'sport_name',
				'ORDER BY' => 'sport_id'
			),
			array(
				'sport_team' => array( 'INNER JOIN', 'sport_id = team_sport_id' )
			)
		);

		// Navigation
		$output .= '<div class="top-networks-navigation">
			<h1>' . wfMsg( 'sportsteams-top-network-most-popular' ) . '</h1>';

		if ( !( $sport ) && !( $type ) && !( $direction ) ) {
			$output .= '<p><b>' . wfMsg( 'sportsteams-top-network-teams' ) . '</b></p>';
		} elseif ( !( $sport ) && !( $type ) && ( $direction == 'best' ) ) {
			$output .= '<p><b>' . wfMsg( 'sportsteams-top-network-teams' ) . '</b></p>';
		} else {
			$output .= '<p><a href="' . $this->getTitle()->escapeFullURL(
				array( 'direction' => 'best' )
			) . '">' . wfMsg( 'sportsteams-top-network-teams' ) . '</a></p>';
		}

		if ( !( $sport ) && ( $type == 'sport' ) && ( $direction == 'best' ) ) {
			$output .= '<p><b>' . wfMsg( 'sportsteams-top-network-sports' ) . '</b></p>';
		} else {
			$output .= '<p><a href="' . $this->getTitle()->escapeFullURL(
				array( 'type' => 'sport', 'direction' => 'best' )
			) . '">' . wfMsg( 'sportsteams-top-network-sports' ) . '</a></p>';
		}

		$output .= '<h1 style="margin-top:15px !important;">' .
			wfMsg( 'sportsteams-top-network-least-popular' ) . '</h1>';

		if ( !( $sport ) && !( $type ) && ( $direction == 'worst' ) ) {
			$output .= '<p><b>' . wfMsg( 'sportsteams-top-network-teams' ) . '</b></p>';
		} else {
			$output .= '<p><a href="' . $this->getTitle()->escapeFullURL(
				array( 'direction' => 'worst' )
			) . '">' . wfMsg( 'sportsteams-top-network-teams' ) . '</a></p>';
		}

		if ( !( $sport ) && ( $type == 'sport' ) && ( $direction == 'worst' ) ) {
			$output .= '<p><b>' . wfMsg( 'sportsteams-top-network-sports' ) . '</b></p>';
		} else {
			$output .= '<p><a href="' . $this->getTitle()->escapeFullURL(
				array( 'type' => 'sport', 'direction' => 'worst' )
			) . '">' . wfMsg( 'sportsteams-top-network-sports' ) . "</a></p>";
		}

		// for grep: sportsteams-top-network-most-pop-by-sport,
		// sportsteams-top-network-least-pop-by-sport
		$output .= '<h1 style="margin-top:15px !important;">' .
			wfMsg( 'sportsteams-top-network-' . strtolower( $adj ) . '-pop-by-sport' ) . '</h1>';

		foreach ( $res_sport_nav as $row_sport_nav ) {
			$sport_id = $row_sport_nav->sport_id;
			$sport_name = $row_sport_nav->sport_name;

			if ( $sport_id == $sport ) {
				$output .= "<p><b>{$sport_name}</b></p>";
				// For grep: sportsteams-top-network-least-team-title,
				// sportsteams-top-network-most-team-title
				$wgOut->setPageTitle(
					wfMsg( 'sportsteams-top-network-' . strtolower( $adj ) . '-team-title',
						$sport_name )
				);
			} else {
				$output .= '<p><a href="' . $this->getTitle()->escapeFullURL(
					array( 'direction' => $direction, 'sport' => $sport_id )
				) . '">' . $sport_name . '</a></p>';
			}
		}

		$output .= '</div>';

		// List Networks
		$output .= '<div class="top-networks">';

		// Set counter
		$x = 1;

		if ( $type == 'sport' ) {
			$fanHome = SpecialPage::getTitleFor( 'FanHome' );
			foreach ( $res_sport as $row_sport ) {
				// More variables
				$user_count = $row_sport->sport_count;
				$sport = $row_sport->sport_name;
				$sport_id = $row_sport->sf_sport_id;

				// Get team logo
				$sport_image = '<img src="' . $wgUploadPath . '/sport_logos/' .
					SportsTeams::getSportLogo( $sport_id, 's' ) .
					'" border="0" alt="logo" />';

				$output .= "<div class=\"network-row\">
					<span class=\"network-number\">{$x}.</span>
					<span class=\"network-team\">
						{$sport_image}
						<a href=\"" . $fanHome->escapeFullURL( array( 'sport_id' => $sport_id ) ) . "\">{$sport}</a>
					</span>
					<span class=\"network-count\">" .
						wfMsgExt(
							'sportsteams-count-fans',
							array( 'parse', 'parsemag' ),
							$user_count
						) .
					'</span>
					<div class="cleared"></div>
				</div>';
				$x++;
			}
		} else {
			foreach ( $res as $row ) {
				// More variables
				$user_count = $row->network_user_count;
				$team = $row->team_name;
				$team_id = $row->sf_team_id;
				$sport_id = $row->team_sport_id;

				// Get team logo
				$team_image = '<img src="' . $wgUploadPath . '/team_logos/' .
					SportsTeams::getTeamLogo( $team_id, 's' ) .
					'" border="0" alt="logo" />';

				$fanHome = SpecialPage::getTitleFor( 'FanHome' );
				$output .= "<div class=\"network-row\">
					<span class=\"network-number\">{$x}.</span>
					<span class=\"network-team\">
						{$team_image}
						<a href=\"" . $fanHome->escapeFullURL( array(
							'sport_id' => $sport_id,
							'team_id' => $team_id
						) ) . "\">{$team}</a>
					</span>
					<span class=\"network-count\">" .
						wfMsgExt(
							'sportsteams-count-fans',
							array( 'parsemag', 'parse' ),
							$user_count
						) .
					'</span>
					<div class="cleared"></div>
				</div>';
				$x++;
			}
		}

		$output .= '</div>
		<div class="cleared"></div>';

		$wgOut->addHTML( $output );
	}
	function getFans() {
		global $wgRequest, $wgLang;

		$sport_id = $wgRequest->getInt( 'sport_id' );
		$team_id = $wgRequest->getInt( 'team_id' );

		$output = '<div class="fans">';
		$fans = SportsTeams::getUsersByFavorite( $sport_id, $team_id, 7, 0 );
		foreach( $fans as $fan ) {
			$user = Title::makeTitle( NS_USER, $fan['user_name'] );
			$avatar = new wAvatar( $fan['user_id'], 'l' );

			$fan_name = $wgLang->truncate( $fan['user_name'], 12 );

			$output .= "<p class=\"fan\">
				<a href=\"{$user->getFullURL()}\">{$avatar->getAvatarURL()}</a><br>
				<a href=\"{$user->getFullURL()}\">{$fan_name}</a>
			</p>";
		}

		$output .= '<div class="cleared"></div></div>';

		return $output;
	}
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgRequest, $wgOut, $wgUser, $wgScriptPath;

		$messages_show = 25;
		$updates_show = 25; // just an arbitrary value to stop PHP from complaining on 12 August 2011 --ashley
		$output = '';
		$sport_id = $wgRequest->getInt( 'sport_id' );
		$team_id = $wgRequest->getInt( 'team_id' );
		$page = $wgRequest->getInt( 'page', 1 );

		if ( $team_id ) {
			$team = SportsTeams::getTeam( $team_id );
			$network_name = $team['name'];
		} elseif ( $sport_id ) {
			$sport = SportsTeams::getSport( $sport_id );
			$network_name = $sport['name'];
		} else {
			// No sports ID nor team ID...bail out or we'll get a database
			// error...
			$wgOut->setPageTitle( wfMsg( 'userstatus-woops' ) );
			$out = '<div class="relationship-request-message">' .
				wfMsg( 'userstatus-invalid-link' ) . '</div>';
			$out .= '<div class="relationship-request-buttons">';
			$out .= '<input type="button" class="site-button" value="' .
				wfMsg( 'mainpage' ) .
				"\" onclick=\"window.location='" .
				Title::newMainPage()->escapeFullURL() . "'\"/>";
			/* removed because I was too lazy to port the error message over :P
			if ( $wgUser->isLoggedIn() ) {
				$out .= ' <input type="button" class="site-button" value="' .
					wfMsg( 'st_network_your_profile' ) .
					"\" onclick=\"window.location='" .
					Title::makeTitle( NS_USER, $wgUser->getName() )->escapeFullURL() . "'\"/>";
			}
			*/
			$out .= '</div>';
			$wgOut->addHTML( $out );
			return true;
		}

		$wgOut->setPageTitle( wfMsg( 'userstatus-network-thoughts', $network_name ) );

		/**
		 * Config for the page
		 */
		$per_page = $messages_show;

		$s = new UserStatus();
		$total = $s->getNetworkUpdatesCount( $sport_id, $team_id );
		$messages = $s->getStatusMessages(
			0,
			$sport_id,
			$team_id,
			$messages_show,
			$page
		);

		$output .= '<div class="gift-links">';
		$output .= '<a href="' .
			SportsTeams::getNetworkURL( $sport_id, $team_id ) . '">' .
				wfMsg( 'userstatus-back-to-network' ) . '</a>';
		$output .= '</div>';

		if( $page == 1 ) {
			$start = 1;
		} else {
			$start = ( $page - 1 ) * $per_page + 1;
		}
		$end = $start + ( count( $messages ) ) - 1;

		if( $total ) {
			$output .= '<div class="user-page-message-top">
			<span class="user-page-message-count" style="font-size: 11px; color: #666666;">' .
				wfMsgExt( 'userstatus-showing-thoughts', 'parsemag', $start, $end, $total ) .
			'</span>
		</div>';
		}

		/**
		 * Build next/prev navigation
		 */
		$numofpages = $total / $per_page;

		if( $numofpages > 1 ) {
			$output .= '<div class="page-nav">';
			if( $page > 1 ) {
				$output .= '<a href="' .
					SportsTeams::getFanUpdatesURL( $sport_id, $team_id ) .
					'&page=' . ( $page - 1 ) . '">' . wfMsg( 'userstatus-prev' ) .
					'</a> ';
			}

			if( ( $total % $per_page ) != 0 ) {
				$numofpages++;
			}
			if( $numofpages >= 9 && $page < $total ) {
				$numofpages = 9 + $page;
				if( $numofpages >= ( $total / $per_page ) ) {
					$numofpages = ( $total / $per_page ) + 1;
				}
			}

			for( $i = 1; $i <= $numofpages; $i++ ) {
				if( $i == $page ) {
					$output .= ( $i . ' ');
				} else {
					$output .= '<a href="' .
						SportsTeams::getFanUpdatesURL( $sport_id, $team_id ) .
						"&page=$i\">$i</a> ";
				}
			}

			if( ( $total - ( $per_page * $page ) ) > 0 ) {
				$output .= ' <a href="' .
					SportsTeams::getFanUpdatesURL( $sport_id, $team_id ) .
					'&page=' . ( $page + 1 ) . '">' . wfMsg( 'userstatus-next' ) .
					'</a>';
			}
			$output .= '</div><p>';
		}

		// Add CSS & JS
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
			$wgOut->addModuleStyles( 'ext.userStatus' );
			$wgOut->addModuleScripts( 'ext.userStatus' );
		} else {
			$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/UserStatus/UserStatus.css' );
			$wgOut->addScriptFile( $wgScriptPath . '/extensions/UserStatus/UserStatus.js' );
		}

		// Registered users who are not blocked can add status updates when the
		// database is not locked
		if( $wgUser->isLoggedIn() && !$wgUser->isBlocked() && !wfReadOnly() ) {
			$output .= "<script>
				var __sport_id__ = {$sport_id};
				var __team_id__ = {$team_id};
				var __updates_show__ = \"{$updates_show}\";
				var __redirect_url__ = \"" . str_replace( '&amp;', '&', SportsTeams::getFanUpdatesURL( $sport_id, $team_id ) ) . "\";
			</script>";

			$output .= "<div class=\"user-status-form\">
			<span class=\"user-name-top\">{$wgUser->getName()}</span> <input type=\"text\" name=\"user_status_text\" id=\"user_status_text\" size=\"40\"/>
			<input type=\"button\" value=\"" . wfMsg( 'userstatus-btn-add' ) . '" class="site-button" onclick="add_status()" />
			</div>';
		}

		$output .= '<div class="user-status-container">';
		if( $messages ) {
			foreach ( $messages as $message ) {
				$user = Title::makeTitle( NS_USER, $message['user_name'] );
				$avatar = new wAvatar( $message['user_id'], 'm' );

				$messages_link = '<a href="' .
					UserStatus::getUserUpdatesURL( $message['user_name'] ) . '">' .
					wfMsg( 'userstatus-view-all-updates', $message['user_name'] ) .
					'</a>';
				$delete_link = '';
				// Allow the owner of the status update and privileged users to
				// delete it
				if(
					$wgUser->getName() == $message['user_name'] ||
					$wgUser->isAllowed( 'delete-status-updates' )
				)
				{
					$delete_link = "<span class=\"user-board-red\">
							<a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$message['id']})\">" .
						wfMsg( 'userstatus-delete' ) . '</a>
					</span>';
				}

				$message_text = preg_replace_callback(
					'/(<a[^>]*>)(.*?)(<\/a>)/i',
					array( 'UserStatus', 'cutLinkText' ),
					$message['text']
				);

				$output .= "<div class=\"user-status-row\">
					<a href=\"{$user->getFullURL()}\">{$avatar->getAvatarURL()}</a>
					<a href=\"{$user->getFullURL()}\"><b>{$message['user_name']}</b></a> {$message_text}
					<span class=\"user-status-date\">" .
						wfMsg( 'userstatus-ago', UserStatus::getTimeAgo( $message['timestamp'] ) ) .
					'</span>
				</div>';
			}
		} else {
			$output .= '<p>' . wfMsg( 'userstatus-no-updates' ) . '</p>';
		}

		$output .= '</div>';

		$wgOut->addHTML( $output );
	}
	/**
	 * Show the special page
	 *
	 * @param $par Mixed: parameter passed to the special page or null
	 */
	public function execute( $par ) {
		global $wgUser, $wgOut, $wgRequest, $wgLang, $wgScriptPath;

		/**
		 * Redirect non-logged in users to Login Page
		 * It will automatically return them to the SimilarFans page
		 */
		if( $wgUser->getID() == 0 ) {
			$wgOut->setPageTitle( wfMsg( 'sportsteams-woops' ) );
			$login = SpecialPage::getTitleFor( 'Userlogin' );
			$wgOut->redirect( $login->getFullURL( 'returnto=Special:SimilarFans' ) );
			return false;
		}

		// Add CSS
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
			$wgOut->addModuleStyles( 'ext.sportsTeams' );
		} else {
			$wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SportsTeams/SportsTeams.css' );
		}

		$output = '';

		/**
		 * Get query string variables
		 */
		$page = $wgRequest->getInt( 'page', 1 );

		if( $wgUser->isLoggedIn() ) {
			$friends = $this->getRelationships( 1 );
			$foes = $this->getRelationships( 2 );
			$relationships = array_merge( $friends, $foes );
		}

		/**
		 * Set up config for page / default values
		 */
		$per_page = 50;
		$per_row = 2;

		$total = SportsTeams::getSimilarUserCount( $wgUser->getID() );

		/* Get all fans */
		$fans = SportsTeams::getSimilarUsers( $wgUser->getID(), $per_page, $page );

		$wgOut->setPageTitle( wfMsg( 'sportsteams-similar-fans' ) );

		//$output .= '<div class="friend-links">';
		//$output .= "<a href=\"{$homepage_title->getFullURL()}&sport_id={$sport_id}&team_id={$team_id}\">< Back to Network Home</a>";
		//$output .= '</div>';

		/* Show total fan count */
		$output .= '<div class="relationship-count">' .
			wfMsgExt( 'sportsteams-num-similar', 'parsemag', $total ) .
			' <a href="' . SpecialPage::getTitleFor( 'InviteContacts' )->escapeFullURL() . '">' .
				wfMsg( 'sportsteams-invite-friends' ) . '</a>.';
		$output .= '</div>';

		if( $fans ) {
			$x = 1;

			foreach ( $fans as $fan ) {
				$user_name_display = $wgLang->truncate( $fan['user_name'], 30 );

				$user = Title::makeTitle( NS_USER, $fan['user_name'] );
				$avatar = new wAvatar( $fan['user_id'], 'ml' );
				$avatar_img = $avatar->getAvatarURL();

				$output .= "<div class=\"relationship-item\">
							<div class=\"relationship-image\"><a href=\"{$user->getFullURL()}\">{$avatar_img}</a></div>
							<div class=\"relationship-info\">
								<div class=\"relationship-name\"><a href=\"{$user->getFullURL()}\">{$user_name_display}</a>";

				$output .= '</div>
					<div class="relationship-actions">';
				$rr = SpecialPage::getTitleFor( 'RemoveRelationship' );
				$ar = SpecialPage::getTitleFor( 'AddRelationship' );
				if( in_array( $fan['user_id'], $friends ) ) {
					$output .= ' <a href="' . $rr->escapeFullURL( "user={$user->getText()}" ) . '">' .
						wfMsg( 'sportsteams-remove-as-friend' ) . '</a> | ';
				}
				if( in_array( $fan['user_id'], $foes ) ) {
					$output .= ' <a href="' . $rr->escapeFullURL( "user={$user->getText()}" ) . '">' .
						wfMsg( 'sportsteams-remove-as-foe' ) . '</a> | ';
				}
				if( $fan['user_name'] != $wgUser->getName() ) {
					if( !in_array( $fan['user_id'], $relationships ) ) {
						$output .= '<a href="' . $ar->escapeFullURL( "user={$fan['user_name']}&rel_type=1" ) . '">' .
							wfMsg( 'sportsteams-add-as-friend' ) . '</a> | ';
						$output .= '<a href="' . $ar->escapeFullURL( "user={$fan['user_name']}&rel_type=2" ) . '">' .
							wfMsg( 'sportsteams-add-as-foe' ) . '</a> | ';
					}
					$output .= '<a href="' . SpecialPage::getTitleFor( 'GiveGift' )->escapeFullURL( "user={$fan['user_name']}" ) . '">' .
						wfMsg( 'sportsteams-give-a-gift' ) . '</a> ';
					//$output .= "<p class=\"relationship-link\"><a href=\"index.php?title=Special:ChallengeUser&user={$fan['user_name']}\"><img src=\"images/common/challengeIcon.png\" border=\"0\" alt=\"issue challenge\"/> issue challenge</a></p>";
					$output .= '<div class="cleared"></div>';
				}
				$output .= '</div>';

				$output .= '<div class="cleared"></div></div>';

				$output .= '</div>';

				if( $x == count( $fans ) || $x != 1 && $x % $per_row == 0 ) {
					$output .= '<div class="cleared"></div>';
				}

				$x++;
			}
		}

		/**
		 * Build next/prev navigation
		 */
		$numofpages = $total / $per_page;

		if( $numofpages > 1 ) {
			$output .= '<div class="page-nav">';
			if( $page > 1 ) {
				$output .= '<a href="' .
					$this->getTitle()->getFullURL( 'page=' . ( $page - 1 ) ) .
					'">' . wfMsg( 'sportsteams-prev' ) . "</a> ";
			}

			if( ( $total % $per_page ) != 0 ) {
				$numofpages++;
			}
			if( $numofpages >= 9 ) {
				$numofpages = 9 + $page;
			}

			for( $i = 1; $i <= $numofpages; $i++ ) {
				if( $i == $page ) {
					$output .= ( $i . ' ');
				} else {
					$output .= '<a href="' . $this->getTitle()->getFullURL( "page=$i" ) . "\">$i</a> ";
				}
			}

			if( ( $total - ( $per_page * $page ) ) > 0 ) {
				$output .= ' <a href="' . 
					$this->getTitle()->getFullURL( 'page=' . ( $page + 1 ) ) .
					'">' . wfMsg( 'sportsteams-next' ) . '</a>';
			}

			$output .= '</div>';
		}

		$wgOut->addHTML( $output );
	}