function wfGetSiteRank() { global $wgUser, $wgHuijiPrefix; $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_UNKNOWN); // This feature is only available for logged-in users. if (!$wgUser->isLoggedIn()) { $out = ResponseGenerator::getJson(ResponseGenerator::ERROR_NOT_LOGGED_IN); return $out; } $dateArr = array(); for ($k = 1; $k < 31; $k++) { $dateArr[] = date('Y-m-d', strtotime("-{$k} day")); } $desdateArr = array_reverse($dateArr); $res['date'] = $desdateArr; foreach ($desdateArr as $key => $value) { $daySiteRank = AllSitesInfo::getAllSitesRankData($wgHuijiPrefix, $value); $drank = isset($daySiteRank[0]['site_score']) ? $daySiteRank[0]['site_score'] : 0; $result[] = (int) $drank; } $res['rank'] = $result; if ($res) { $ret = array('success' => true, 'result' => $res); $out = json_encode($ret); return $out; } }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUploadPath, $wgUser, $wgHuijiPrefix; $templateParser = new TemplateParser(__DIR__ . '/pages'); $out = $this->getOutput(); $user = $this->getUser(); if (!$user->isAllowed('AdminDashboard')) { $out->permissionRequired('AdminDashboard'); return; } // Set the page title, robot policies, etc. $this->setHeaders(); // Add CSS $out->addModules('ext.socialprofile.userprofile.css'); $out->addModules('ext.socialprofile.admindashboard.css'); // Add js and message // $out->addModules( 'skin.bootstrapmediawiki.huiji.getRecordsInterface.js' ); $out->addModules('ext.socialprofile.admindashboard.js'); $out->addModules('ext.socialprofile.userprofile.js'); $output = ''; // Prevent E_NOTICE $yesterday = date("Y-m-d", strtotime("-1 day")); $totaledit = SiteStats::edits(); $ueb = new UserEditBox(); $rankInfo = AllSitesInfo::getAllSitesRankData($wgHuijiPrefix, $yesterday); $usf = new UserSiteFollow(); $follows = $usf->getSiteFollowers('', $wgHuijiPrefix); // print_r($follows); $followCount = count($follows); if ($followCount >= 8) { $follows = array_slice($follows, 0, 8); $display = ''; } else { $display = 'none'; } $newFollow = array(); foreach ($follows as $value) { $arr['user_name'] = $value['user_name']; $userPage = Title::makeTitle(NS_USER, $value['user_name']); $arr['user_url'] = htmlspecialchars($userPage->getFullURL()); $arr['follow_date'] = wfMessage('comments-time-ago', HuijiFunctions::getTimeAgo(strtotime($value['follow_date'])))->text(); $newFollow[] = $arr; } $sentToAll = SpecialPage::getTitleFor('SendToFollowers')->getFullURL(); $showMore = SpecialPage::getTitleFor('EditRank')->getFullURL(); $rightsManage = SpecialPage::getTitleFor('用户权限')->getFullURL(); $blockUsers = SpecialPage::getTitleFor('封禁')->getFullURL(); $freezeUsers = SpecialPage::getTitleFor('解除封禁')->getFullURL(); $replaceText = SpecialPage::getTitleFor('替换文本')->getFullURL(); $siteRankPage = SpecialPage::getTitleFor('SiteRank')->getFullURL(); $allSpecial = SpecialPage::getTitleFor('特殊页面')->getFullURL(); $siteAvatar = (new wSiteAvatar($wgHuijiPrefix, 'l'))->getAvatarHtml(); $token = $user->getEditToken(); if (is_null($newFollow)) { $newFollow = false; } $output .= $templateParser->processTemplate('admin_index', array('siteRank' => isset($rankInfo[0]['site_rank']) ? $rankInfo[0]['site_rank'] : '暂无', 'siteScore' => isset($rankInfo[0]['site_score']) ? $rankInfo[0]['site_score'] : '暂无', 'yesterdayCount' => UserSiteFollow::getFollowerCountOneday($wgHuijiPrefix, $yesterday), 'totalCount' => UserSiteFollow::getFollowerCount($wgHuijiPrefix), 'yesterdayEdit' => $ueb->getSiteEditCount('', $wgHuijiPrefix, $yesterday, $yesterday), 'totalEdit' => $totaledit, 'totalView' => $ueb->getSiteViewCount(-1, $wgHuijiPrefix, '', ''), 'yesterdayView' => $ueb->getSiteViewCount(-1, $wgHuijiPrefix, $yesterday, $yesterday), 'newFollow' => $newFollow, 'sendToAll' => $sentToAll, 'showMore' => $showMore, 'display' => $display, 'rightsManage' => $rightsManage, 'blockUsers' => $blockUsers, 'freezeUsers' => $freezeUsers, 'replaceText' => $replaceText, 'siteRankPage' => $siteRankPage, 'allSpecial' => $allSpecial, 'siteAvatar' => $siteAvatar, 'token' => $token)); $out->addHtml($output); }
function wfAddForkCount($page_id) { $count = AllSitesInfo::getPageForkCount($page_id); $pageCount = !is_null($count) ? $count : 0; $dbw = wfGetDB(DB_MASTER); $dbw->upsert('template_fork_count', array('template_id' => $page_id, 'fork_count' => 1), array('template_id' => $page_id), array('fork_count' => $pageCount + 1), __METHOD__); return 'success'; }
/** * count all site edits,files,pages,sites,users, * @return array */ public function getStats() { $key = wfForeignMemcKey('huiji', '', 'Huiji', 'getStats'); $stats = $this->cache->get($key); if ($stats != '') { return $stats; } else { $stats['edits'] = AllSitesInfo::getAllSiteEditCount(); $stats['files'] = AllSitesInfo::getAllUploadFileCount(); $stats['pages'] = AllSitesInfo::getAllPageCount(); $stats['sites'] = AllSitesInfo::getSiteCountNum(); $stats['users'] = AllSitesInfo::getUserCountNum(); $this->cache->set($key, $stats, 24 * 60 * 60); } return $stats; }
/** * 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); }
static function getAllSitesRank() { $allSite = HuijiPrefix::getAllPrefix(); $today = date('Y-m-d'); $yesterday = date('Y-m-d', strtotime('-1 days')); $lastWeek = date('Y-m-d', strtotime('-8 days')); $lastMonth = date('Y-m-d', strtotime('-31 days')); $ueb = new UserEditBox(); $editUserYesterday = $ueb->getSiteEditUserCount($yesterday, $yesterday); $editUserWeek = $ueb->getSiteEditUserCount($lastWeek, $yesterday); $editUserMonth = $ueb->getSiteEditUserCount($lastMonth, $yesterday); // print_r($editUserYesterday); $viewDate = array(); $editDate = array(); $editUserDate = array(); foreach ($allSite as $value) { $viewResult['yesterday'] = $ueb->getSiteViewCount('', $value, $yesterday, $yesterday); $viewResult['week'] = $ueb->getSiteViewCount('', $value, $lastWeek, $yesterday); $viewResult['month'] = $ueb->getSiteViewCount('', $value, $lastMonth, $yesterday); $editResult['yesterday'] = $ueb->getSiteEditCount('', $value, $yesterday, $yesterday); $editResult['week'] = $ueb->getSiteEditCount('', $value, $lastWeek, $yesterday); $editResult['month'] = $ueb->getSiteEditCount('', $value, $lastMonth, $yesterday); $viewDate[$value] = round($viewResult['yesterday'] + $viewResult['week'] / 7 + $viewResult['month'] / 30); $editDate[$value] = round($editResult['yesterday'] + $editResult['week'] / 7 + $editResult['month'] / 30); $editUserDate[$value] = round(isset($editUserYesterday[$value]) ? $editUserYesterday[$value] : 0 + (isset($editUserWeek[$value]) ? $editUserWeek[$value] : 0) / 7 + (isset($editUserMonth[$value]) ? $editUserMonth[$value] : 0) / 30); } //sort arr asort($viewDate); asort($editDate); asort($editUserDate); // print_r($editUserDate); $i = 1; //loop score $viewRes = array(); $editRes = array(); $editUserRes = array(); foreach ($viewDate as $key => $value) { $viewRes[$key] = $i * 10; $i++; } $j = 1; foreach ($editDate as $key => $value) { $editRes[$key] = $j * 10; $j++; } $k = 1; foreach ($editUserDate as $key => $value) { $editUserRes[$key] = $k * 10; $k++; } //highest score $highest = ($k - 1) * 100; //Comprehensive 2 4 4 $allRank = array(); foreach ($viewRes as $key => $value) { $allRank[$key] = $value * 2 + $editRes[$key] * 4 + $editUserRes[$key] * 4; } arsort($allRank); $x = 1; // print_r($allRank); //final rank foreach ($allRank as $key => $value) { $rank = $x; $score = round(100 * $value / $highest, 2); // $numRank['rank'] = $x; // $numRank['score'] = round(100*$value/$highest, 2); // $res[$key] = $numRank; //insert $dbw = wfGetDB(DB_MASTER); $dbw->insert('site_rank', array('site_rank' => $rank, 'site_score' => $score, 'site_prefix' => $key, 'site_rank_date' => $yesterday), __METHOD__); //best rank $key_rank = AllSitesInfo::getSiteBestRank($key); $site_rank = !is_null($key_rank) ? $key_rank : 1000; if ($rank < $site_rank) { $dbw = wfGetDB(DB_MASTER); $dbw->upsert('site_best_rank', array('site_rank' => $rank, 'site_prefix' => $key), array('site_prefix' => $key), array('site_rank' => $rank), __METHOD__); } $x++; } }
static function showPage() { global $wgUser, $wgParser; $templateParser = new TemplateParser(__DIR__ . '/View'); $output = ''; // Prevent E_NOTICE //user login if ($wgUser->isLoggedIn()) { $login = true; } else { $login = false; $register = Linker::linkKnown(SpecialPage::getTitleFor('Userlogin'), '注册', array(), array('type' => 'signup')); $active = 'active'; $inactive = 'in active'; } // check mobile device $mobile = mobiledetect(); $mobileUser = $mobile && $login; if (!$mobileUser) { //right data $fileCount = AllSitesInfo::getAllUploadFileCount(); $siteCount = AllSitesInfo::getSiteCountNum(); $userCount = AllSitesInfo::getUsreCountNum(); $editCount = AllSitesInfo::getAllSiteEditCount(); $pageCount = AllSitesInfo::getAllPageCount(); $userName = $wgUser->getName(); $usreId = $wgUser->getId(); $avatar = new wAvatar($usreId, 'l'); $userAvatar = $avatar->getAvatarURL(); //level $stats = new UserStats($usreId, $userName); $stats_data = $stats->getUserStats(); $user_level = new UserLevel($stats_data['points']); $level_link = Title::makeTitle(NS_HELP, wfMessage('user-profile-userlevels-link')->inContentLanguage()->text()); $levelUrl = htmlspecialchars($level_link->getFullURL()); $userLevel = $user_level->getLevelName(); //user info $notice = SpecialPage::getTitleFor('ViewFollows'); $contributions = SpecialPage::getTitleFor('Contributions'); $userEdit = Linker::link($contributions, $stats_data['edits'], array(), array('target' => $userName, 'contribs' => 'user')); $follower = Linker::link($notice, UserUserFollow::getFollowingCount($wgUser), array('id' => 'user-following-count'), array('user' => $userName, 'rel_type' => 1)); $followee = Linker::link($notice, UserUserFollow::getFollowerCount($wgUser), array('id' => 'user-follower-count'), array('user' => $userName, 'rel_type' => 2)); //siterank $yesterday = date('Y-m-d', strtotime('-1 days')); $allSiteRank = AllSitesInfo::getAllSitesRankData('', $yesterday); $siteRank = array_slice($allSiteRank, 0, 10); $siteInfo = array(); foreach ($siteRank as $key => $value) { $siteRank[$key]['site_prefix'] = HuijiPrefix::prefixToSiteName($value['site_prefix']); $siteRank[$key]['site_url'] = HuijiPrefix::prefixToUrl($value['site_prefix']); $siteInfo = AllSitesInfo::getPageInfoByPrefix($value['site_prefix']); $siteRank[$key]['totalEdits'] = $siteInfo['totalEdits']; $siteRank[$key]['totalArticles'] = $siteInfo['totalArticles']; $siteRank[$key]['totalPages'] = $siteInfo['totalPages']; $siteRank[$key]['totalUsers'] = $siteInfo['totalUsers']; } //userrank $weekRank = UserStats::getUserRank(10, 'week'); $monthRank = UserStats::getUserRank(20, 'month'); $totalRank = UserStats::getUserRank(20, 'total'); //小蓝格 $ueb = new UserEditBox(); $editBox = $editData = array(); $userEditInfo = $ueb->getUserEditInfo($usreId); $maxlen = $currentMaxlen = 0; //init variables. foreach ($userEditInfo as $value) { if (is_object($value) && !empty($value->_id) && $value->value > 0) { $editBox[$value->_id] = $value->value; $editData[] = $value->_id; } } $today = date("Y-m-d"); $yesterday = date("Y-m-d", strtotime("-1 day")); $editBox[$today] = UserEditBox::getTodayEdit($usreId); if (!empty($editBox[$today])) { $editData[] = $today; } $totalEdit = count($editData); if ($totalEdit > 0) { $resArr[] = strtotime($editData[0]); $maxlen = 1; } for ($k = 1; $k < count($editData); $k++) { if (in_array(strtotime($editData[$k]) - 86400, $resArr)) { $resArr[] = strtotime($editData[$k]); if (count($resArr) > $maxlen) { $maxlen = count($resArr); } } else { $resArr = array(); $resArr[] = strtotime($editData[$k]); } if ($resArr[count($resArr) - 1] == strtotime($today) || $resArr[count($resArr) - 1] == strtotime($yesterday)) { $currentMaxlen = count($resArr); } else { $currentMaxlen = 0; } } $lange = '<svg width="710" height="110" class=" "> <g transform="translate(20, 20)">'; $n = 676 / 13; $dateArr = array(); for ($k = 0; $k < 365; $k++) { $dateArr[] = date('Y-m-d', strtotime("-{$k} day")); } $desdateArr = array_reverse($dateArr); $translate = array(); for ($i = 0; $i <= $n; $i++) { $trani = $i * 13; $lange .= '<g transform="translate(' . $trani . ', 0)">'; $dayofweek = date('w', strtotime($desdateArr[0])); if ($i == 0) { $j = $dayofweek; $start = 0; $m = 7 - $dayofweek; } else { $j = 0; $m = 7; $start = $i * 7 - $dayofweek; } $zoneDate = array_slice($desdateArr, $start, $m); foreach ($zoneDate as $val) { $arrDate[$j] = $val; $y = $j * 13; $dataCount = isset($editBox[$val]) ? $editBox[$val] : 0; if ($dataCount == 0) { $color = '#eee'; } elseif ($dataCount > 0 && $dataCount <= 8) { $color = '#86beee'; } elseif ($dataCount > 8 && $dataCount <= 21) { $color = '#5ea2de'; } elseif ($dataCount > 21 && $dataCount <= 55) { $color = '#256fb1'; } else { $color = '#0d5493'; } $lange .= '<rect class="day" width="11" height="11" y="' . $y . '" fill="' . $color . '" data-count="' . $dataCount . '" data-date="' . $val . '" title="' . $val . ' 编辑' . $dataCount . '次"></rect>'; $j = $j >= 7 ? 0 : $j + 1; } if (!empty($arrDate[0])) { $translate[$arrDate[0]] = $trani; } $lange .= '</g>'; } $moninit = 1; for ($p = 0; $p < 12; $p++) { $year = date('Y') - 1; $mon = date('m') + $p + 1; if ($mon > 12) { $mon = $moninit++; $year = date('Y'); } $sunDay = UserEditBox::getSunday($mon, $year); $Stime = strtotime($sunDay); $sunDay = date('Y-m-d', $Stime); if (!isset($translate[$sunDay])) { $Suntime = strtotime($sunDay); $Sundate = date('Y', $Suntime) - 1; $sunDay = UserEditBox::getSunday($mon, $Sundate); } foreach ($translate as $key => $value) { if (strtotime($key) == strtotime($sunDay)) { $x = $value; } } $lange .= '<text x="' . $x . '" y="-5" class="' . $year . '">' . $mon . '月</text>'; } $lange .= ' <text text-anchor="middle" class="wday" dx="-10" dy="9" style="display: none;">S</text> <text text-anchor="middle" class="wday" dx="-10" dy="22">M</text> <text text-anchor="middle" class="wday" dx="-10" dy="35" style="display: none;">T</text> <text text-anchor="middle" class="wday" dx="-10" dy="48">W</text> <text text-anchor="middle" class="wday" dx="-10" dy="61" style="display: none;">T</text> <text text-anchor="middle" class="wday" dx="-10" dy="74">F</text> <text text-anchor="middle" class="wday" dx="-10" dy="87" style="display: none;">S</text> </g> </svg>'; //url helpManual huijitramac $helpManual = 'http://www.huiji.wiki/wiki/%E5%B8%AE%E5%8A%A9:%E7%BC%96%E8%BE%91%E6%89%8B%E5%86%8C'; $tarmac = 'http://www.huiji.wiki/wiki/%E7%81%B0%E6%9C%BAwiki:%E7%81%B0%E6%9C%BA%E5%81%9C%E6%9C%BA%E5%9D%AA'; $contact = 'http://www.huiji.wiki/wiki/%E7%81%B0%E6%9C%BAwiki:%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC'; } if ($login) { // follow $followUserCount = UserUserFollow::getFollowingCount($wgUser); if ($followUserCount >= 5) { $userHidden = true; } else { $userHidden = false; } $followSiteCount = UserSiteFollow::getFollowingCount($wgUser); if ($followSiteCount >= 5) { $siteHidden = true; } else { $siteHidden = false; } //recommend user $weekRank $monthRank $totalRank $uuf = new UserUserFollow(); if (count($weekRank) >= 8) { $recommend = UserStats::getUserRank(10, 'week'); } elseif (count($monthRank) >= 8) { $recommend = UserStats::getUserRank(20, 'month'); } else { $recommend = UserStats::getUserRank(20, 'total'); } $recommendRes = array(); $flres = array(); foreach ($recommend as $value) { $tuser = User::newFromName($value['user_name']); $isFollow = $uuf->checkUserUserFollow($wgUser, $tuser); if (!$isFollow && $value['user_name'] != $userName) { $flres['avatar'] = $value['avatarImage']; $flres['username'] = $value['user_name']; $flres['userurl'] = $value['user_url']; $recommendRes[] = $flres; } } $recommendRes = array_slice($recommendRes, 0, 5); //recommend site $usf = new UserSiteFollow(); // $recSite = array_slice($allSiteRank,0 ,5); $recommendSite = array(); foreach ($allSiteRank as $value) { $isFollowSite = $usf->checkUserSiteFollow($wgUser, $value['site_prefix']); if ($isFollowSite == false) { $fsres['s_name'] = HuijiPrefix::prefixToSiteName($value['site_prefix']); $fsres['s_url'] = HuijiPrefix::prefixToUrl($value['site_prefix']); $fsres['s_prefix'] = $value['site_prefix']; $fsres['s_avatar'] = (new wSiteAvatar($value['site_prefix'], 'l'))->getAvatarHtml(); $recommendSite[] = $fsres; } } $recommendSite = array_slice($recommendSite, 0, 5); if ($login && !$mobile) { $infoHeader = wfMessage('info-header-user')->parseAsBlock(); } elseif (!$login) { $infoHeader = wfMessage('info-header-anon')->parseAsBlock(); } else { $infoHeader = ''; } } $output .= $templateParser->processTemplate('frontpage', array('mobileUser' => $mobileUser, 'infoHeader' => $infoHeader, 'fileCount' => $fileCount, 'siteCount' => $siteCount, 'userCount' => $userCount, 'editCount' => $editCount, 'pageCount' => $pageCount, 'userName' => $userName, 'userAvatar' => $userAvatar, 'levelUrl' => $levelUrl, 'userLevel' => $userLevel, 'userEdit' => $userEdit, 'follower' => $follower, 'followee' => $followee, 'siteRank' => $siteRank, 'weekRank' => $weekRank, 'monthRank' => $monthRank, 'totalRank' => $totalRank, 'lange' => $lange, 'login' => $login, 'register' => $register, 'userHidden' => $userHidden, 'siteHidden' => $siteHidden, 'active' => $active, 'inactive' => $inactive, 'recommendSite' => $recommendSite, 'recContent' => $recContent, 'followUserCount' => $followUserCount, 'followSiteCount' => $followSiteCount, 'helpManual' => $helpManual, 'tarmac' => $tarmac, 'contact' => $contact)); return $output; }
/** * get site's best rank * @return string */ public function getBestRank() { $yesterday = date('Y-m-d', strtotime('-1 days')); $key = $this->getCustomKey('getBestRank' . $yesterday); $data = $this->cache->get($key); if ($data != '') { return $data; } else { $rank = AllSitesInfo::getSiteBestRank($this->mPrefix); return $rank; $this->cache->set($key, $rank, 48 * 60 * 60); } return $rank; }