/** * Get the header for the social profile page, which includes the user's * points and user level (if enabled in the site configuration) and lots * more. * * @param $user_id Integer: user ID * @param $user_name String: user name */ function getProfileTop($user_id, $user_name) { global $wgOut, $wgUser, $wgLang; global $wgUserLevels; $stats = new UserStats($user_id, $user_name); $stats_data = $stats->getUserStats(); $user_level = new UserLevel($stats_data['points']); $level_link = Title::makeTitle(NS_HELP, wfMessage('user-profile-userlevels-link')->inContentLanguage()->text()); $this->initializeProfileData($user_name); $profile_data = $this->profile_data; // Variables and other crap $page_title = $this->getTitle()->getText(); $title_parts = explode('/', $page_title); $user = $title_parts[0]; $id = User::idFromName($user); $user_safe = urlencode($user); // Safe urls $add_relationship = SpecialPage::getTitleFor('AddRelationship'); $remove_relationship = SpecialPage::getTitleFor('RemoveRelationship'); $give_gift = SpecialPage::getTitleFor('GiveGift'); $send_board_blast = SpecialPage::getTitleFor('SendBoardBlast'); $update_profile = SpecialPage::getTitleFor('UpdateProfile'); $watchlist = SpecialPage::getTitleFor('Watchlist'); $contributions = SpecialPage::getTitleFor('Contributions', $user); $send_message = SpecialPage::getTitleFor('UserBoard'); $upload_avatar = SpecialPage::getTitleFor('UploadAvatar'); $user_page = Title::makeTitle(NS_USER, $user); $user_social_profile = Title::makeTitle(NS_USER_PROFILE, $user); $user_wiki = Title::makeTitle(NS_USER_WIKI, $user); $us = new UserStatus($this->user); $city = $us->getCity(); $city = Sanitizer::escapeHtmlAllowEntities($city); $birthday = $us->getBirthday(); $status = $us->getStatus(); $status = Sanitizer::escapeHtmlAllowEntities($status); $gender = $us->getGender(); if ($gender == 'male') { $genderIcon = '♂'; $gendertext = '他'; } elseif ($gender == 'female') { $genderIcon = '♀'; $gendertext = '她'; } else { $genderIcon = '♂/♀'; $gendertext = 'TA'; } if ($this->isOwner()) { $gendertext = '你'; } if ($id != 0) { $relationship = UserRelationship::getUserRelationshipByID($id, $wgUser->getID()); } $avatar = new wAvatar($this->user_id, 'l'); wfDebug('profile type: ' . $profile_data['user_page_type'] . "\n"); $output = ''; //get more $target = SpecialPage::getTitleFor('ShowFollowedSites'); $query = array('user_id' => $wgUser->getId(), 'target_user_id' => $this->user_id); $mailVerify = $wgUser->getEmailAuthenticationTimestamp(); if ($mailVerify == NULL) { $href = "/wiki/Special:ConfirmEmail"; } else { $href = "/wiki/Special:UploadAvatar"; } $output .= '<div id="profile-right" class="col-md-6 col-sm-12 col-xs-12">'; $output .= '<div id="profile-title-container"> <h1 id="profile-title"> <div id="profile-image">' . ($this->isOwner() ? '<div class="profile-image-container crop-headimg" id="crop-avatar"><div class="avatar-view upload-tool" title="上传头像">' . $avatar->getOwnerAvatarURL() . '</div>' . $this->cropModal() . '</div>' : $avatar->getAvatarURL()) . '</div>' . $user_name . '</h1></div>'; $output .= '<div class="modal fade watch-url" tabindex="-1" role="dialog" aria-labelledby="mySmModalLabel" aria-hidden="true"> <div class="modal-dialog modal-sm"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="gridSystemModalLabel">' . $gendertext . '关注的wiki</h4> </div> <div class="modal-body"> <div class="list-group"> </div> ' . Linker::LinkKnown($target, '<i class="fa fa-arrows-alt"></i> 全部', array('type' => 'button', 'class' => 'btn btn-default'), $query) . ' </div> </div> </div> </div>'; // Show the user's level and the amount of points they have if // UserLevels has been configured contributions $notice = SpecialPage::getTitleFor('ViewFollows'); $contributions = SpecialPage::getTitleFor('Contributions'); $output .= '<div> <ul class="user-follow-msg"> <li><h5>编辑</h5>' . Linker::link($contributions, $stats_data['edits'], array(), array('target' => $user, 'contribs' => 'user')) . '</li> <li><h4>|</h4></li> <li><h5>关注</h5>' . Linker::link($notice, UserUserFollow::getFollowingCount(User::newFromName($user)), array('id' => 'user-following-count'), array('user' => $user, 'rel_type' => 1)) . '</li> <li><h4>|</h4></li> <li><h5>被关注</h5>' . Linker::link($notice, UserUserFollow::getFollowerCount(User::newFromName($user)), array('id' => 'user-follower-count'), array('user' => $user, 'rel_type' => 2)) . '</li> </ul> <div class="cleared"></div> </div> <!--<span id="user-site-count">' . '</span>个站点。-->'; if ($wgUserLevels) { $progress = $user_level->getLevelProgress() * 100; $output .= '<div id="honorific-level" class="label"> <a href="' . htmlspecialchars($level_link->getFullURL()) . '" rel="nofollow">' . $user_level->getLevelName() . '</a> </div> <div id="points-level" class="progress"> <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%"> <span class="sr-only">' . wfMessage('user-profile-points', $wgLang->formatNum($stats_data['points']))->escaped() . '</span> </div> </div>'; } $output .= '<div class="profile-actions">'; $output .= '<div class="form-container ' . ($this->isOwner() ? 'owner' : '') . '"><div class="form-msg"><a class="form-location ' . ($this->isOwner() ? 'edit' : '') . '">' . ($city == '' ? $this->isOwner() ? '填写居住地' : '居住地未公开' : $city) . '</a> <span class="span-color">|</span><a class="form-date ' . ($this->isOwner() ? 'edit' : '') . '" data-birthday="' . ($birthday == '' || $birthday == '0000-00-00' ? '' : $birthday) . '">' . ($birthday == '' || $birthday == '0000-00-00' ? $this->isOwner() ? '填写生日' : '生日未公开' : '') . '</a> <span class="span-color">|</span><a class="form-sex ' . ($this->isOwner() ? 'edit' : '') . '" data-sex="' . $gender . '">' . $genderIcon . '</a></div>'; $output .= '<div class="user-autograph"><a class="form-autograph ' . ($this->isOwner() ? 'edit' : '') . '">' . ($status == '' ? $this->isOwner() ? '填写个人状态' : '这个人很懒,什么都没有写...' : $status) . '</a></div></div>'; // Links to User:user_name from User_profile: // if ( $this->getTitle()->getNamespace() == NS_USER_PROFILE && $this->profile_data['user_id'] && $this->profile_data['user_page_type'] == 0 ) { // $output .= '| <a href="' . htmlspecialchars( $user_page->getFullURL() ) . '" rel="nofollow">' . // wfMessage( 'user-page-link' )->escaped() . '</a> '; // } // // Links to User:user_name from User_profile: // if ( $this->getTitle()->getNamespace() == NS_USER && $this->profile_data['user_id'] && $this->profile_data['user_page_type'] == 0 ) { // $output .= '| <a href="' . htmlspecialchars( $user_social_profile->getFullURL() ) . '" rel="nofollow">' . // wfMessage( 'user-social-profile-link' )->escaped() . '</a> '; // } // if ( $this->getTitle()->getNamespace() == NS_USER && ( !$this->profile_data['user_id'] || $this->profile_data['user_page_type'] == 1 ) ) { // $output .= '| <a href="' . htmlspecialchars( $user_wiki->getFullURL() ) . '" rel="nofollow">' . // wfMessage( 'user-wiki-link' )->escaped() . '</a>'; // } $output .= '</div></div>'; return $output; }
/** * Show the special page * * @param $params Mixed: parameter(s) passed to the page or null */ public function execute($params) { global $wgUser; $lang = $this->getLanguage(); $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); // Set the page title, robot policies, etc. $this->setHeaders(); // Add CSS $out->addModuleStyles('ext.socialprofile.useruserfollows.css'); // Add JS $out->addModuleScripts('ext.socialprofile.useruserfollows.js'); $output = ''; /** * Get query string variables */ $user_name = $request->getVal('user'); $rel_type = $request->getInt('rel_type'); $page = $request->getInt('page'); /** * Redirect Non-logged in users to Login Page * It will automatically return them to the ViewRelationships page */ // if ( !$user->isLoggedIn() && $user_name == '' ) { // $out->setPageTitle( $this->msg( 'ur-error-page-title' )->plain() ); // $login = SpecialPage::getTitleFor( 'Userlogin' ); // $out->redirect( htmlspecialchars( $login->getFullURL( 'returnto=Special:ViewFollows' ) ) ); // return false; // } /** * Set up config for page / default values */ if (!$page || !is_numeric($page)) { $page = 1; } if (!$rel_type || !is_numeric($rel_type)) { $rel_type = 2; } $per_page = 10; $per_row = 2; /** * If no user is set in the URL, we assume its the current user */ if (!$user_name) { $user_name = $user->getName(); } $user_id = User::idFromName($user_name); $target_user = User::newFromId($user_id); $userPage = Title::makeTitle(NS_USER, $user_name); /** * Error message for username that does not exist (from URL) */ if ($user_id == 0) { $out->setPageTitle($this->msg('ur-error-title')->plain()); $output = '<div class="relationship-error-message">' . $this->msg('ur-error-message-no-user')->plain() . '</div> <div class="relationship-request-buttons"> <input type="button" class="site-button" value="' . $this->msg('ur-main-page')->plain() . '" onclick=\'window.location="index.php?title=' . $this->msg('mainpage')->inContentLanguage()->escaped() . '"\' />'; if ($user->isLoggedIn()) { $output .= '<input type="button" class="site-button" value="' . $this->msg('ur-your-profile')->plain() . '" onclick=\'window.location="' . htmlspecialchars($user->getUserPage()->getFullURL()) . '"\' />'; } $output .= '</div>'; $out->addHTML($output); return false; } /** * Get all relationships */ $uuf = new UserUserFollow(); $follows = $uuf->getFollowList($target_user, $rel_type, '', $page); $star_page = $per_page * ($page - 1); $per_follow = array_slice($follows, $star_page, $per_page); $followerCount = UserUserFollow::getFollowerCount($target_user); $followingCount = UserUserFollow::getFollowingCount($target_user); $back_link = Title::makeTitle(NS_USER, $user_name); $target = SpecialPage::getTitleFor('ViewFollows'); $query1 = array('user' => $user_name, 'rel_type' => 1); $query2 = array('user' => $user_name, 'rel_type' => 2); $blast = SpecialPage::getTitleFor('SendBoardBlast'); if ($user_name == $wgUser->getName()) { $noticestr = '关注我的人'; $noticedstr = '我关注的人'; } else { $noticestr = '关注' . $user_name . '的人'; $noticedstr = $user_name . '关注的人'; } if ($rel_type == 1) { $out->setPageTitle($this->msg('ur-title-friend', $user_name)->parse()); $total = $followingCount; $target = SpecialPage::getTitleFor('ViewFollows'); $query1 = array('user' => $user_name, 'rel_type' => 1); $query2 = array('user' => $user_name, 'rel_type' => 2); $rem = $this->msg('ur-remove-relationship-friend')->plain(); $output .= '<div class="back-links"> <a href="' . htmlspecialchars($back_link->getFullURL()) . '">' . $this->msg('ur-backlink', $user_name)->parse() . '</a> | ' . Linker::LinkKnown($target, $noticestr, array(), $query2) . ' </div> <div class="relationship-wrapper"><div class="relationship-count">' . $this->msg('ur-relationship-count-friends', $user_name, $total)->text() . '</div><div class="relationship-list">'; } else { $out->setPageTitle($this->msg('ur-title-foe', $user_name)->parse()); $total = $followerCount; $rem = $this->msg('ur-remove-relationship-foe')->plain(); $output .= '<div class="back-links"> <a href="' . htmlspecialchars($back_link->getFullURL()) . '">' . $this->msg('ur-backlink', $user_name)->parse() . '</a> | ' . Linker::LinkKnown($target, $noticedstr, array(), $query1); if ($user_name == $wgUser->getName()) { $output .= '| ' . Linker::LinkKnown($blast, '向关注我的人群发信息'); } $output .= '</div> <div class="relationship-wrapper"><div class="relationship-count">' . $this->msg('ur-relationship-count-foes', $user_name, $total)->text() . '</div><div class="relationship-list">'; } if ($per_follow) { $x = 1; foreach ($per_follow as $follow) { // $indivRelationship = UserRelationship::getUserRelationshipByID( // $relationship['user_id'], // $user->getID() // ); $username = $follow['user_name']; $userobj = User::newFromName($username); $ust = new UserStatus($userobj); $allinfo = $ust->getUserAllInfo(); // Safe titles $userPage = Title::makeTitle(NS_USER, $allinfo['username']); // $indivFollow = $uuf->checkUserUserFollow($user, User::newFromId($follow['user_id'])); $is_follow = $allinfo['is_follow']; if ($is_follow == 'Y') { $followButton = '<li class="user-user-follow unfollow" data-username="******"><a><i class="fa fa-minus-square-o"></i>取关</a></li> '; } else { $followButton = '<li class="user-user-follow" data-username="******"><i class="fa fa-plus-square-o"></i></i>关注</li> '; } $userPageURL = htmlspecialchars($userPage->getFullURL()); // $avatar = new wAvatar( $follow['user_id'], 'ml' ); // $avatar_img = $avatar->getAvatarURL(); $avatar_img = $allinfo['url']; $user_gender = $allinfo['gender']; $user_status = $allinfo['status']; $user_count = $allinfo['usercounts']; $user_counted = $allinfo['usercounted']; $editcount = $allinfo['editcount']; // $commonfollow = $allinfo['commonfollow']; // $minefollowerhim = $allinfo['minefollowerhim']; $user_level = $allinfo['level']; $username_length = strlen($allinfo['username']); $username_space = stripos($allinfo['username'], ' '); if (($username_space == false || $username_space >= "30") && $username_length > 30) { $user_name_display = substr($allinfo['username'], 0, 30) . ' ' . substr($allinfo['username'], 30, 50); } else { $user_name_display = $allinfo['username']; } if ($user_gender == 'male') { $genderIcon = '♂'; } elseif ($user_gender == 'female') { $genderIcon = '♀'; } else { $genderIcon = '♂/♀'; } $output .= "<div class=\"relationship-item\">\r\n\t\t\t\t\t<a href=\"{$userPageURL}\" data-name=\"{$user_name_display}\">{$avatar_img}</a>\r\n\t\t\t\t\t<div class=\"relationship-info\">\r\n\t\t\t\t\t\t<div class=\"relationship-name\">\r\n\t\t\t\t\t\t\t<a href=\"{$userPageURL}\">{$user_name_display}</a><i>{$genderIcon}</i><i>{$user_level}</i>\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t<div class=\"relationship-actions\">"; if (empty($user_status)) { $output .= '<div>这个人很懒</div>'; } else { $output .= '<div>' . $user_status . '</div>'; } $output .= '<div>关注数:' . $user_count . ' | 被关注:' . $user_counted . ' | 编辑:' . $editcount . '</div>'; if ($allinfo['username'] != $wgUser->getName()) { $output .= '<ul class="relationship-list-btn">' . $followButton; } else { $output .= '<ul class="relationship-list-btn">'; } $target = SpecialPage::getTitleFor('GiveGift'); $query = array('user' => $follow['user_name']); $output .= '<li>' . Linker::LinkKnown($target, '<i class="fa fa-gift"></i>礼物</a>', array(), $query) . '</li> </ul>'; $output .= '</div> <div class="cleared"></div> </div>'; $output .= '</div>'; if ($x == count($follows) || $x != 1 && $x % $per_row == 0) { $output .= '<div class="cleared"></div>'; } $x++; } } /** * Build next/prev nav */ $total = intval(str_replace(',', '', $total)); $numofpages = $total / $per_page; $pageLink = $this->getPageTitle(); if ($numofpages > 1) { $output .= '<nav class="page-nav pagination">'; if ($page > 1) { $output .= '<li>' . Linker::link($pageLink, '<span aria-hidden="true">«</span>', array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $page - 1)) . '</li>'; } 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 .= '<li class="active"><a href="#">' . $i . ' <span class="sr-only">(current)</span></a></li>'; } else { $output .= '<li>' . Linker::link($pageLink, $i, array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $i)) . '</li>'; } } if ($total - $per_page * $page > 0) { $output .= '<li>' . Linker::link($pageLink, '<span aria-hidden="true">»</span>', array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $page + 1)) . '</li>'; } $output .= '</nav></div></div></div></div>'; } $out->addHTML($output); }