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;
	}
	/**
	 * 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 );
	}
	static function getNetworkName( $sport_id, $team_id ) {
		if( $team_id ) {
			$network = SportsTeams::getTeam( $team_id );
		} else {
			$network = SportsTeams::getSport( $sport_id );
		}

		return $network['name'];
	}
Exemplo n.º 5
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 $wgUser, $wgOut, $wgRequest, $wgScriptPath, $wgSportsTeamsGoogleAPIKey;

		if ( $wgUser->isLoggedIn() ) {
			$this->friends = $this->getRelationships( 1 );
			$this->foes = $this->getRelationships( 2 );
			$this->relationships = array_merge( $this->friends, $this->foes );
		} else {
			// Prevent fatals (+1 notice) for anonymous users
			$this->friends = $this->foes = $this->relationships =
				$fan_info = '';
		}

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

		// If there's neither a sports ID nor a team ID, show an error message.
		// @todo FIXME: I don't like this; we should be showing a listing of
		// all networks or something instead of basically telling the user to
		// go away.
		if( !$sport_id && !$team_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 true;
		}

		$this->network_count = SportsTeams::getUserCount( $sport_id, $team_id );
		$this->friends_network_count = SportsTeams::getFriendsCountInFavorite(
			$wgUser->getId(),
			$sport_id,
			$team_id
		);

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

		$team_image = SportsTeams::getLogo( $sport_id, $team_id, 'l' );

		$homepage_title = Title::makeTitle( NS_MAIN, $this->network );
		$view_fans_title = SpecialPage::getTitleFor( 'ViewFans' );
		$join_fans_title = SpecialPage::getTitleFor( 'AddFan' );
		$leave_fans_title = SpecialPage::getTitleFor( 'RemoveFan' );

		// Set the page title
		$wgOut->setPageTitle( wfMsg( 'sportsteams-network-fan-network', $this->network ) );

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

		// Ashish Datta
		// Add the script for the maps and set the onload() handler
		// DONT FORGET TO CHANGE KEY WHEN YOU CHANGE DOMAINS
		// @note As of 12 August 2011, http://code.google.com/apis/maps/documentation/javascript/v2/
		// states that the version 2 of Google Maps API has been deprecated
		$wgOut->addScript( "<script src=\"http://maps.google.com/maps?file=api&amp;v=2.x&amp;key={$wgSportsTeamsGoogleAPIKey}\" type=\"text/javascript\"></script>" );
		$wgOut->addScript( $this->getMap() );
		// this originally used setOnloadHandler; addOnloadHook() won't work
		$wgOut->addScript( '<script>jQuery( document ).ready( function() { loadMap(); } );</script>' );

		if( SportsTeams::isFan( $wgUser->getID(), $sport_id, $team_id ) ) {
			$fan_info = '<p><span class="profile-on">' .
				wfMsg( 'sportsteams-network-you-are-fan' ) . '</span></p>';
			$fan_info .= '<p><span><a href="' . $leave_fans_title->getFullURL(
				"sport_id={$sport_id}&team_id={$team_id}"
			) . '" style="text-decoration:none;">' .
				wfMsg( 'sportsteams-network-leave-network' ) .
			'</a></span></p>';
		} elseif ( $wgUser->isLoggedIn() ) {
			$fan_info = '<p><span class="profile-on"><a href="' .
				$join_fans_title->getFullURL(
					"sport_id={$sport_id}&team_id={$team_id}"
				) . '" style="text-decoration: none;">' .
				wfMsg( 'sportsteams-network-join-network' ) . '</a></span></p>';
		}

		$output = '';

		$output .= '<div class="fan-top">';

		$output .= '<div class="fan-top-left">';
		$output .= '<h1>' . wfMsg( 'sportsteams-network-info' ) . '</h1>';
		$output .= '<div class="network-info-left">';
		$output .= $team_image;
		$output .= '<p>' . wfMsg( 'sportsteams-network-logo' ) . '</p>';
		$output .= '</div>';
		$output .= '<div class="network-info-right">';
		$output .= '<p>' . wfMsg( 'sportsteams-network-fans-col' ) . ' <a href="' .
			$view_fans_title->getFullURL(
				array(
					'sport_id' => $sport_id,
					'team_id' => $team_id
				)
			) . "\">{$this->network_count}</a></p>";
		if( $wgUser->isLoggedIn() ) {
			$output .= '<p>' . wfMsg( 'sportsteams-network-friends-col' ) ." {$this->friends_network_count}</p>";
		}
		$output .= $fan_info;
		$output .= '</div>';
		$output .= '<div class="cleared"></div>';
		$output .= '</div>';
		$this_count = count( SportsTeams::getUsersByFavorite( $sport_id, $team_id, 7, 0 ) );
		$output .= '<div class="fan-top-right">';
		$output .= '<h1>' . wfMsg( 'sportsteams-network-fans', $this->network ) . '</h1>';
		$output .= '<p style="margin:-8px 0px 0px 0px; color:#797979;">' .
			wfMsgExt(
				'sportsteams-network-fan-display',
				'parsemag',
				$this_count,
				$view_fans_title->getFullURL( array(
					'sport_id' => $sport_id, 'team_id' => $team_id
				) ),
				$this->network_count
			) . '</p>';
		$output .= $this->getFans();
		$output .= '</div>';

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

		$output .= '<div class="fan-left">';

		// Latest Network User Updates
		$updates_show = 25;
		$s = new UserStatus();
		$output .= '<div class="network-updates">';
		$output .= '<h1 class="network-page-title">' .
			wfMsg( 'sportsteams-network-latest-thoughts' ) . '</h1>';
		$output .= '<div style="margin-bottom:10px;">
			<a href="' . SportsTeams::getFanUpdatesURL( $sport_id, $team_id ) . '">' .
				wfMsg( 'sportsteams-network-all-thoughts' ) . '</a>
		</div>';
		// Registered users (whether they're members of the network or not) can
		// post new status updates on the network's page from the network's
		// page
		if( $wgUser->isLoggedIn() ) {
			$output .= "\n<script type=\"text/javascript\">
				var __sport_id__ = {$sport_id};
				var __team_id__ = {$team_id};
				var __updates_show__ = {$updates_show};
				var __user_status_link__ = '" . SpecialPage::getTitleFor( 'UserStatus' )->getFullURL() . "';</script>\n";
			$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\" onkeypress=\"detEnter(event)\" maxlength=\"150\" />
				<input type=\"button\" value=\"" . wfMsg( 'sportsteams-add-button' ) . '" class="site-button" onclick="add_status()" />
			</div>';
		}
		$output .= '<div id="network-updates">';
		$output .= $s->displayStatusMessages(
			0, $sport_id, $team_id, $updates_show, 1/*$page*/
		);
		$output .= '</div>';

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

		$output .= '<div class="fan-right">';

		// Network location map
		$output .= '<div class="fan-map">';
		$output .= '<h1 class="network-page-title">' .
			wfMsg( 'sportsteams-network-fan-locations' ) . '</h1>';
		$output .= '<div class="gMap" id="gMap"></div>
			<div class="gMapInfo" id="gMapInfo"></div>';
		$output .= '</div>';

		// Top network fans
		$output .= '<div class="top-fans">';
		$output .= '<h1 class="network-page-title">' .
			wfMsg( 'sportsteams-network-top-fans' ) . '</h1>';
		$tfr = SpecialPage::getTitleFor( 'TopUsersRecent' );
		$output .= "<p class=\"fan-network-sub-text\">
				<a href=\"" . $tfr->escapeFullURL( 'period=weekly' ) . '">' .
					wfMsg( 'sportsteams-network-top-fans-week' ) .
				"</a> -
				<a href=\"{$view_fans_title->getFullURL( array( 'sport_id' => $sport_id, 'team_id' => $team_id ))}\">" .
					wfMsg( 'sportsteams-network-complete-list' ) . '</a>
			</p>';
		$output .= $this->getTopFans();
		$output .= '</div>';

		$output .= '<div class="network-articles">';
		$output .= '<h1 class="network-page-title">' .
			wfMsg( 'sportsteams-network-articles', $this->network ) . '</h1>';
		$output .= '<p class="fan-network-sub-text">';
		if ( class_exists( 'BlogPage' ) ) { // @todo CHECKME: is there any point in this check?
			$createBlogPage = SpecialPage::getTitleFor( 'CreateBlogPage' );
			$output .= '<a href="' . $createBlogPage->escapeFullURL() . '">' .
				wfMsg( 'sportsteams-network-write-article' ) . '</a> - ';
		}
		$output .= "<a href=\"{$homepage_title->getFullURL()}\">" . wfMsg( 'sportsteams-network-main-page' ) . '</a>
			</p>';
		$output .= $this->getArticles();
		$output .= '</div>';

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

		$wgOut->addHTML( $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 );
	}
	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 );
	}