/** * 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 ); }