/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUser, $wgOut, $wgRequest, $wgUploadPath, $wgSystemGiftsScripts; $wgOut->addExtensionStyle($wgSystemGiftsScripts . '/SystemGift.css'); $output = ''; // Prevent E_NOTICE // If gift ID wasn't passed in the URL parameters or if it's not // numeric, display an error message $giftId = $wgRequest->getInt('gift_id'); if (!$giftId || !is_numeric($giftId)) { $wgOut->setPageTitle(wfMsg('ga-error-title')); $wgOut->addHTML(wfMsg('ga-error-message-invalid-link')); return false; } $gift = UserSystemGifts::getUserGift($giftId); if ($gift) { if ($gift['status'] == 1) { if ($gift['user_name'] == $wgUser->getName()) { $g = new UserSystemGifts($gift['user_name']); $g->clearUserGiftStatus($gift['id']); $g->decNewSystemGiftCount($wgUser->getID()); } } // DB stuff $dbr = wfGetDB(DB_MASTER); $res = $dbr->select('user_system_gift', array('DISTINCT sg_user_name', 'sg_user_id', 'sg_gift_id', 'sg_date'), array("sg_gift_id = {$gift['gift_id']}", "sg_user_name <> '" . $dbr->strencode($gift['user_name']) . "'"), __METHOD__, array('GROUP BY' => 'sg_user_name', 'ORDER BY' => 'sg_date DESC', 'OFFSET' => 0, 'LIMIT' => 6)); $wgOut->setPageTitle(wfMsg('ga-gift-title', $gift['user_name'], $gift['name'])); $profileURL = Title::makeTitle(NS_USER, $gift['user_name'])->escapeFullURL(); $output .= '<div class="back-links">' . wfMsg('ga-back-link', $profileURL, $gift['user_name']) . '</div>'; $message = $wgOut->parse(trim($gift['description']), false); $output .= '<div class="ga-description-container">'; $giftImage = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt=""/>'; $output .= "<div class=\"ga-description\">\r\n\t\t\t\t\t{$giftImage}\r\n\t\t\t\t\t<div class=\"ga-name\">{$gift['name']}</div>\r\n\t\t\t\t\t<div class=\"ga-timestamp\">({$gift['timestamp']})</div>\r\n\t\t\t\t\t<div class=\"ga-description-message\">\"{$message}\"</div>"; $output .= '<div class="cleared"></div> </div>'; $output .= '<div class="ga-recent"> <div class="ga-recent-title">' . wfMsg('ga-recent-recipients-award') . '</div> <div class="ga-gift-count">' . wfMsgExt('ga-gift-given-count', 'parsemag', $gift['gift_count']) . '</div>'; foreach ($res as $row) { $userToId = $row->sg_user_id; $avatar = new wAvatar($userToId, 'ml'); $userNameLink = Title::makeTitle(NS_USER, $row->sg_user_name); $output .= '<a href="' . $userNameLink->escapeFullURL() . "\">\r\n\t\t\t\t\t{$avatar->getAvatarURL()}\r\n\t\t\t\t</a>"; } $output .= '<div class="cleared"></div> </div> </div>'; $wgOut->addHTML($output); } else { $wgOut->setPageTitle(wfMsg('ga-error-title')); $wgOut->addHTML(wfMsg('ga-error-message-invalid-link')); } }
/** * Adds awards for all registered users, updates statistics and purges * caches. * Special:PopulateAwards calls this function */ public function update_system_gifts() { global $wgOut, $wgMemc; $dbw = wfGetDB(DB_MASTER); $stats = new UserStatsTrack(1, ''); $this->categories = array_flip($this->categories); $res = $dbw->select('system_gift', array('gift_id', 'gift_category', 'gift_threshold', 'gift_name'), array(), __METHOD__, array('ORDER BY' => 'gift_category, gift_threshold ASC')); $x = 0; foreach ($res as $row) { if ($row->gift_category && !in_array($row->gift_category, $this->repeatableGifts)) { $res2 = $dbw->select('user_stats', array('stats_user_id', 'stats_user_name'), array($stats->stats_fields[$this->categories[$row->gift_category]] . " >= {$row->gift_threshold}", 'stats_user_id <> 0'), __METHOD__); foreach ($res2 as $row2) { if ($this->doesUserHaveGift($row2->stats_user_id, $row->gift_id) == false) { $dbw->insert('user_system_gift', array('sg_gift_id' => $row->gift_id, 'sg_user_id' => $row2->stats_user_id, 'sg_user_name' => $row2->stats_user_name, 'sg_status' => 0, 'sg_date' => date('Y-m-d H:i:s', time() - 60 * 60 * 24 * 3)), __METHOD__); $sg_key = wfForeignMemcKey('huiji', '', 'user', 'profile', 'system_gifts', "{$row2->stats_user_id}"); $wgMemc->delete($sg_key); // Update counters (bug #27981) UserSystemGifts::incGiftGivenCount($row->gift_id); $wgOut->addHTML(wfMessage('ga-user-got-awards', $row2->stats_user_name, $row->gift_name)->escaped() . '<br />'); $x++; } } } } $wgOut->addHTML(wfMessage('ga-awards-given-out')->numParams($x)->parse()); }
/** * 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 getAwards($user_name) { global $wgUser, $wgMemc, $wgUserProfileDisplay, $wgUploadPath; // If not enabled in site settings, don't display if ($wgUserProfileDisplay['awards'] == false) { return ''; } $output = ''; // System gifts $sg = new UserSystemGifts($user_name); // Try cache $sg_key = wfMemcKey('user', 'profile', 'system_gifts', "{$sg->user_id}"); $data = $wgMemc->get($sg_key); if (!$data) { wfDebug("Got profile awards for user {$user_name} from DB\n"); $system_gifts = $sg->getUserGiftList(0, 4); $wgMemc->set($sg_key, $system_gifts, 60 * 60 * 4); } else { wfDebug("Got profile awards for user {$user_name} from cache\n"); $system_gifts = $data; } $system_gift_count = $sg->getGiftCountByUsername($user_name); $system_gift_link = SpecialPage::getTitleFor('ViewSystemGifts'); $per_row = 4; if ($system_gifts) { $x = 1; $output .= '<div class="user-section-heading"> <div class="user-section-title">' . wfMsg('user-awards-title') . '</div> <div class="user-section-actions"> <div class="action-right">'; if ($system_gift_count > 4) { $output .= '<a href="' . $system_gift_link->escapeFullURL('user='******'" rel="nofollow">' . wfMsg('user-view-all') . '</a>'; } $output .= '</div> <div class="action-left">'; if ($system_gift_count > 4) { $output .= wfMsg('user-count-separator', '4', $system_gift_count); } else { $output .= wfMsg('user-count-separator', $system_gift_count, $system_gift_count); } $output .= '</div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> <div class="user-gift-container">'; foreach ($system_gifts as $gift) { if ($gift['status'] == 1 && $user_name == $wgUser->getName()) { $sg->clearUserGiftStatus($gift['id']); $wgMemc->delete($sg_key); $sg->decNewSystemGiftCount($wgUser->getID()); } $gift_image = '<img src="' . $wgUploadPath . '/awards/' . SystemGifts::getGiftImage($gift['gift_id'], 'ml') . '" border="0" alt="" />'; $gift_link = $user = SpecialPage::getTitleFor('ViewSystemGift'); $class = ''; if ($gift['status'] == 1) { $class = 'class="user-page-new"'; } $output .= '<a href="' . $gift_link->escapeFullURL('gift_id=' . $gift['id']) . '" ' . $class . " rel=\"nofollow\">\r\n\t\t\t\t\t{$gift_image}\r\n\t\t\t\t</a>"; if ($x == count($system_gifts) || $x != 1 && $x % $per_row == 0) { $output .= '<div class="cleared"></div>'; } $x++; } $output .= '</div>'; } return $output; }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUploadPath; $out = $this->getOutput(); $user = $this->getUser(); // Set the page title, robot policies, etc. $this->setHeaders(); // Add CSS $out->addModuleStyles('ext.socialprofile.systemgifts.css'); $output = ''; // Prevent E_NOTICE // If gift ID wasn't passed in the URL parameters or if it's not // numeric, display an error message $giftId = $this->getRequest()->getInt('gift_id'); if (!$giftId || !is_numeric($giftId)) { $out->setPageTitle($this->msg('ga-error-title')->plain()); $out->addHTML($this->msg('ga-error-message-invalid-link')->plain()); return false; } $gift = UserSystemGifts::getUserGift($giftId); if ($gift) { if ($gift['status'] == 1) { if ($gift['user_name'] == $user->getName()) { $g = new UserSystemGifts($gift['user_name']); $g->clearUserGiftStatus($gift['id']); $g->decNewSystemGiftCount($user->getID()); } } // DB stuff $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('user_system_gift', array('DISTINCT sg_user_name', 'sg_user_id', 'sg_gift_id', 'sg_date'), array("sg_gift_id = {$gift['gift_id']}", 'sg_user_name <> ' . $dbr->addQuotes($gift['user_name'])), __METHOD__, array('GROUP BY' => 'sg_user_name', 'ORDER BY' => 'sg_date DESC', 'OFFSET' => 0, 'LIMIT' => 6)); $out->setPageTitle($this->msg('ga-gift-title', $gift['user_name'], $gift['name'])->parse()); $profileURL = htmlspecialchars(Title::makeTitle(NS_USER, $gift['user_name'])->getFullURL()); $output .= '<div class="back-links">' . $this->msg('ga-back-link', $profileURL, $gift['user_name'])->text() . '</div>'; $message = $out->parse(trim($gift['description']), false); $output .= '<div class="ga-description-container">'; $giftImage = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt=""/>'; $output .= "<div class=\"ga-description\">\n\t\t\t\t\t{$giftImage}\n\t\t\t\t\t<div class=\"ga-name\">{$gift['name']}</div>\n\t\t\t\t\t<div class=\"ga-timestamp\">({$gift['timestamp']})</div>\n\t\t\t\t\t<div class=\"ga-description-message\">{$message}</div>"; $output .= '<div class="cleared"></div> </div>'; // If someone else in addition to the current user has gotten this // award, then and only then show the "Other recipients of this // award" header and the list of avatars if ($gift['gift_count'] > 1) { $output .= '<div class="ga-recent"> <div class="ga-recent-title">' . $this->msg('ga-recent-recipients-award')->plain() . '</div> <div class="ga-gift-count">' . $this->msg('ga-gift-given-count')->numParams($gift['gift_count'])->parse() . '</div>'; foreach ($res as $row) { $userToId = $row->sg_user_id; $avatar = new wAvatar($userToId, 'ml'); $userNameLink = Title::makeTitle(NS_USER, $row->sg_user_name); $output .= '<a href="' . htmlspecialchars($userNameLink->getFullURL()) . "\">\n\t\t\t\t\t{$avatar->getAvatarURL()}\n\t\t\t\t</a>"; } $output .= '<div class="cleared"></div> </div>'; // .ga-recent } $output .= '</div>'; $out->addHTML($output); } else { $out->setPageTitle($this->msg('ga-error-title')->plain()); $out->addHTML($this->msg('ga-error-message-invalid-link')->plain()); } }
function getNewSystemGiftLink() { global $wgUser, $wgScriptPath; $gift_count = UserSystemGifts::getNewSystemGiftCount( $wgUser->getID() ); $gifts_title = SpecialPage::getTitleFor( 'ViewSystemGifts' ); $output = ''; if ( $gift_count > 0 ) { $output .= '<p> <img src="' . $wgScriptPath . '/extensions/SocialProfile/images/awardIcon.png" alt="" border="0" /> <span class="profile-on"><a href="' . $gifts_title->escapeFullURL() . '" rel="nofollow">' . wfMsgExt( 'mp-request-new-award', 'parsemag', $gift_count ) . '</a></span> </p>'; } return $output; }
/** * 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); }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUser, $wgOut, $wgRequest, $wgUploadPath, $wgSystemGiftsScripts; $wgOut->addExtensionStyle($wgSystemGiftsScripts . '/SystemGift.css'); $output = ''; $user_name = $wgRequest->getVal('user'); $page = $wgRequest->getVal('page'); /** * Redirect Non-logged in users to Login Page * It will automatically return them to the ViewSystemGifts page */ if ($wgUser->getID() == 0 && $user_name == '') { $wgOut->setPageTitle(wfMsg('ga-error-title')); $login = SpecialPage::getTitleFor('Userlogin'); $wgOut->redirect($login->escapeFullURL('returnto=Special:ViewSystemGifts')); return false; } /** * If no user is set in the URL, we assume it's the current user */ if (!$user_name) { $user_name = $wgUser->getName(); } $user_id = User::idFromName($user_name); /** * Error message for username that does not exist (from URL) */ if ($user_id == 0) { $wgOut->setPageTitle(wfMsg('ga-error-title')); $wgOut->addHTML(wfMsg('ga-error-message-no-user')); return false; } /** * Config for the page */ $per_page = 10; if (!$page || !is_numeric($page)) { $page = 1; } $per_row = 2; /** * Get all Gifts for this user into the array */ $rel = new UserSystemGifts($user_name); $gifts = $rel->getUserGiftList(0, $per_page, $page); $total = $rel->getGiftCountByUsername($user_name); /** * Show gift count for user */ $wgOut->setPageTitle(wfMsg('ga-title', $rel->user_name)); $output .= '<div class="back-links">' . wfMsg('ga-back-link', $wgUser->getUserPage()->escapeFullURL(), $rel->user_name) . '</div>'; $output .= '<div class="ga-count">' . wfMsgExt('ga-count', 'parsemag', $rel->user_name, $total) . '</div>'; // Safelinks $view_system_gift_link = SpecialPage::getTitleFor('ViewSystemGift'); if ($gifts) { $x = 1; foreach ($gifts as $gift) { $gift_image = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'ml') . '" border="0" alt="" />'; $output .= "<div class=\"ga-item\">\r\n\t\t\t\t\t{$gift_image}\r\n\t\t\t\t\t<a href=\"" . $view_system_gift_link->escapeFullURL('gift_id=' . $gift['id']) . "\">{$gift['gift_name']}</a>"; if ($gift['status'] == 1) { if ($user_name == $wgUser->getName()) { $rel->clearUserGiftStatus($gift['id']); $rel->decNewSystemGiftCount($wgUser->getID()); } $output .= '<span class="ga-new">' . wfMsg('ga-new') . '</span>'; } $output .= '<div class="cleared"></div> </div>'; if ($x == count($gifts) || $x != 1 && $x % $per_row == 0) { $output .= '<div class="cleared"></div>'; } $x++; } } /** * Build next/prev nav */ $numofpages = $total / $per_page; $page_link = SpecialPage::getTitleFor('ViewSystemGifts'); if ($numofpages > 1) { $output .= '<div class="page-nav">'; if ($page > 1) { $output .= '<a href="' . $page_link->escapeFullURL('user='******'&page=' . ($page - 1)) . '">' . wfMsg('ga-previous') . '</a> '; } 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 .= $i . ' '; } else { $output .= '<a href="' . $page_link->escapeFullURL('user='******'&page=' . $i) . "\">{$i}</a> "; } } if ($total - $per_page * $page > 0) { $output .= ' <a href="' . $page_link->escapeFullURL('user='******'&page=' . ($page + 1)) . '">' . wfMsg('ga-next') . '</a>'; } $output .= '</div>'; } /** * Build next/prev nav */ $wgOut->addHTML($output); }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUploadPath, $wgUser; $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); // Set the page title, robot policies, etc. $this->setHeaders(); // Add CSS $out->addModuleStyles('ext.socialprofile.systemgifts.css'); $output = ''; $user_name = $request->getVal('user'); if ($user_name) { $user = User::newFromName($user_name); } $page = $request->getInt('page', 1); /** * Redirect Non-logged in users to Login Page * It will automatically return them to the ViewSystemGifts page */ if ($user->getID() == 0 && $user_name == '') { $out->setPageTitle($this->msg('ga-error-title')->plain()); $login = SpecialPage::getTitleFor('Userlogin'); $out->redirect(htmlspecialchars($login->getFullURL('returnto=Special:ViewSystemGifts'))); return false; } /** * If no user is set in the URL, we assume it's the current user */ if (!$user_name) { $user_name = $user->getName(); } $user_id = User::idFromName($user_name); /** * Error message for username that does not exist (from URL) */ if ($user_id == 0) { $out->setPageTitle($this->msg('ga-error-title')->plain()); $out->addHTML($this->msg('ga-error-message-no-user')->plain()); return false; } /** * Config for the page */ $per_page = 20; $per_row = 2; /** * Get all Gifts for this user into the array */ $rel = new UserSystemGifts($user_name); $gifts = $rel->getUserGiftList(0, $per_page, $page); $total = '<span style="color:#428bca;font-size:20px;font-weight: bold;">' . $rel->getGiftCountByUsername($user_name) . '</span>'; $curUserObj = User::newFromName($user_name); $uuf = new UserUserFollow(); $follows = $uuf->getFollowList($curUserObj, 1, '', $page); $follows[] = array('user_name' => $curUserObj->getName()); $giftCount = array(); foreach ($follows as $value) { $giftCount[$value['user_name']] = $rel->getGiftCountByUsername($value['user_name']); } arsort($giftCount); $max = count($giftCount); $countRes = array(); $i = 1; foreach ($giftCount as $key => $value) { $countRes[$key] = $i; $i++; } if ($curUserObj->getName() == $wgUser->getName()) { $who = '我'; } else { $who = $curUserObj->getName(); } // print_r($countRes); /** * Show gift count for user */ $allGiftList = '/wiki/' . SpecialPage::getTitleFor('SystemGiftList'); $out->setPageTitle($this->msg('ga-title', $rel->user_name)->parse()); $output .= '<div class="back-links">' . $this->msg('ga-back-link', htmlspecialchars($user->getUserPage()->getFullURL()), $rel->user_name)->text() . '</div>'; $output .= '<div class="ga-count">' . $this->msg('ga-count', $rel->user_name, $total)->parse() . ', 在' . $who . '的好友中排第<span style="color:#428bca;font-size:20px;font-weight: bold;">' . $countRes[$curUserObj->getName()] . '</span>名</div>'; $output .= '<div><a href="' . $allGiftList . '">查看所有奖励</a></div><div class="giftlist">'; // Safelinks $view_system_gift_link = SpecialPage::getTitleFor('ViewSystemGift'); // print_r($gifts); // print_r($countRes); if ($gifts) { foreach ($gifts as $gift) { $gift_image = "<div class='img'><img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt="" /></div>'; $output .= "<div class=\"ga-item have\">\n\t\t\t\t\t<a href=\"" . htmlspecialchars($view_system_gift_link->getFullURL('gift_id=' . $gift['id'])) . "\" data-toggle='popover' data-trigger='hover' title='{$gift['gift_name']}' data-content='{$gift['gift_description']}'>\n {$gift_image}"; if ($gift['status'] == 1) { if ($user_name == $user->getName()) { $rel->clearUserGiftStatus($gift['id']); $rel->decNewSystemGiftCount($user->getID()); } /*$output .= ' <span class="label label-success">' . $this->msg( 'ga-new' )->plain() . '</span>';*/ } $output .= '<div class="cleared"></div> </a></div>'; } $output .= '</div>'; } /** * Build next/prev nav */ $pcount = $rel->getGiftCountByUsername($user_name); $numofpages = $pcount / $per_page; $page_link = $this->getPageTitle(); if ($numofpages > 1) { $output .= '<div class="page-nav-wrapper"><nav class="page-nav pagination">'; if ($page > 1) { $output .= '<li>' . Linker::link($page_link, '<span aria-hidden="true">«</span>', array(), array('user' => $user_name, 'page' => $page - 1)) . '</li>'; } if ($pcount % $per_page != 0) { $numofpages++; } if ($numofpages >= 9 && $page < $pcount) { $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($page_link, $i, array(), array('user' => $user_name, 'page' => $i)); } } if ($pcount - $per_page * $page > 0) { $output .= '<li>' . Linker::link($page_link, '<span aria-hidden="true">»</span>', array(), array('user' => $user_name, 'page' => $page + 1)) . '</li>'; } $output .= '</nav></div>'; } /** * Output everything */ $out->addHTML($output); }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUploadPath; $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); // Set the page title, robot policies, etc. $this->setHeaders(); // Add CSS $out->addModuleStyles('ext.socialprofile.systemgifts.css'); $output = ''; $user_name = $request->getVal('user'); if ($user_name) { $user_current = User::newFromName($user_name); } $page = $request->getInt('page', 1); /** * Redirect Non-logged in users to Login Page * It will automatically return them to the ViewSystemGifts page */ if ($user->getID() == 0 && $user_name == '') { $out->setPageTitle($this->msg('ga-error-title')->plain()); $login = SpecialPage::getTitleFor('Userlogin'); $out->redirect(htmlspecialchars($login->getFullURL('returnto=Special:ViewSystemGifts'))); return false; } /** * If no user is set in the URL, we assume it's the current user */ if (!$user_name) { $user_name = $user->getName(); } $user_id = User::idFromName($user_name); /** * Error message for username that does not exist (from URL) */ if ($user_id == 0) { $out->setPageTitle($this->msg('ga-error-title')->plain()); $out->addHTML($this->msg('ga-error-message-no-user')->plain()); return false; } /** * Config for the page */ $per_page = 10; $per_row = 2; /** * Get all Gifts for this user into the array */ $rel = new UserSystemGifts($user_name); $gifts = $rel->getUserGiftList(0, $per_page, $page); $total = $rel->getGiftCountByUsername($user_name); /** * Show gift count for user */ $out->setPageTitle($this->msg('ga-title', $rel->user_name)->parse()); $output .= '<div class="back-links">' . $this->msg('ga-back-link', htmlspecialchars($user_current->getUserPage()->getFullURL()), $rel->user_name)->text() . '</div>'; $output .= '<div class="ga-count">' . $this->msg('ga-count', $rel->user_name, $total)->parse() . '</div>'; // Safelinks $view_system_gift_link = SpecialPage::getTitleFor('ViewSystemGift'); if ($gifts) { $x = 1; foreach ($gifts as $gift) { $gift_image = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage($gift['gift_id'], 'ml') . '" border="0" alt="" />'; $output .= "<div class=\"ga-item\">\n\t\t\t\t\t{$gift_image}\n\t\t\t\t\t<a href=\"" . htmlspecialchars($view_system_gift_link->getFullURL('gift_id=' . $gift['id'])) . "\">{$gift['gift_name']}</a>"; if ($gift['status'] == 1) { if ($user_name == $user->getName()) { $rel->clearUserGiftStatus($gift['id']); $rel->decNewSystemGiftCount($user->getID()); } $output .= ' <span class="label label-success">' . $this->msg('ga-new')->plain() . '</span>'; } $output .= '<div class="cleared"></div> </div>'; if ($x == count($gifts) || $x != 1 && $x % $per_row == 0) { $output .= '<div class="cleared"></div>'; } $x++; } } /** * Build next/prev nav */ $numofpages = $total / $per_page; $page_link = $this->getPageTitle(); if ($numofpages > 1) { $output .= '<nav class="page-nav pagination">'; if ($page > 1) { $output .= '<li>' . Linker::link($page_link, '<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($page_link, $i, array(), array('user' => $user_name, 'page' => $i)); } } if ($total - $per_page * $page > 0) { $output .= '<li>' . Linker::link($page_link, '<span aria-hidden="true">»</span>', array(), array('user' => $user_name, 'rel_type' => $rel_type, 'page' => $page + 1)) . '</li>'; } $output .= '</nav>'; } /** * Output everything */ $out->addHTML($output); }