/** * 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); }
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++; } }
/** * get the site's some days edit count * @param sting $fromTime '2016-01-01' * @param string $toTime '2016-02-02' * @return array */ public function getEditCount($fromTime, $toTime) { $ueb = new UserEditBox(); return $ueb->getSiteEditCount(-1, $this->mPrefix, $fromTime, $toTime); }