/** * Updates user's points after they've made an edit in a namespace that is * listed in the $wgNamespacesForEditPoints array. */ function incEditCount($article, $revision, $baseRevId) { global $wgUser, $wgNamespacesForEditPoints, $wgMemc, $wgHuijiPrefix; // only keep tally for allowable namespaces if (!is_array($wgNamespacesForEditPoints) || in_array($article->getTitle()->getNamespace(), $wgNamespacesForEditPoints)) { $stats = new UserStatsTrack($wgUser->getID(), $wgUser->getName()); $stats->incStatField('edit'); } $dbr = wfGetDB(DB_SLAVE); $num = SiteStats::edits(); $sg = SystemGifts::checkEditsCounts($num); $usg = new UserSystemGifts($wgUser->getName()); if ($sg) { $usg->sendSystemGift(17); } $key = wfForeignMemcKey('huiji', '', 'revision', 'high_edit_site_followed', $wgUser->getName(), $wgHuijiPrefix); $wgMemc->incr($key); $key = wfForeignMemcKey('huiji', '', 'revision', 'last_edit_user', $article->getTitle()->getArticleId(), $wgHuijiPrefix); $wgMemc->delete($key); return true; }
/** * Increase a given social statistic field by $val. * * @param $field String: field name in user_stats database table * @param $val Integer: increase $field by this amount, defaults to 1 */ function incStatField($field, $val = 1) { global $wgUser, $wgMemc, $wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly; if (!$wgUser->isAllowed('bot') && !$wgUser->isAnon() && $this->stats_fields[$field]) { $dbw = wfGetDB(DB_MASTER); $dbw->update('user_stats', array($this->stats_fields[$field] . '=' . $this->stats_fields[$field] . "+{$val}"), array('stats_user_id' => $this->user_id), __METHOD__); $this->updateTotalPoints(); $this->clearCache(); // update weekly/monthly points if (isset($this->point_values[$field]) && !empty($this->point_values[$field])) { if ($wgUserStatsTrackWeekly) { $this->updateWeeklyPoints($this->point_values[$field]); } if ($wgUserStatsTrackMonthly) { $this->updateMonthlyPoints($this->point_values[$field]); } } $s = $dbw->selectRow('user_stats', array($this->stats_fields[$field]), array('stats_user_id' => $this->user_id), __METHOD__); $stat_field = $this->stats_fields[$field]; $field_count = $s->{$stat_field}; $key = wfForeignMemcKey('huiji', '', 'system_gift', 'id', $field . '-' . $field_count); $data = $wgMemc->get($key); if ($data != '' && is_int($data)) { wfDebug("Got system gift ID from cache\n"); $systemGiftID = $data; } else { $g = new SystemGifts(); $systemGiftID = $g->doesGiftExistForThreshold($field, $field_count); if ($systemGiftID) { $wgMemc->set($key, $systemGiftID, 60 * 30); } } if ($systemGiftID) { $sg = new UserSystemGifts($this->user_name); $sg->sendSystemGift($systemGiftID); } } }
function view() { global $wgOut, $wgUser, $wgHuijiprefix, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline; $wgOut->setPageTitle($this->mTitle->getPrefixedText()); // No need to display noarticletext, we use our own message if (!$this->user_id) { parent::view(); return ''; } $staff = ''; $bureaucrat = ''; $sysop = ''; $rollback = ''; $autoconfirmed = ''; if (in_array('staff', $this->user->getEffectiveGroups(true))) { $staff = '<li>职员</li> '; } if (in_array('bot', $this->user->getEffectiveGroups(true))) { $staff = '<li>机器人</li> '; } if (in_array('bureaucrat', $this->user->getEffectiveGroups(true))) { $bureaucrat = '<li>行政员</li> '; } if (in_array('sysop', $this->user->getEffectiveGroups(true))) { $sysop = '<li>管理员</li> '; } if (in_array('rollback', $this->user->getEffectiveGroups(true))) { $rollback = '<li>回退员</li> '; } if (in_array('autoconfirmed', $this->user->getEffectiveGroups(true))) { $autoconfirmed = '<li>自动确认用户</li> '; } $usf = new UserSiteFollow(); $uuf = new UserUserFollow(); $topFollowedSites = $usf->getTopFollowedSitesWithDetails($wgUser->getId(), $this->user_id); // $temp = array(); // $res = array(); // foreach( $topFollowedSites as $value ){ // // if ( $wgUser->isLoggedIn() ) { // $user = User::newFromName( $this->user_name ); // // } // $temp['url'] = HuijiPrefix::prefixToUrl($value); // $temp['name'] = HuijiPrefix::prefixToSiteName($value); // $temp['count'] = UserStats::getSiteEditsCount($user,$value); // $res[] = $temp; // } //sort by edit num $count = array(); foreach ($topFollowedSites as $val) { $count[] = $val['count']; } array_multisort($count, SORT_DESC, $topFollowedSites); $userCount = UserSiteFollow::getFollowingCount($this->user); if ($this->isOwner()) { $target = SpecialPage::getTitleFor('ViewFollows'); $query = array('user' => $this->user_name, 'rel_type' => 1); $button1 = '<li class="mw-ui-button">' . Linker::LinkKnown($target, '<i class="fa fa-users"></i>朋友', array(), $query) . '</li> '; } elseif ($uuf->checkUserUserFollow($wgUser, $this->user)) { $button1 = '<li id="user-user-follow" class="unfollow mw-ui-button"><a><i class="fa fa-minus-square-o"></i>取关</a></li> '; } else { $button1 = '<li id="user-user-follow" class="mw-ui-button"><i class="fa fa-plus-square-o"></i></i>关注</li> '; } if ($this->isOwner()) { $target = SpecialPage::getTitleFor('ViewGifts'); $query = array('user' => $this->user_name); $button2 = '<li class="mw-ui-button">' . Linker::LinkKnown($target, '<i class="fa fa-gift"></i>礼物</a>', array(), $query) . '</li> '; } else { $target = SpecialPage::getTitleFor('GiveGift'); $query = array('user' => $this->user_name); $button2 = '<li class="mw-ui-button">' . Linker::LinkKnown($target, '<i class="fa fa-gift"></i>赠送</a>', array(), $query) . '</li> '; } $contributions = SpecialPage::getTitleFor('Contributions'); $watchlist = SpecialPage::getTitleFor('Watchlist'); $send_message = SpecialPage::getTitleFor('UserBoard'); $user_safe = urlencode($this->user); $tools = array(); if ($wgUser->isLoggedIn()) { if (!$this->isOwner()) { $tools[] = '<li><a href="' . htmlspecialchars($send_message->getFullURL('user='******'&conv=' . $user_safe)) . '" rel="nofollow">' . wfMessage('user-send-message')->escaped() . '</a></li>'; if ($wgUser->isAllowed('block')) { # Block / Change block / Unblock links if ($this->user->isBlocked() && $this->user->getBlock()->getType() != Block::TYPE_AUTO) { $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('Block', $this->user_name), wfMessage('change-blocklink')->escaped()) . '</li>'; $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('Unblock', $this->user_name), wfMessage('unblocklink')->escaped()) . '</li>'; } else { $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('Block', $this->user_name), wfMessage('blocklink')->escaped()) . '</li>'; } } # Block log link $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('Log', 'block'), wfMessage('sp-contributions-blocklog'), array(), array('page' => $this->mTitle->getPrefixedText())) . '</li>'; # Suppression log link if ($wgUser->isAllowed('suppressionlog')) { $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('Log', 'suppress'), wfMessage('sp-contributions-suppresslog')->escaped(), array(), array('offender' => $this->user_name)) . '</li>'; } } # Uploads $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('Listfiles', $this->user_name), wfMessage('sp-contributions-uploads')->escaped()) . '</li>'; # Other logs link $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('Log', $this->user_name), wfMessage('sp-contributions-logs')->escaped()) . '</li>'; # Add link to deleted user contributions for priviledged users if ($wgUser->isAllowed('deletedhistory')) { $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('DeletedContributions', $this->user_name), wfMessage('sp-contributions-deleted')->escaped()) . '</li>'; } # Add a link to change user rights for privileged users $userrightsPage = new UserrightsPage(); $userrightsPage->setContext($this->getContext()); if ($userrightsPage->userCanChangeRights($this->user)) { $tools[] = '<li>' . Linker::linkKnown(SpecialPage::getTitleFor('Userrights', $this->user_name), wfMessage('sp-contributions-userrights')->escaped()) . '</li>'; } if ($this->isOwner()) { $tools[] = '<li><a href="' . htmlspecialchars($watchlist->getFullURL()) . '">' . wfMessage('user-watchlist')->escaped() . '</a></li>'; } } //user isonline // $_SESSION['username'] = $wgUser->getName(); // $user = User::newFromName( $this->user_name ); // $isonline = OnlineStatusBar_StatusCheck::getStatus( $user ); // if($isonline === 'online'){ // $online = '在线'; // }else{ // $online = '未知'; // } // $wgOut->addModuleScripts( 'ext.socialprofile.useruserfollows.js' ); #this script is already added globally // $wgOut->addHTML($wgAjaxExportList); # What is that for?? $wgOut->addHTML('<div class="profile-page"><div id="profile-top" class="jumbotron row">'); $wgOut->addHTML($this->getProfileTop($this->user_id, $this->user_name)); $wgOut->addHTML(' <div class="col-md-6 col-sm-12 col-xs-12 profile-top-right"> <div class="profile-top-right-top"> <div><h4><span class="icon-huiji"></span>在本wiki</h4></div> <ul>' . $staff . $bureaucrat . $sysop . $rollback . $autoconfirmed . '</ul> </div> <div class="profile-top-right-bottom"> <ul>'); foreach ($topFollowedSites as $value) { $Turl[] = HuijiPrefix::prefixToUrl($value['key']); $Tname[] = $value['val']; $Tcount[] = $value['count']; } if (isset($Tname)) { $num = count($Tname) > 3 ? 3 : count($Tname); for ($i = 0; $i < $num; $i++) { $wgOut->addHTML('<li><a href="' . $Turl[$i] . '">' . $Tname[$i] . '</a></li>'); } } $wgOut->addHTML(' </ul> '); if ($this->isOwner()) { $wgOut->addHTML('<a >查看我关注的<i id="site-following-count">' . $userCount . '</i>个wiki</a>'); } else { $wgOut->addHTML('<a >关注了<i>' . $userCount . '</i>个wiki</a>'); } $wgOut->addHTML(' <div> <ul class="profile-interactive">' . $button1 . $button2 . '<li class="dropdown-toggle mw-ui-button" data-toggle="dropdown" aria-expanded="false"><span class="glyphicon glyphicon-align-justify"></span></li> <ul class="dropdown-menu" role="menu"> ' . implode('', $tools) . ' <li><a href="' . htmlspecialchars($contributions->getFullURL('target=' . $user_safe . '&contribs=user')) . '" rel="nofollow">' . wfMessage('user-contributions')->escaped() . '</a></li> </ul> </ul> </div> </div> </div> '); $wgOut->addHTML('<div class="cleared"></div></div>'); // // User does not want social profile for User:user_name, so we just // // show header + page content // if ( // $this->getTitle()->getNamespace() == NS_USER && // $this->profile_data['user_id'] && // $this->profile_data['user_page_type'] == 0 // ) // { // parent::view(); // return ''; // } $ueb = new UserEditBox(); $editBox = $editData = array(); $userEditInfo = $ueb->getUserEditInfo($this->user_id); $maxlen = $currentMaxlen = 0; //init variables. if ($userEditInfo != false) { $wgOut->addHTML('<div id="user-page-center" class="col-md-12 hidden-xs"> <div class="panel panel-default"><div class="user-section-heading panel-heading"> <div class="user-section-title">贡献</div> <div class="action-right"></div> <div class="cleared"></div></div><div class="user-gift-container panel-body check-body">'); foreach ($userEditInfo as $value) { if (is_object($value) && !empty($value->_id) && $value->value > 0) { $editBox[$value->_id] = $value->value; $editData[] = $value->_id; //echo $value->_id.'->'.$value->value.'<br>'; } } $today = date("Y-m-d"); $yesterday = date("Y-m-d", strtotime("-1 day")); $editBox[$today] = UserEditBox::getTodayEdit($this->user_id); 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; } } $usg = new UserSystemGifts($this->user->getName()); if ($maxlen == 2) { $usg->sendSystemGift(33); } elseif ($maxlen == 3) { $usg->sendSystemGift(34); } elseif ($maxlen == 7) { $usg->sendSystemGift(35); } elseif ($maxlen == 13) { $usg->sendSystemGift(36); } elseif ($maxlen == 23) { $usg->sendSystemGift(37); } elseif ($maxlen == 61) { $usg->sendSystemGift(38); } elseif ($maxlen == 109) { $usg->sendSystemGift(39); } elseif ($maxlen == 199) { $usg->sendSystemGift(40); } elseif ($maxlen == 367) { $usg->sendSystemGift(41); } elseif ($maxlen == 727) { $usg->sendSystemGift(42); } elseif ($maxlen == 1213) { $usg->sendSystemGift(43); } elseif ($maxlen == 1579) { $usg->sendSystemGift(44); } elseif ($maxlen == 1949) { $usg->sendSystemGift(45); } elseif ($maxlen == 2333) { $usg->sendSystemGift(46); } $wgOut->addHTML(' <div class="check-wrapper"><svg width="725" 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; $wgOut->addHTML(' <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'; } $wgOut->addHTML('<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; } $wgOut->addHTML('</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; } } $wgOut->addHTML('<text x="' . $x . '" y="-5" class="' . $year . '">' . $mon . '月</text>'); } $wgOut->addHTML(' <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> <div class="legend-intro"> <span><b>编辑数</b> 低</span> <ul class="legend"> <li style="background-color: #eee"></li> <li style="background-color: #86beee"></li> <li style="background-color: #5ea2de"></li> <li style="background-color: #256fb1"></li> <li style="background-color: #0d5493"></li> </ul> <span>高</span> </div> <div class="edit-statistics"><p>连续编辑纪录<span>' . $maxlen . '</span></p><p>总编辑天数<span>' . $totalEdit . '</span></p><p>当前连续编辑<span>' . $currentMaxlen . '<span></p></div> </div>'); $wgOut->addHTML('</div></div></div>'); } // Left side $wgOut->addHTML('<div id="user-page-left" class="col-md-6">'); if (!wfRunHooks('UserProfileBeginLeft', array(&$this))) { wfDebug(__METHOD__ . ": UserProfileBeginLeft messed up profile!\n"); } if ($this->user_id != $wgUser->getId()) { $wgOut->addHTML($this->getCommonInterest($wgUser->getId(), $this->user_id)); } $wgOut->addHTML($this->getRelationships($this->user_name, 1)); $wgOut->addHTML($this->getRelationships($this->user_name, 2)); $wgOut->addHTML($this->getGifts($this->user_name)); $wgOut->addHTML($this->getCustomInfo($this->user_name)); $wgOut->addHTML($this->getInterests($this->user_name)); $wgOut->addHTML($this->getFanBoxes($this->user_name)); $wgOut->addHTML($this->getUserStats($this->user_id, $this->user_name)); $wgOut->addHTML($this->getEditingActivity($this->user_name)); $wgOut->addHTML($this->getNonEditingActivity($this->user_name)); if (!wfRunHooks('UserProfileEndLeft', array(&$this))) { wfDebug(__METHOD__ . ": UserProfileEndLeft messed up profile!\n"); } $wgOut->addHTML('</div>'); wfDebug("profile start right\n"); // Right side $wgOut->addHTML('<div id="user-page-right" class="col-md-6">'); if (!wfRunHooks('UserProfileBeginRight', array(&$this))) { wfDebug(__METHOD__ . ": UserProfileBeginRight messed up profile!\n"); } $wgOut->addHTML($this->getAwards($this->user_name)); $wgOut->addHTML($this->getPersonalInfo($this->user_id, $this->user_name)); // Hook for BlogPage if (!wfRunHooks('UserProfileRightSideAfterActivity', array($this))) { wfDebug(__METHOD__ . ": UserProfileRightSideAfterActivity hook messed up profile!\n"); } $wgOut->addHTML($this->getCasualGames($this->user_id, $this->user_name)); $wgOut->addHTML($this->getUserBoard($this->user_id, $this->user_name)); if (!wfRunHooks('UserProfileEndRight', array(&$this))) { wfDebug(__METHOD__ . ": UserProfileEndRight messed up profile!\n"); } $wgOut->addHTML('</div><div class="cleared"></div></div>'); }
/** * Show the special page * * @param $period String: either weekly or monthly */ public function execute($period) { global $wgContLang, $wgUser; global $wgUserStatsPointValues; $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); // Blocked through Special:Block? Tough luck. if ($user->isBlocked()) { $out->blockedPage(false); return false; } // Is the database locked or not? if (wfReadOnly()) { $out->readOnlyPage(); return false; } // Check for the correct permission if (!$user->isAllowed('generatetopusersreport')) { $out->permissionRequired('generatetopusersreport'); return false; } // Set the page title, robot policy, etc. $this->setHeaders(); $period = $request->getVal('period', $period); // If we don't have a period, default to weekly or else we'll be // hitting a database error because when constructing table names // later on in the code, we assume that $period is set to something if (!$period) { $period = 'weekly'; } // Make sure that we are actually going to give out some extra points // for weekly and/or monthly wins, depending on which report we're // generating here. If not, there's no point in continuing. if (empty($wgUserStatsPointValues["points_winner_{$period}"])) { $out->addHTML($this->msg('user-stats-report-error-variable-not-set', $period)->escaped()); return; } // There used to be a lot of inline CSS here in the original version. // I removed that, because most of it is already in TopList.css, inline // CSS (and JS, for that matter) is evil, there were only 5 CSS // declarations that weren't in TopList.css and it was making the // display look worse, not better. // Add CSS $out->addModuleStyles('ext.socialprofile.userstats.css'); // Used as the LIMIT for SQL queries; basically, show this many users // in the generated reports. $user_count = $request->getInt('user_count', 10); if ($period == 'weekly') { $period_title = $wgContLang->date(wfTimestamp(TS_MW, strtotime('-1 week'))) . '-' . $wgContLang->date(wfTimestampNow()); } elseif ($period == 'monthly') { $date = getdate(); // It's a PHP core function $period_title = $wgContLang->getMonthName($date['mon']) . ' ' . $date['year']; } $dbw = wfGetDB(DB_MASTER); // Query the appropriate points table $res = $dbw->select("user_points_{$period}", array('up_user_id', 'up_user_name', 'up_points'), array(), __METHOD__, array('ORDER BY' => 'up_points DESC', 'LIMIT' => $user_count)); $last_rank = 0; $last_total = 0; $x = 1; $users = array(); // Initial run is a special case if ($dbw->numRows($res) <= 0) { // For the initial run, everybody's a winner! // Yes, I know that this isn't ideal and I'm sorry about that. // The original code just wouldn't work if the first query // (the $res above) returned nothing so I had to work around that // limitation. $res = $dbw->select('user_stats', array('stats_user_id', 'stats_user_name', 'stats_total_points'), array(), __METHOD__, array('ORDER BY' => 'stats_total_points DESC', 'LIMIT' => $user_count)); $output = '<div class="top-users">'; foreach ($res as $row) { if ($row->stats_total_points == $last_total) { $rank = $last_rank; } else { $rank = $x; } $last_rank = $x; $last_total = $row->stats_total_points; $x++; $userObj = User::newFromId($row->stats_user_id); $user_group = $userObj->getEffectiveGroups(); if (!in_array('bot', $user_group) && !in_array('bot-global', $user_group)) { $users[] = array('user_id' => $row->stats_user_id, 'user_name' => $row->stats_user_name, 'points' => $row->stats_total_points, 'rank' => $rank); } } } else { $output = '<div class="top-users">'; foreach ($res as $row) { if ($row->up_points == $last_total) { $rank = $last_rank; } else { $rank = $x; } $last_rank = $x; $last_total = $row->up_points; $x++; $userObj = User::newFromId($row->up_user_id); $user_group = $userObj->getEffectiveGroups(); if (!in_array('bot', $user_group) && !in_array('bot-global', $user_group)) { $users[] = array('user_id' => $row->up_user_id, 'user_name' => $row->up_user_name, 'points' => $row->up_points, 'rank' => $rank); } } } $winner_count = 0; $winners = ''; if (!empty($users)) { $localizedUserNS = $wgContLang->getNsText(NS_USER); foreach ($users as $user) { if ($user['rank'] == 1) { // Mark the user ranked #1 as the "winner" for the given // period if ($period == 'weekly') { $systemGiftID = 9; } elseif ($period == 'monthly') { $systemGiftID = 10; } $sg = new UserSystemGifts($user['user_name']); $sg->sendSystemGift($systemGiftID); $stats = new UserStatsTrack($user['user_id'], $user['user_name']); $stats->incStatField("points_winner_{$period}"); if ($winners) { $winners .= ', '; } $winners .= "[[{$localizedUserNS}:{$user['user_name']}|{$user['user_name']}]]"; $winner_count++; } elseif ($user['rank'] == 2 || $user['rank'] == 3) { if ($period == 'weekly') { $systemGiftID = 13; } elseif ($period == 'monthly') { $systemGiftID = 15; } $sg = new UserSystemGifts($user['user_name']); $sg->sendSystemGift($systemGiftID); } else { if ($period == 'weekly') { $systemGiftID = 14; } elseif ($period == 'monthly') { $systemGiftID = 16; } $sg = new UserSystemGifts($user['user_name']); $sg->sendSystemGift($systemGiftID); } } } // Start building the content of the report page $pageContent = "__NOTOC__\n"; // For grep: user-stats-weekly-winners, user-stats-monthly-winners $pageContent .= '==' . $this->msg("user-stats-{$period}-winners")->numParams($winner_count)->inContentLanguage()->parse() . "==\n\n"; // For grep: user-stats-weekly-win-congratulations, user-stats-monthly-win-congratulations $pageContent .= $this->msg("user-stats-{$period}-win-congratulations")->numParams($winner_count, $wgContLang->formatNum($wgUserStatsPointValues["points_winner_{$period}"]))->inContentLanguage()->parse() . "\n\n"; $pageContent .= "=={$winners}==\n\n<br />\n"; $pageContent .= '==' . $this->msg('user-stats-full-top')->numParams($wgContLang->formatNum($user_count))->inContentLanguage()->parse() . "==\n\n"; foreach ($users as $user) { $userTitle = Title::makeTitle(NS_USER, $user['user_name']); $pageContent .= $this->msg('user-stats-report-row', $wgContLang->formatNum($user['rank']), $user['user_name'], $wgContLang->formatNum($user['points']))->inContentLanguage()->parse() . "\n\n"; $output .= "<div class=\"top-fan-row\">\n\t\t\t<span class=\"top-fan-num\">{$user['rank']}</span><span class=\"top-fan\"> <a href='" . $userTitle->getFullURL() . "' >" . $user['user_name'] . "</a>\n\t\t\t</span>"; $output .= '<span class="top-fan-points">' . $this->msg('user-stats-report-points', $wgContLang->formatNum($user['points']))->inContentLanguage()->parse() . '</span> </div>'; } // Make the edit as MediaWiki default $oldUser = $wgUser; $wgUser = User::newFromName('MediaWiki default'); $wgUser->addGroup('bot'); // Add a note to the page that it was automatically generated $pageContent .= "\n\n''" . $this->msg('user-stats-report-generation-note')->parse() . "''\n\n"; // Create the Title object that represents the report page // For grep: user-stats-report-weekly-page-title, user-stats-report-monthly-page-title $title = Title::makeTitleSafe(NS_PROJECT, $this->msg("user-stats-report-{$period}-page-title", $period_title)->inContentLanguage()->escaped()); $article = new Article($title); // If the article doesn't exist, create it! // @todo Would there be any point in updating a pre-existing article? // I think not, but... if (!$article->exists()) { // For grep: user-stats-report-weekly-edit-summary, user-stats-report-monthly-edit-summary $article->doEdit($pageContent, $this->msg("user-stats-report-{$period}-edit-summary")->inContentLanguage()->escaped()); $date = date('Y-m-d H:i:s'); // Archive points from the weekly/monthly table into the archive // table $dbw->insertSelect('user_points_archive', "user_points_{$period}", array('up_user_name' => 'up_user_name', 'up_user_id' => 'up_user_id', 'up_points' => 'up_points', 'up_period' => $period == 'weekly' ? 1 : 2, 'up_date' => $dbw->addQuotes($date)), '*', __METHOD__); // Clear the current point table to make way for the next period $res = $dbw->delete("user_points_{$period}", '*', __METHOD__); } // Switch the user back $wgUser = $oldUser; $output .= '</div>'; // .top-users $out->addHTML($output); }