/** * Show the special page * * @param $params Mixed: parameter(s) passed to the page or null */ public function execute($params) { global $wgUser, $wgSitename, $wgHuijiPrefix, $wgUserLevels; $out = $this->getOutput(); $this->setHeaders(); $out->addHtml(TopUsersPoints::getRankingDropdown('站点排行榜')); $output = '<i>' . $this->msg('editranknote')->plain() . '</i>'; // Add CSS $out->addModuleStyles('ext.socialprofile.userstats.css'); $yesterday = date('Y-m-d', strtotime('-1 days')); $beforeyesterday = date('Y-m-d', strtotime('-2 days')); $allSiteRank = AllSitesInfo::getAllSitesRankData('', $yesterday); $beforeallSiteRank = AllSitesInfo::getAllSitesRankData('', $beforeyesterday); $beforeArr = array(); foreach ($beforeallSiteRank as $value) { $beforeArr[$value['site_prefix']] = $value['site_rank']; } $output .= '<div class="top-users">'; $total = count($allSiteRank); if ($total > 50) { $allSiteRank = array_slice($allSiteRank, 0, 50); } elseif ($total == 0) { $output .= '<p>站点排行榜正在生成中...请刷新重试!</p>'; $output .= '</div><div class="cleared"></div>'; $out->addHTML($output); return; } foreach ($allSiteRank as $key => $value) { $diff = abs($value['site_rank'] - $beforeArr[$value['site_prefix']]); if ($diff == 0) { $diff = ''; } if ($value['site_rank'] > $beforeArr[$value['site_prefix']]) { $change = 'glyphicon glyphicon-arrow-down red'; } elseif ($value['site_rank'] < $beforeArr[$value['site_prefix']]) { $change = 'glyphicon glyphicon-arrow-up green'; } else { $change = 'glyphicon glyphicon-minus'; } $output .= "<div class=\"top-fan-row\">\r\n\t\t\t\t<span class=\"top-fan-num\">{$value['site_rank']}.</span>\r\n\t\t\t\t<span class=\"top-fan\"><a href='" . HuijiPrefix::prefixToUrl($value['site_prefix']) . "'>" . (new wSiteAvatar($value['site_prefix'], 's'))->getAvatarHtml() . HuijiPrefix::prefixToSiteName($value['site_prefix']) . "</a><i class= \"" . $change . " hidden-sm hidden-xs\">" . $diff . "</i><i class=\"fa fa-flag-checkered hidden-sm hidden-xs\">" . $value['best_rank'] . "</i></span><span class=\"top-fan-points\">" . $value['site_score'] . '马赫</sp>'; $output .= '<div class="cleared"></div>'; $output .= '</div>'; } $output .= '</div><div class="cleared"></div>'; $out->addHTML($output); }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgMemc; $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); // Set the page title, robot policies, etc. $this->setHeaders(); // Load CSS $out->addModuleStyles('ext.socialprofile.userstats.css'); $periodFromRequest = $request->getVal('period'); if ($periodFromRequest == 'weekly') { $period = 'weekly'; } elseif ($periodFromRequest == 'monthly') { $period = 'monthly'; } if (!isset($period)) { $period = 'weekly'; } if ($period == 'weekly') { $pageTitle = 'top-fans-weekly-points-link'; } else { $pageTitle = 'top-fans-monthly-points-link'; } $out->addHtml(TopUsersPoints::getRankingDropdown('用户' . $this->msg($pageTitle)->plain())); $out->setPageTitle($this->msg($pageTitle)->plain()); $count = 50; $user_list = array(); // Try cache $key = wfForeignMemcKey('huiji', '', 'user_stats', $period, 'points', $count); $data = $wgMemc->get($key); if ($data != '') { wfDebug("Got top users by {$period} points ({$count}) from cache\n"); $user_list = $data; } else { wfDebug("Got top users by {$period} points ({$count}) from DB\n"); $params['ORDER BY'] = 'up_points DESC'; $params['LIMIT'] = $count; $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select("user_points_{$period}", array('up_user_id', 'up_user_name', 'up_points'), array('up_user_id <> 0'), __METHOD__, $params); foreach ($res as $row) { $userObj = User::newFromId($row->up_user_id); $user_group = $userObj->getEffectiveGroups(); if (!in_array('bot', $user_group) && !in_array('bot-global', $user_group)) { $user_list[] = array('user_id' => $row->up_user_id, 'user_name' => $row->up_user_name, 'points' => $row->up_points); } } $wgMemc->set($key, $user_list, 60 * 5); } // // Top nav bar // $top_title = SpecialPage::getTitleFor( 'TopUsers' ); // $recent_title = SpecialPage::getTitleFor( 'TopUsersRecent' ); // $output = '<div class="top-fan-nav"> // <h1>' . $this->msg( 'top-fans-by-points-nav-header' )->plain() . '</h1> // <p><a href="' . htmlspecialchars( $top_title->getFullURL() ) . '">' . // $this->msg( 'top-fans-total-points-link' )->plain() . '</a></p>'; // if ( $period == 'weekly' ) { // $output .= '<p><a href="' . htmlspecialchars( $recent_title->getFullURL( 'period=monthly' ) ) . '">' . // $this->msg( 'top-fans-monthly-points-link' )->plain() . '</a><p> // <p><b>' . $this->msg( 'top-fans-weekly-points-link' )->plain() . '</b></p>'; // } else { // $output .= '<p><b>' . $this->msg( 'top-fans-monthly-points-link' )->plain() . '</b><p> // <p><a href="' . htmlspecialchars( $recent_title->getFullURL( 'period=weekly' ) ) . '">' . // $this->msg( 'top-fans-weekly-points-link' )->plain() . '</a></p>'; // } // // Build nav of stats by category based on MediaWiki:Topfans-by-category // $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' ); // $message = $this->msg( 'topfans-by-category' )->inContentLanguage(); // if ( !$message->isDisabled() ) { // $output .= '<h1 class="top-title">' . // $this->msg( 'top-fans-by-category-nav-header' )->plain() . '</h1>'; // $lines = explode( "\n", $message->text() ); // foreach ( $lines as $line ) { // if ( strpos( $line, '*' ) !== 0 ) { // continue; // } else { // $line = explode( '|', trim( $line, '* ' ), 2 ); // $stat = $line[0]; // $link_text = $line[1]; // // Check if the link text is actually the name of a system // // message (refs bug #30030) // $msgObj = $this->msg( $link_text ); // if ( !$msgObj->isDisabled() ) { // $link_text = $msgObj->parse(); // } // $output .= '<p>'; // $output .= Linker::link( // $by_category_title, // $link_text, // array(), // array( 'stat' => $stat ) // ); // $output .= '</p>'; // } // } // } // $output .= '</div>'; $x = 1; $output .= '<div class="top-users">'; foreach ($user_list as $item) { $user_title = Title::makeTitle(NS_USER, $item['user_name']); $avatar = new wAvatar($item['user_id'], 'm'); $avatarImage = $avatar->getAvatarURL(); if ($item['points'] < 0) { $points = 0; } else { $points = $item['points']; } if ($user->getName() == $item['user_name']) { $active = 'active'; } else { $active = ''; } $output .= '<div class="top-fan-row {$active}"> <span class="top-fan-num">' . $x . '.</span> <span class="top-fan"><a href="' . htmlspecialchars($user_title->getFullURL()) . '" >' . $avatarImage . '</a><a href="' . htmlspecialchars($user_title->getFullURL()) . '" >' . $item['user_name'] . '</a> </span>'; $output .= '<span class="top-fan-points"><b>' . $this->getLanguage()->formatNum($points) . '</b> ' . $this->msg('top-fans-points')->plain() . '</span>'; $output .= '<div class="cleared"></div>'; $output .= '</div>'; $x++; } $output .= '</div><div class="cleared"></div>'; $out->addHTML($output); }
/** * Show the special page * * @param $params Mixed: parameter(s) passed to the page or null */ public function execute($params) { global $wgUser, $wgSitename, $wgHuijiPrefix, $wgUserLevels; $lang = $this->getLanguage(); $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); // Set the page title, robot policies, etc. $this->setHeaders(); $out->addHtml(TopUsersPoints::getRankingDropdown($wgSitename . '排行榜')); $output = '<i>' . $this->msg('editranknote')->plain() . '</i>'; // Add CSS // $out->addModuleStyles( 'ext.socialprofile.useruserfollows.css' ); $out->addModuleStyles('ext.socialprofile.userstats.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'); /** * 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 = 20; $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); $sitefollows = UserSiteFollow::getSiteFollowersWithDetails($target_user, $wgHuijiPrefix); $total = count($sitefollows); $star_page = $per_page * ($page - 1); $result = array_slice($sitefollows, $star_page, $per_page); if (!$result) { $output .= '<div class="top-users"><h3>此页暂时没有排行</h3>'; } $output .= '<div class="top-users">'; $x = $star_page + 1; foreach ($result as $user) { if ($wgUser->getName() == $user['user']) { $active = 'active'; } else { $active = ''; } $user_title = Title::makeTitle(NS_USER, $user['user']); $commentIcon = $user['url']; $output .= "<div class=\"top-fan-row {$active}\">\n\t\t\t\t<span class=\"top-fan-num\">{$x}.</span>\n\t\t\t\t<span class=\"top-fan\"><a href='" . $user['userUrl'] . "'>\n\t\t\t\t\t{$commentIcon} </a><a href='" . $user['userUrl'] . "'>" . $user['user'] . '</a><i class="hidden-xs hidden-sm">' . $user['level'] . ' </i></span>'; $output .= '<span class="top-fan-points"><b>' . number_format($user['count']) . '</b> ' . $this->msg('top-fans-times')->plain() . '</span>'; $output .= '<div class="cleared"></div>'; $output .= '</div>'; $x++; } $output .= '</div><div class="cleared"></div>'; /** * 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>'; } $out->addHTML($output); }