/** * 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, $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&v=2.x&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 ); }