/** * 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; }
public function execute() { $params = $this->extractRequestParams(); if (!is_null($params['prop'])) { $this->prop = array_flip($params['prop']); } else { $this->prop = []; } $users = (array) $params['users']; $goodNames = $done = []; $result = $this->getResult(); // Canonicalize user names foreach ($users as $u) { $n = User::getCanonicalName($u); if ($n === false || $n === '') { $vals = ['name' => $u, 'invalid' => true]; $fit = $result->addValue(['query', $this->getModuleName()], null, $vals); if (!$fit) { $this->setContinueEnumParameter('users', implode('|', array_diff($users, $done))); $goodNames = []; break; } $done[] = $u; } else { $goodNames[] = $n; } } $result = $this->getResult(); if (count($goodNames)) { $this->addTables('user'); $this->addFields(User::selectFields()); $this->addWhereFld('user_name', $goodNames); $this->showHiddenUsersAddBlockInfo(isset($this->prop['blockinfo'])); $data = []; $res = $this->select(__METHOD__); $this->resetQueryParams(); // get user groups if needed if (isset($this->prop['groups']) || isset($this->prop['rights'])) { $userGroups = []; $this->addTables('user'); $this->addWhereFld('user_name', $goodNames); $this->addTables('user_groups'); $this->addJoinConds(['user_groups' => ['INNER JOIN', 'ug_user=user_id']]); $this->addFields(['user_name', 'ug_group']); $userGroupsRes = $this->select(__METHOD__); foreach ($userGroupsRes as $row) { $userGroups[$row->user_name][] = $row->ug_group; } } foreach ($res as $row) { // create user object and pass along $userGroups if set // that reduces the number of database queries needed in User dramatically if (!isset($userGroups)) { $user = User::newFromRow($row); } else { if (!isset($userGroups[$row->user_name]) || !is_array($userGroups[$row->user_name])) { $userGroups[$row->user_name] = []; } $user = User::newFromRow($row, ['user_groups' => $userGroups[$row->user_name]]); } $huijiUser = HuijiUser::newFromUser($user); $name = $user->getName(); $data[$name]['userid'] = $user->getId(); $data[$name]['name'] = $name; if (isset($this->prop['editcount'])) { $data[$name]['editcount'] = $user->getEditCount(); } if (isset($this->prop['registration'])) { $data[$name]['registration'] = wfTimestampOrNull(TS_ISO_8601, $user->getRegistration()); } if (isset($this->prop['groups'])) { $data[$name]['groups'] = $user->getEffectiveGroups(); } if (isset($this->prop['implicitgroups'])) { $data[$name]['implicitgroups'] = $user->getAutomaticGroups(); } if (isset($this->prop['rights'])) { $data[$name]['rights'] = $user->getRights(); } if ($row->ipb_deleted) { $data[$name]['hidden'] = true; } if (isset($this->prop['blockinfo']) && !is_null($row->ipb_by_text)) { $data[$name]['blockid'] = (int) $row->ipb_id; $data[$name]['blockedby'] = $row->ipb_by_text; $data[$name]['blockedbyid'] = (int) $row->ipb_by; $data[$name]['blockedtimestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp); $data[$name]['blockreason'] = $row->ipb_reason; $data[$name]['blockexpiry'] = $row->ipb_expiry; } if (isset($this->prop['emailable'])) { $data[$name]['emailable'] = $user->canReceiveEmail(); } if (isset($this->prop['gender'])) { $gender = $user->getOption('gender'); if (strval($gender) === '') { $gender = 'unknown'; } $data[$name]['gender'] = $gender; } if (isset($this->prop['centralids'])) { $data[$name] += ApiQueryUserInfo::getCentralUserInfo($this->getConfig(), $user, $params['attachedwiki']); } if (isset($this->prop['designation'])) { $data[$name]['designation'] = $huijiUser->getDesignation(false, true); } if (isset($this->prop['avatar'])) { $data[$name]['avatar'] = array("l" => $huijiUser->getAvatar('l')->getAvatarUrlPath(), "ml" => $huijiUser->getAvatar('ml')->getAvatarUrlPath(), "m" => $huijiUser->getAvatar('m')->getAvatarUrlPath(), "s" => $huijiUser->getAvatar('s')->getAvatarUrlPath()); } if (isset($this->prop['status'])) { $us = new UserStatus($user); $data[$name]['status'] = $us->getStatus(); } if (isset($this->prop['birthday'])) { $us = new UserStatus($user); $data[$name]['birthday'] = $us->getBirthday(); } if (isset($this->prop['city'])) { $us = new UserStatus($user); $data[$name]['city'] = $us->getCity(); } if (isset($this->prop['province'])) { $us = new UserStatus($user); $data[$name]['province'] = $us->getProvince(); } if (isset($this->prop['followingcount'])) { $data[$name]['followingcount'] = $huijiUser->getFollowingUsersCount(); } if (isset($this->prop['followercount'])) { $data[$name]['followercount'] = $huijiUser->getFollowerCount(); } if (isset($this->prop['followingsitescount'])) { $data[$name]['followingsitescount'] = $huijiUser->getFollowingSitesCount(); } if (isset($this->prop['stats'])) { $data[$name]['stats'] = $huijiUser->getStats(); } if (isset($this->prop['level'])) { $data[$name]['level'] = $huijiUser->getLevel()->getLevelNumber(); } if (isset($this->prop['followingsites'])) { $vals['followingsites'] = $huijiUser->getFollowingSites(true); } if (isset($this->prop['context'])) { if ($this->getUser()->isLoggedIn()) { $data[$name]['context']['followedbyme'] = $huijiUser->isFollowedBy($this->getUser()) ? "true" : "false"; $me = HuijiUser::newFromUser($this->getUser()); $iAmFollowing = $me->getFollowingUsers(); $heIsFollowing = $huijiUser->getFollowingUsers(); $bothfollowing = []; if ($heIsFollowing != null) { foreach ($heIsFollowing as $someUser) { //Php is awesome... if (array_search($someUser['user_name'], array_column($iAmFollowing, 'user_name'))) { $bothfollowing[] = $someUser['user_name']; } } } $data[$name]['context']['bothfollowing'] = $bothfollowing; $data[$name]['context']['alsofollowing'] = UserStatus::getFollowingFollowsUser($huijiUser->getName(), $me->getName()); $data[$name]['context']['followingsites'] = $huijiUser->getFollowingSites(true, $this->getUser()); } else { $data[$name]['context'] = false; } } if (!is_null($params['token'])) { $tokenFunctions = $this->getTokenFunctions(); foreach ($params['token'] as $t) { $val = call_user_func($tokenFunctions[$t], $user); if ($val === false) { $this->setWarning("Action '{$t}' is not allowed for the current user"); } else { $data[$name][$t . 'token'] = $val; } } } } } $context = $this->getContext(); // Second pass: add result data to $retval foreach ($goodNames as $u) { if (!isset($data[$u])) { $data[$u] = ['name' => $u]; $urPage = new UserrightsPage(); $urPage->setContext($context); $iwUser = $urPage->fetchUser($u); if ($iwUser instanceof UserRightsProxy) { $data[$u]['interwiki'] = true; if (!is_null($params['token'])) { $tokenFunctions = $this->getTokenFunctions(); foreach ($params['token'] as $t) { $val = call_user_func($tokenFunctions[$t], $iwUser); if ($val === false) { $this->setWarning("Action '{$t}' is not allowed for the current user"); } else { $data[$u][$t . 'token'] = $val; } } } } else { $data[$u]['missing'] = true; if (isset($this->prop['cancreate']) && !$this->getConfig()->get('DisableAuthManager')) { $status = MediaWiki\Auth\AuthManager::singleton()->canCreateAccount($u); $data[$u]['cancreate'] = $status->isGood(); if (!$status->isGood()) { $data[$u]['cancreateerror'] = $this->getErrorFormatter()->arrayFromStatus($status); } } } } else { if (isset($this->prop['groups']) && isset($data[$u]['groups'])) { ApiResult::setArrayType($data[$u]['groups'], 'array'); ApiResult::setIndexedTagName($data[$u]['groups'], 'g'); } if (isset($this->prop['implicitgroups']) && isset($data[$u]['implicitgroups'])) { ApiResult::setArrayType($data[$u]['implicitgroups'], 'array'); ApiResult::setIndexedTagName($data[$u]['implicitgroups'], 'g'); } if (isset($this->prop['rights']) && isset($data[$u]['rights'])) { ApiResult::setArrayType($data[$u]['rights'], 'array'); ApiResult::setIndexedTagName($data[$u]['rights'], 'r'); } } $fit = $result->addValue(['query', $this->getModuleName()], null, $data[$u]); if (!$fit) { $this->setContinueEnumParameter('users', implode('|', array_diff($users, $done))); break; } $done[] = $u; } $result->addIndexedTagName(['query', $this->getModuleName()], 'user'); }
public function getStatus($status) { return UserStatus::getStatus($status); }
/** * Устанавливает состояния полей из массива * * @param array $resArray */ private function setData($resArray) { $this->name = $resArray["name"]; $this->secondName = $resArray["second_name"]; $this->burthday = $resArray["burthday"]; $this->mail = $resArray["mail"]; $this->photo = $resArray["photo"]; $this->ip = $resArray["ip"]; $this->id = $resArray["id"]; $this->isOnline = $this->isOnline(); $this->location = new UserLocation(array("countryId" => $resArray["country"], "regionId" => $resArray["region"], "cityId" => $resArray["city"]), $this); $arrLoc = $this->location->getLocation(); $this->zodiac = Zodiac::calculateByDate($this->burthday); $this->utc = $resArray["utc_time"]; $status = new UserStatus($this->id); $this->status = $status->getStatus(); if ($this->other) { $this->lastUpdate = $resArray["update_time"]; } }
/** * Query user info based on filters. * * */ protected function getCurrentUserInfo() { $user = $this->getUser(); $huijiUser = HuijiUser::newFromUser($user); $vals = []; $vals['id'] = intval($user->getId()); $vals['name'] = $user->getName(); if ($user->isAnon()) { $vals['anon'] = true; } if (isset($this->prop['blockinfo']) && $user->isBlocked()) { $vals = array_merge($vals, self::getBlockInfo($user->getBlock())); } if (isset($this->prop['hasmsg'])) { $vals['messages'] = $user->getNewtalk(); } if (isset($this->prop['groups'])) { $vals['groups'] = $user->getEffectiveGroups(); ApiResult::setArrayType($vals['groups'], 'array'); // even if empty ApiResult::setIndexedTagName($vals['groups'], 'g'); // even if empty } if (isset($this->prop['implicitgroups'])) { $vals['implicitgroups'] = $user->getAutomaticGroups(); ApiResult::setArrayType($vals['implicitgroups'], 'array'); // even if empty ApiResult::setIndexedTagName($vals['implicitgroups'], 'g'); // even if empty } if (isset($this->prop['rights'])) { // User::getRights() may return duplicate values, strip them $vals['rights'] = array_values(array_unique($user->getRights())); ApiResult::setArrayType($vals['rights'], 'array'); // even if empty ApiResult::setIndexedTagName($vals['rights'], 'r'); // even if empty } if (isset($this->prop['changeablegroups'])) { $vals['changeablegroups'] = $user->changeableGroups(); ApiResult::setIndexedTagName($vals['changeablegroups']['add'], 'g'); ApiResult::setIndexedTagName($vals['changeablegroups']['remove'], 'g'); ApiResult::setIndexedTagName($vals['changeablegroups']['add-self'], 'g'); ApiResult::setIndexedTagName($vals['changeablegroups']['remove-self'], 'g'); } if (isset($this->prop['options'])) { $vals['options'] = $user->getOptions(); $vals['options'][ApiResult::META_BC_BOOLS] = array_keys($vals['options']); } if (isset($this->prop['preferencestoken'])) { $p = $this->getModulePrefix(); $this->setWarning("{$p}prop=preferencestoken has been deprecated. Please use action=query&meta=tokens instead."); } if (isset($this->prop['preferencestoken']) && !$this->lacksSameOriginSecurity() && $user->isAllowed('editmyoptions')) { $vals['preferencestoken'] = $user->getEditToken('', $this->getMain()->getRequest()); } if (isset($this->prop['editcount'])) { // use intval to prevent null if a non-logged-in user calls // api.php?format=jsonfm&action=query&meta=userinfo&uiprop=editcount $vals['editcount'] = intval($user->getEditCount()); } if (isset($this->prop['ratelimits'])) { $vals['ratelimits'] = $this->getRateLimits(); } if (isset($this->prop['realname']) && !in_array('realname', $this->getConfig()->get('HiddenPrefs'))) { $vals['realname'] = $user->getRealName(); } if ($user->isAllowed('viewmyprivateinfo')) { if (isset($this->prop['email'])) { $vals['email'] = $user->getEmail(); $auth = $user->getEmailAuthenticationTimestamp(); if (!is_null($auth)) { $vals['emailauthenticated'] = wfTimestamp(TS_ISO_8601, $auth); } } } if (isset($this->prop['registrationdate'])) { $regDate = $user->getRegistration(); if ($regDate !== false) { $vals['registrationdate'] = wfTimestamp(TS_ISO_8601, $regDate); } } if (isset($this->prop['acceptlang'])) { $langs = $this->getRequest()->getAcceptLang(); $acceptLang = []; foreach ($langs as $lang => $val) { $r = ['q' => $val]; ApiResult::setContentValue($r, 'code', $lang); $acceptLang[] = $r; } ApiResult::setIndexedTagName($acceptLang, 'lang'); $vals['acceptlang'] = $acceptLang; } if (isset($this->prop['unreadcount'])) { $store = MediaWikiServices::getInstance()->getWatchedItemStore(); $unreadNotifications = $store->countUnreadNotifications($user, self::WL_UNREAD_LIMIT); if ($unreadNotifications === true) { $vals['unreadcount'] = self::WL_UNREAD_LIMIT . '+'; } else { $vals['unreadcount'] = $unreadNotifications; } } if (isset($this->prop['centralids'])) { $vals += self::getCentralUserInfo($this->getConfig(), $this->getUser(), $this->params['attachedwiki']); } if (isset($this->prop['designation'])) { $vals['designation'] = $huijiUser->getDesignation(false, true); } if (isset($this->prop['avatar'])) { $vals['avatar'] = array("l" => $huijiUser->getAvatar('l')->getAvatarUrlPath(), "ml" => $huijiUser->getAvatar('ml')->getAvatarUrlPath(), "m" => $huijiUser->getAvatar('m')->getAvatarUrlPath(), "s" => $huijiUser->getAvatar('s')->getAvatarUrlPath()); } if (isset($this->prop['gender'])) { $vals['gender'] = $huijiUser->getOption('gender'); } if (isset($this->prop['status'])) { $us = new UserStatus($user); $vals['status'] = $us->getStatus(); } if (isset($this->prop['birthday'])) { $us = new UserStatus($user); $vals['birthday'] = $us->getBirthday(); } if (isset($this->prop['city'])) { $us = new UserStatus($user); $vals['city'] = $us->getCity(); } if (isset($this->prop['province'])) { $us = new UserStatus($user); $vals['province'] = $us->getProvince(); } if (isset($this->prop['followingcount'])) { $vals['followingcount'] = $huijiUser->getFollowingUsersCount(); } if (isset($this->prop['followercount'])) { $vals['followercount'] = $huijiUser->getFollowerCount(); } if (isset($this->prop['followingsitescount'])) { $vals['followingsitescount'] = $huijiUser->getFollowingSitesCount(); } if (isset($this->prop['stats'])) { $vals['stats'] = $huijiUser->getStats(); } if (isset($this->prop['level'])) { $vals['level'] = $huijiUser->getLevel()->getLevelNumber(); } if (isset($this->prop['followingsites'])) { $vals['followingsites'] = $huijiUser->getFollowingSites(true); } return $vals; }