function execute() { global $wgUser, $wgOut; $wgOut->setPagetitle("Top Users"); $dbr =& wfGetDB(DB_MASTER); $sql = "SELECT stats_user_id,stats_user_name, stats_total_points from user_stats where stats_year_id = 1 and stats_user_id <> 0 ORDER BY stats_total_points DESC LIMIT 0,50"; $res = $dbr->query($sql); $header = wfMsg("topusersheader"); if ($header != "<topusersheader>") { $out = $header; } // $out = "<span style='font-size:11px;color:#666666;'>Here are the top users since the new \"season\" started on March 7th, 2007. Points are based on a super secret formula.<p><a href=\"index.php?title=ArmchairGM Top Users: Year 1\">Click here for the Top Users of the Inaugural Year</a></span><p>"; $x = 1; $out .= "<div class=\"top-users\">\n <div class=\"top-user-header\"><span class=\"top-user-num\">#</span><span class=\"top-user\">User</span><span class=\"top-user-points\">Points</span></div>"; while ($row = $dbr->fetchObject($res)) { $user_name = $row->stats_user_name; $user_title = Title::makeTitle(NS_USER, $row->stats_user_name); $avatar = new wAvatar($row->stats_user_id, "s"); $CommentIcon = $avatar->getAvatarImage(); $out .= "<div class=\"top-user-row\">\n\t \t\t<span class=\"top-user-num\">{$x}</span><span class=\"top-user\"><img src='images/avatars/" . $CommentIcon . "' alt='' border=''> <a href='" . $user_title->getFullURL() . "' class=\"top-user-link\">" . $row->stats_user_name . "</a><a href='" . $user_title->getTalkPage()->getFullURL() . "' class=\"top-user-talk\"><img src=\"images/commentIcon.gif\" border=\"0\" hspace=\"3\" align=\"middle\" alt=\"\" /></a>\n\t\t\t</span>"; $out .= "<span class=\"top-user-points\">" . $row->stats_total_points . "</span>\n\t \t</div>"; $x++; } $out .= "</div>"; $wgOut->addHTML($out); }
/** * Get comments of the day -- five newest comments within the last 24 hours * * @return String: HTML */ function getCommentsOfTheDay($input, $args, $parser) { global $wgMemc, $wgUploadPath; $oneDay = 60 * 60 * 24; // Try memcached first $key = wfMemcKey('comments-of-the-day', 'standalone-hook'); $data = $wgMemc->get($key); if ($data) { // success, got it from memcached! $commentsOfTheDay = $data; } elseif (!$data || $args['nocache']) { // just query the DB $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array('Comments', 'page'), array('Comment_Username', 'comment_ip', 'comment_text', 'comment_date', 'Comment_user_id', 'CommentID', 'IFNULL(Comment_Plus_Count - Comment_Minus_Count,0) AS Comment_Score', 'Comment_Plus_Count AS CommentVotePlus', 'Comment_Minus_Count AS CommentVoteMinus', 'Comment_Parent_ID', 'page_title', 'page_namespace'), array('comment_page_id = page_id', 'UNIX_TIMESTAMP(comment_date) > ' . (time() - $oneDay)), __METHOD__, array('ORDER BY' => '(Comment_Plus_Count) DESC', 'LIMIT' => 5)); $commentsOfTheDay = array(); foreach ($res as $row) { $commentsOfTheDay[] = array('username' => $row->Comment_Username, 'userid' => $row->Comment_user_id, 'score' => $row->CommentVotePlus, 'text' => $row->comment_text, 'id' => $row->CommentID, 'pagens' => $row->page_namespace, 'pagetitle' => $row->page_title); } $wgMemc->set($key, $commentsOfTheDay, $oneDay); } $comments = ''; foreach ($commentsOfTheDay as $commentOfTheDay) { $title2 = Title::makeTitle($commentOfTheDay['pagens'], $commentOfTheDay['pagetitle']); if ($commentOfTheDay['userid'] != 0) { $title = Title::makeTitle(NS_USER, $commentOfTheDay['username']); $commentPoster_Display = $commentOfTheDay['username']; $commentPoster = '<a href="' . $title->getFullURL() . '" title="' . $title->getText() . '" rel="nofollow">' . $commentOfTheDay['username'] . '</a>'; $avatar = new wAvatar($commentOfTheDay['userid'], 's'); $commentIcon = $avatar->getAvatarImage(); } else { $commentPoster_Display = wfMsg('comment-anon-name'); $commentPoster = wfMsg('comment-anon-name'); $commentIcon = 'default_s.gif'; } $comment_text = substr($commentOfTheDay['text'], 0, 50 - strlen($commentPoster_Display)); if ($comment_text != $commentOfTheDay['text']) { $comment_text .= wfMsg('ellipsis'); } $comments .= '<div class="cod">'; $sign = ''; if ($commentOfTheDay['score'] > 0) { $sign = '+'; } elseif ($commentOfTheDay['score'] < 0) { $sign = '-'; // this *really* shouldn't be happening... } $comments .= '<span class="cod-score">' . $sign . $commentOfTheDay['score'] . '</span> <img src="' . $wgUploadPath . '/avatars/' . $commentIcon . '" alt="" align="middle" style="margin-bottom:8px;" border="0"/> <span class="cod-poster">' . $commentPoster . '</span>'; $comments .= '<span class="cod-comment"><a href="' . $title2->getFullURL() . '#comment-' . $commentOfTheDay['id'] . '" title="' . $title2->getText() . '">' . $comment_text . '</a></span>'; $comments .= '</div>'; } $output = ''; if (!empty($comments)) { $output .= $comments; } else { $output .= wfMsg('comments-no-comments-of-day'); } return $output; }
function getWelcome() { global $wgUser, $wgOut, $wgScriptPath, $wgUploadPath; // Add CSS $wgOut->addExtensionStyle($wgScriptPath . '/extensions/SocialProfile/UserWelcome/UserWelcome.css'); // Get stats and user level $stats = new UserStats($wgUser->getID(), $wgUser->getName()); $stats_data = $stats->getUserStats(); $user_level = new UserLevel($stats_data['points']); // Safe links $level_link = Title::makeTitle(NS_HELP, wfMsgForContent('mp-userlevels-link')); $avatar_link = SpecialPage::getTitleFor('UploadAvatar'); // Make an avatar $avatar = new wAvatar($wgUser->getID(), 'l'); // Profile top images/points $output = '<div class="mp-welcome-logged-in"> <h2>' . wfMsg('mp-welcome-logged-in', $wgUser->getName()) . '</h2> <div class="mp-welcome-image"> <a href="' . $wgUser->getUserPage()->escapeFullURL() . '" rel="nofollow"><img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0"/></a>'; if (strpos($avatar->getAvatarImage(), 'default_') !== false) { $output .= '<div><a href="' . $avatar_link->escapeFullURL() . '" rel="nofollow">' . wfMsg('mp-welcome-upload') . '</a></div>'; } else { $output .= '<div><a href="' . $avatar_link->escapeFullURL() . '" rel="nofollow">' . wfMsg('mp-welcome-edit') . '</a></div>'; } $output .= '</div>'; global $wgUserLevels; if ($wgUserLevels) { $output .= '<div class="mp-welcome-points"> <div class="points-and-level"> <div class="total-points">' . wfMsgExt('mp-welcome-points', 'parsemag', $stats_data['points']) . '</div> <div class="honorific-level"><a href="' . $level_link->escapeFullURL() . '">(' . $user_level->getLevelName() . ')</a></div> </div> <div class="cleared"></div> <div class="needed-points"> <br />' . wfMsgExt('mp-welcome-needed-points', 'parsemag', $level_link->escapeFullURL(), $user_level->getNextLevelName(), $user_level->getPointsNeededToAdvance()) . '</div> </div>'; } $output .= '<div class="cleared"></div>'; $output .= getRequests(); $output .= '</div>'; return $output; }
function displayChallenge() { global $wgUser; $out = "<br><span class=pagetitle>ArmchairGM Challenge Info</span><br><br>"; $avatar1 = new wAvatar($this->challenge_username1, "l"); $avatar2 = new wAvatar($this->challenge_username2, "l"); $title1 = Title::makeTitle(NS_USER, $this->challenge_username1); $title2 = Title::makeTitle(NS_USER, $this->challenge_username2); $out .= "<table cellpadding=8 bgcolor=#eeeeee cellspacing=0 style='border:1px solid #666666'><tr><td>\n\t\t\t<img src='images/avatars/" . $avatar1->getAvatarImage() . "alt='' border=''>\n\t\t\t</td>"; $out .= "<td><span class=challenge-user-title><a href=" . $title1->getFullURL() . " class=challenge-user-title>" . $title1->getText() . "</a></span> (" . $this->getRecord($this->challenge_user_id_1) . ")\n\t\t\t\t<b>vs.</b> "; $out .= "</td><td><img src='images/avatars/" . $avatar2->getAvatarImage() . "alt='' border=''></td><td><span class=challenge-user-title>"; $out .= "<a href=" . $title2->getFullURL() . " class=challenge-user-title>" . $title2->getText() . "</a> </span> (" . $this->getRecord($this->challenge_user_id_2) . ")</td></tr></table><br>"; $out .= "<table ><tr><td><b>Event:</b> <span class=challenge-event>" . $this->challenge_info . " [" . $this->challenge_event_date . "]</span>"; $out .= "<br><b>" . $this->challenge_username1 . "'s description: </b><span class=challenge-description>" . $this->challenge_description . "</span></td></tr></table>"; $out .= "</td></tr></table><br><table cellpadding=0 cellspacing=0 ><tr><td valign=top><span class=title>if " . $this->challenge_username1 . " wins, " . $this->challenge_username2 . " has to . . . </span>"; $out .= "<table cellpadding=0 cellspacing=0 class=challenge-terms width=300><tr><td>" . $this->challenge_win_terms . "</td></tr></table><br>"; $out .= "</td><td width=20> </td><td valign=top><span class=title>if " . $this->challenge_username2 . " wins, " . $this->challenge_username1 . " has to . . . </span>"; $out .= "<table cellpadding=0 cellspacing=0 class=challenge-terms width=300><tr><td>" . $this->challenge_lose_terms . "</td></tr></table>"; $out .= "</td></tr></table>"; if ($wgUser->isAllowed('protect') && $this->challenge_user_id_2 != $wgUser->mId && $this->challenge_user_id_1 != $wgUser->mId) { $out .= "<a href=javascript:challengeCancel(" . $this->challenge_id . ") style='color:#990000'>Admin Cancel Challenge Due to Abuse</a>"; } $out .= "<hr><span class=challenge-status>\n\t\t\t\t<span class=title>Challenge Status</span><br><span id=challange-status>\n\t\t\t"; switch ($this->challenge_status) { case 0: $out .= $this->getStatusOpen(); break; case 1: if (1 == 2) { $out .= $this->getStatusAccepted(); } else { $out .= $this->getStatusAwaitingApproval(); } break; case -1: $out .= $this->getStatusRejected(); break; case -2: $out .= "<span class=challenge-rejected>Removed due to violation of rules</span>"; break; case 3: $out .= $this->getStatusCompleted(); break; } $out .= "</span></span><span id=status2></span>"; return $out; }
function getNYAvatar($user_id) { global $wgUploadDirectory; $avatar = new wAvatar($user_id, 'l'); $img = $avatar->getAvatarImage(); if ( $img ) { if ( substr(trim($img), 0, 7) != 'default' ) { $img = preg_replace("/\?(.*)/", '', $img); $img = $wgUploadDirectory . "/avatars/" . trim($img); } else { $img = '-'; } } else { $img = '-'; } echo $img; }
function getWelcome() { global $wgUser, $wgOut, $wgLang; // Add CSS $wgOut->addModuleStyles('ext.socialprofile.userwelcome.css'); // Get stats and user level $stats = new UserStats($wgUser->getID(), $wgUser->getName()); $stats_data = $stats->getUserStats(); $user_level = new UserLevel($stats_data['points']); // Safe links $level_link = Title::makeTitle(NS_HELP, wfMessage('mp-userlevels-link')->inContentLanguage()->plain()); $avatar_link = SpecialPage::getTitleFor('UploadAvatar'); // Make an avatar $avatar = new wAvatar($wgUser->getID(), 'l'); // Profile top images/points $output = '<div class="mp-welcome-logged-in"> <h2>' . wfMessage('mp-welcome-logged-in', $wgUser->getName())->parse() . '</h2> <div class="mp-welcome-image"> <a href="' . htmlspecialchars($wgUser->getUserPage()->getFullURL()) . '" rel="nofollow">' . $avatar->getAvatarURL() . '</a>'; if (strpos($avatar->getAvatarImage(), 'default_') !== false) { $uploadOrEditMsg = 'mp-welcome-upload'; } else { $uploadOrEditMsg = 'mp-welcome-edit'; } $output .= '<div><a href="' . htmlspecialchars($avatar_link->getFullURL()) . '" rel="nofollow">' . wfMessage($uploadOrEditMsg)->plain() . '</a></div>'; $output .= '</div>'; global $wgUserLevels; if ($wgUserLevels) { $output .= '<div class="mp-welcome-points"> <div class="points-and-level"> <div class="total-points">' . wfMessage('mp-welcome-points', $wgLang->formatNum($stats_data['points']))->parse() . '</div> <div class="honorific-level"><a href="' . htmlspecialchars($level_link->getFullURL()) . '">(' . $user_level->getLevelName() . ')</a></div> </div> <div class="cleared"></div> <div class="needed-points"> <br />' . wfMessage('mp-welcome-needed-points', htmlspecialchars($level_link->getFullURL()), $user_level->getNextLevelName(), $user_level->getPointsNeededToAdvance())->text() . '</div> </div>'; } $output .= '<div class="cleared"></div>'; $output .= getRequests(); $output .= '</div>'; return $output; }
function execute() { global $wgUser, $wgOut, $wgRequest; //$wgOut->addHTML("Coming Soon"); $out = ""; $out .= "<br><span class=pagetitle>ArmchairGM Challenge Standings</span><br><br>"; $out .= "<table cellpadding=3 cellspacing=0 border=0><tr>\n\t\t\t<td class=challenge-standings-title>#</td>\n\t\t\t<td class=challenge-standings-title>user</td>\n\t\t\t<td class=challenge-standings-title>W</td>\n\t\t\t<td class=challenge-standings-title>L</td>\n\t\t\t<td class=challenge-standings-title>T</td>\n\t\t\t<td class=challenge-standings-title>%</td>\n\t\t\t<td class=challenge-standings-title></td>\n\t\t\t</tr>"; $dbr =& wfGetDB(DB_SLAVE); $sql = "SELECT challenge_record_username, challenge_wins, challenge_losses, challenge_ties, (challenge_wins / (challenge_wins + challenge_losses + challenge_ties) ) as winning_percentage FROM challenge_user_record ORDER BY (challenge_wins / (challenge_wins + challenge_losses + challenge_ties) ) DESC, challenge_wins DESC LIMIT 0,25"; $res = $dbr->query($sql); $x = 1; while ($row = $dbr->fetchObject($res)) { $avatar1 = new wAvatar($row->challenge_record_username, "s"); $out .= "<tr>\n\t\t\t\t\t\t\t<td class=challenge-standings>" . $x . "</td>\n\t\t\t\t\t\t\t<td class=challenge-standings><img src='images/avatars/" . $avatar1->getAvatarImage() . "' align=absmiddle><a href=index.php?title=Special:ChallengeHistory&user="******" style='font-weight:bold;font-size:13px'>" . $row->challenge_record_username . "</a> " . $user1Icon . "</td>\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t<td class=challenge-standings>" . $row->challenge_wins . "</td>\n\t\t\t\t\t\t\t<td class=challenge-standings>" . $row->challenge_losses . "</td>\n\t\t\t\t\t\t\t<td class=challenge-standings>" . $row->challenge_ties . "</td>\n\t\t\t\t\t\t\t<td class=challenge-standings>" . str_replace(".0", ".", number_format($row->winning_percentage, 3)) . "</td>"; if ($row->challenge_record_username != $wgUser->mName) { $out .= "<td class=challenge-standings><a href=index.php?title=Special:ChallengeUser&user="******" style='color:#666666'>challenge user</a></td>"; } $out .= "</td>\n\t\t\t\t</tr>"; $x++; } $wgOut->addHTML($out); }
/** * Returns the footer for a page * * @return $footer The generated footer, including recent editors */ function footer() { global $wgMemc, $wgTitle, $wgUploadPath; $title = Title::makeTitle($wgTitle->getNamespace(), $wgTitle->getText()); $pageTitleId = $wgTitle->getArticleID(); $main_page = Title::newMainPage(); $about = Title::makeTitle(wfMsgForContent('aboutpage')); $special = SpecialPage::getTitleFor('Specialpages'); $help = SpecialPage::getTitleFor('Userlogin', 'signup'); $disclaimerPage = Title::newFromText(wfMsgForContent('disclaimerpage')); $footerShow = array(NS_MAIN, NS_FILE); if (defined('NS_VIDEO')) { $footerShow[] = NS_VIDEO; } $footer = ''; // Show the list of recent editors and their avatars if the page is in // one of the allowed namespaces and it is not the main page if (in_array($wgTitle->getNamespace(), $footerShow) && $pageTitleId != $main_page->getArticleID()) { $key = wfMemcKey('recenteditors', 'list', $pageTitleId); $data = $wgMemc->get($key); $editors = array(); if (!$data) { wfDebug(__METHOD__ . ": Loading recent editors for page {$pageTitleId} from DB\n"); $dbw = wfGetDB(DB_MASTER); $res = $dbw->select('revision', array('DISTINCT rev_user', 'rev_user_text'), array('rev_page' => $pageTitleId, 'rev_user <> 0', "rev_user_text <> 'MediaWiki default'"), __METHOD__, array('ORDER BY' => 'rev_user_text ASC', 'LIMIT' => 8)); foreach ($res as $row) { // Prevent blocked users from appearing $user = User::newFromId($row->rev_user); if (!$user->isBlocked()) { $editors[] = array('user_id' => $row->rev_user, 'user_name' => $row->rev_user_text); } } $wgMemc->set($key, $editors, 60 * 5); } else { wfDebug(__METHOD__ . ": Loading recent editors for page {$pageTitleId} from cache\n"); $editors = $data; } $x = 1; $per_row = 4; if (count($editors) > 0) { $footer .= '<div id="footer-container"> <div id="footer-actions"> <h2>' . wfMsg('nimbus-contribute') . '</h2>' . wfMsgExt('nimbus-pages-can-be-edited', 'parsemag') . '<a href="' . $title->escapeFullURL($this->skin->editUrlOptions()) . '" rel="nofollow" class="edit-action">' . wfMsg('editthispage') . '</a> <a href="' . $title->getTalkPage()->escapeFullURL() . '" rel="nofollow" class="discuss-action">' . wfMsg('talkpage') . '</a> <a href="' . $title->escapeFullURL('action=history') . '" rel="nofollow" class="page-history-action">' . wfMsg('pagehist') . '</a>'; $footer .= '</div>'; // Only load the page editors' avatars if wAvatar class exists and $wgUserLevels is an array global $wgUserLevels; if (class_exists('wAvatar') && is_array($wgUserLevels)) { $footer .= '<div id="footer-contributors"> <h2>' . wfMsg('nimbus-recent-contributors') . '</h2>' . wfMsg('nimbus-recent-contributors-info'); foreach ($editors as $editor) { $avatar = new wAvatar($editor['user_id'], 'm'); $user_title = Title::makeTitle(NS_USER, $editor['user_name']); $footer .= '<a href="' . $user_title->escapeFullURL() . '" rel="nofollow"> <img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="' . htmlspecialchars($editor['user_name']) . '" title="' . htmlspecialchars($editor['user_name']) . '" /> </a>'; if ($x == count($editors) || $x != 1 && $x % $per_row == 0) { $footer .= '<br />'; } $x++; } $footer .= '</div>'; } $footer .= '</div>'; } } $footer .= '<div id="footer-bottom"> <a href="' . $main_page->escapeLocalURL() . '" rel="nofollow">' . wfMsg('mainpage') . '</a> <a href="' . $about->escapeLocalURL() . '" rel="nofollow">' . wfMsg('about') . '</a> <a href="' . $special->escapeLocalURL() . '" rel="nofollow">' . wfMsg('specialpages') . '</a> <a href="' . $help->escapeLocalURL() . '" rel="nofollow">' . wfMsg('help') . '</a> <a href="' . $disclaimerPage->escapeLocalURL() . '" rel="nofollow">' . wfMsg('disclaimers') . '</a>'; // "Advertise" link on the footer, but only if a URL has been specified // in the MediaWiki:Nimbus-advertise-url system message $adURL = trim(wfMsgForContent('nimbus-advertise-url')); if (!wfEmptyMsg('nimbus-advertise-url', $adURL)) { $footer .= '<a href="' . $adURL . '" rel="nofollow">' . wfMsg('nimbus-advertise') . '</a>'; } $footer .= '</div>' . "\n"; return $footer; }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserLevels, $wgUploadPath, $wgScriptPath; // Load CSS $wgOut->addExtensionStyle($wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css'); $periodFromRequest = $wgRequest->getVal('period'); if ($periodFromRequest == 'weekly') { $period = 'weekly'; } elseif ($periodFromRequest == 'monthly') { $period = 'monthly'; } if (!isset($period)) { $period = 'weekly'; } if ($period == 'weekly') { $wgOut->setPageTitle(wfMsg('user-stats-weekly-title')); } else { $wgOut->setPageTitle(wfMsg('user-stats-monthly-title')); } $count = 50; $user_list = array(); // Try cache $key = wfMemcKey('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) { $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'); $out = '<div class="top-fan-nav"> <h1>' . wfMsg('top-fans-by-points-nav-header') . '</h1> <p><a href="' . $top_title->escapeFullURL() . '">' . wfMsg('top-fans-total-points-link') . '</a></p>'; if ($period == 'weekly') { $out .= '<p><a href="' . $recent_title->escapeFullURL('period=monthly') . '">' . wfMsg('top-fans-monthly-points-link') . '</a><p> <p><b>' . wfMsg('top-fans-weekly-points-link') . '</b></p>'; } else { $out .= '<p><b>' . wfMsg('top-fans-monthly-points-link') . '</b><p> <p><a href="' . $recent_title->escapeFullURL('period=weekly') . '">' . wfMsg('top-fans-weekly-points-link') . '</a></p>'; } // Build nav of stats by category based on MediaWiki:Topfans-by-category $by_category_title = SpecialPage::getTitleFor('TopFansByStatistic'); $nav = array(); $lines = explode("\n", wfMsgForContent('topfans-by-category')); if (count($lines) > 0) { $out .= '<h1 style="margin-top:15px !important;">' . wfMsg('top-fans-by-category-nav-header') . '</h1>'; } foreach ($lines as $line) { if (strpos($line, '*') !== 0) { continue; } else { $line = explode('|', trim($line, '* '), 2); $stat = $line[0]; $link_text = $line[1]; $out .= '<p><a href="' . $by_category_title->escapeFullURL("stat={$stat}") . '">' . $link_text . '</a></p>'; } } $out .= '</div>'; $x = 1; $out .= '<div class="top-users">'; foreach ($user_list as $user) { $user_title = Title::makeTitle(NS_USER, $user['user_name']); $avatar = new wAvatar($user['user_id'], 'm'); $commentIcon = $avatar->getAvatarImage(); $out .= '<div class="top-fan-row"> <span class="top-fan-num">' . $x . '.</span> <span class="top-fan"> <img src="' . $wgUploadPath . '/avatars/' . $commentIcon . '" alt="" border="" /> <a href="' . $user_title->escapeFullURL() . '" >' . $user['user_name'] . '</a> </span>'; $out .= '<span class="top-fan-points"><b>' . number_format($user['points']) . '</b> ' . wfMsg('top-fans-points') . '</span>'; $out .= '<div class="cleared"></div>'; $out .= '</div>'; $x++; } $out .= '</div><div class="cleared"></div>'; $wgOut->addHTML($out); }
/** * Get the avatars of the people who recently edited this blog post, if * this feature is enabled in BlogPage config. * * @return String: HTML or nothing */ function recentEditors() { global $wgUploadPath, $wgBlogPageDisplay; if ($wgBlogPageDisplay['recent_editors'] == false) { return ''; } $editors = $this->getEditorsList(); $output = ''; if (count($editors) > 0) { $output .= '<div class="recent-container"> <h2>' . wfMsg('blog-recent-editors') . '</h2> <div>' . wfMsg('blog-recent-editors-message') . '</div>'; foreach ($editors as $editor) { $avatar = new wAvatar($editor['user_id'], 'm'); $userTitle = Title::makeTitle(NS_USER, $editor['user_name']); $output .= '<a href="' . $userTitle->escapeFullURL() . "\"><img src=\"{$wgUploadPath}/avatars/{$avatar->getAvatarImage()}\" alt=\"" . $userTitle->getText() . '" border="0" /></a>'; } $output .= '</div>'; } return $output; }
/** * search for avatar of the username $editorName. * * If the avatar is in jpg and the option $wgCollaborationDiagramConvertToPNG set to true then * all avatars that are not in PNG will be converted to PNG with ImageMagick program set in $wgImageMagickConvertCommand variable * @param $editorName * @return string */ private function printGuyPicture($editorName) { $user = User::newFromName($editorName); if ($user == false) { return ''; } else { global $IP, $wgCollaborationDiagramConvertToPNG, $wgImageMagickConvertCommand, $wgUseImageMagick; $avatar = new wAvatar($user->getId(), 'l'); $tmpArr = explode('?r=', $avatar->getAvatarImage()); $avatarImage = $tmpArr[0]; $avatarWithPath = "{$IP}/images/avatars/{$avatarImage}"; if ($wgCollaborationDiagramConvertToPNG == true && $wgUseImageMagick == true && isset($wgImageMagickConvertCommand)) { exec($wgImageMagickConvertCommand . " " . $avatarWithPath . " " . substr_replace($avatarWithPath, 'png', -3)); ///probably code injection possible here!!! $avatarWithPath = substr_replace($avatarWithPath, 'png', -3); } $pictureWithLabel = "[label=<\n<table border=\"0\">\n <tr>\n <td><img src=\"{$avatarWithPath}\" /></td>\n </tr>\n <tr>\n <td>{$editorName}</td>\n </tr>\n</table>>]"; return $this->drawUserNode($editorName) . $pictureWithLabel; } }
private function setFile($file) { global $wgUploadDirectory, $wgAvatarKey, $wgMemc, $wgUser, $wgSiteAvatarKey, $wgHuijiPrefix; if (!$this->isUserAvatar) { $uid = $wgHuijiPrefix; $avatarKey = $wgSiteAvatarKey; $avatar = new wSiteAvatar($uid, 'l'); } else { $uid = $wgUser->getId(); $avatarKey = $wgAvatarKey; $avatar = new wAvatar($uid, 'l'); } // $dest = $this->avatarUploadDirectory; $imageInfo = getimagesize($file->getTempName()); $errorCode = $file->getError(); if ($errorCode === UPLOAD_ERR_OK) { $type = exif_imagetype($file->getTempName()); if ($type) { $extension = image_type_to_extension($type); $src = $this->avatarUploadDirectory . '/' . date('YmdHis') . '.original' . $extension; if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) { if (file_exists($src)) { unlink($src); } // If this is the user's first custom avatar, update statistics (in // case if we want to give out some points to the user for uploading // their first avatar) if ($this->isUserAvatar && strpos($avatar->getAvatarImage(), 'default_') !== false) { $stats = new UserStatsTrack($uid, $wgUser->getName()); $stats->incStatField('user_image'); } $this->createThumbnail($file->getTempName(), $imageInfo, $avatarKey . '_' . $uid . '_l', 200); $this->createThumbnail($file->getTempName(), $imageInfo, $avatarKey . '_' . $uid . '_ml', 50); $this->createThumbnail($file->getTempName(), $imageInfo, $avatarKey . '_' . $uid . '_m', 30); $this->createThumbnail($file->getTempName(), $imageInfo, $avatarKey . '_' . $uid . '_s', 16); switch ($imageInfo[2]) { case 1: $ext = 'gif'; break; case 2: $ext = 'jpg'; break; case 3: $ext = 'png'; break; default: return $this->msg = '请上传如下类型的图片: JPG, PNG, GIF(错误代码:14)'; } $this->cleanUp($ext, $avatarKey, $uid); /* I know this is bad but whatever */ $result = true; if ($result) { $this->src = $src; $this->type = $type; $this->extension = $extension; //$this -> setDst(); } else { $this->msg = '无法保存文件(错误代码:13)'; } } else { $this->msg = '请上传如下类型的图片: JPG, PNG, GIF(错误代码:12)'; } } else { $this->msg = '请上传一个图片文件(错误代码:11)'; } } else { $this->msg = $this->codeToMessage($errorCode); } }
/** * Create the thumbnails and delete old files */ public function performUpload( $comment, $pageText, $watch, $user ) { global $wgUploadDirectory, $wgUser, $wgDBname, $wgMemc; $this->avatarUploadDirectory = $wgUploadDirectory . '/avatars'; $imageInfo = getimagesize( $this->mTempPath ); switch ( $imageInfo[2] ) { case 1: $ext = 'gif'; break; case 2: $ext = 'jpg'; break; case 3: $ext = 'png'; break; default: return Status::newFatal( 'filetype-banned-type' ); } $dest = $this->avatarUploadDirectory; $uid = $wgUser->getId(); $avatar = new wAvatar( $uid, 'l' ); // If this is the user's first custom avatar, update statistics (in // case if we want to give out some points to the user for uploading // their first avatar) if ( strpos( $avatar->getAvatarImage(), 'default_' ) !== false ) { $stats = new UserStatsTrack( $uid, $wgUser->getName() ); $stats->incStatField( 'user_image' ); } $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $uid . '_l', 75 ); $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $uid . '_ml', 50 ); $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $uid . '_m', 30 ); $this->createThumbnail( $this->mTempPath, $imageInfo, $wgDBname . '_' . $uid . '_s', 16 ); if ( $ext != 'jpg' ) { if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.jpg' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.jpg' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.jpg' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.jpg' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.jpg' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.jpg' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.jpg' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.jpg' ); } } if ( $ext != 'gif' ) { if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.gif' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.gif' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.gif' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.gif' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.gif' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.gif' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.gif' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.gif' ); } } if ( $ext != 'png' ) { if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.png' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_s.png' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.png' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_m.png' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.png' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_l.png' ); } if ( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.png' ) ) { unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $uid . '_ml.png' ); } } $key = wfMemcKey( 'user', 'profile', 'avatar', $uid, 's' ); $data = $wgMemc->delete( $key ); $key = wfMemcKey( 'user', 'profile', 'avatar', $uid, 'm' ); $data = $wgMemc->delete( $key ); $key = wfMemcKey( 'user', 'profile', 'avatar', $uid , 'l' ); $data = $wgMemc->delete( $key ); $key = wfMemcKey( 'user', 'profile', 'avatar', $uid, 'ml' ); $data = $wgMemc->delete( $key ); $this->mExtension = $ext; return Status::newGood(); }
/** * How many % of this user's profile is complete? * Currently unused, I think that this might've been used in some older * ArmchairGM code, but this looks useful enough to be kept around. * * @return Integer */ public function getProfileComplete() { global $wgUser; $complete_count = 0; // Check all profile fields $profile = $this->getProfile(); foreach ( $this->profile_fields as $field ) { if ( $profile[$field] ) { $complete_count++; } $this->profile_fields_count++; } // Check if the user has a non-default avatar $this->profile_fields_count++; $avatar = new wAvatar( $wgUser->getID(), 'l' ); if ( strpos( $avatar->getAvatarImage(), 'default_' ) === false ) { $complete_count++; } return round( $complete_count / $this->profile_fields_count * 100 ); }
/** * This is currently unused, seems to be a leftover from the ArmchairGM * days. * * @param $user_name String: user name * @return String: HTML */ function getProfileImage($user_name) { global $wgUser; $avatar = new wAvatar($this->user_id, 'l'); $avatarTitle = SpecialPage::getTitleFor('UploadAvatar'); $output = '<div class="profile-image">'; if ($wgUser->getName() == $this->user_name) { if (strpos($avatar->getAvatarImage(), 'default_') != false) { $caption = 'upload image'; } else { $caption = 'new image'; } $output .= '<a href="' . htmlspecialchars($avatarTitle->getFullURL()) . '" rel="nofollow">' . $avatar->getAvatarURL() . '<br /> (' . $caption . ') </a>'; } else { $output .= $avatar->getAvatarURL(); } $output .= '</div></div>'; return $output; }
public function updateAvatar() { global $wgUploadPath, $wgServer, $wgUser; $avatar = new wAvatar($wgUser->getID(), 'l'); $imageURL = $wgServer . '/' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage(); $this->Avatar = $imageURL; }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ) { global $wgRequest, $wgOut, $wgUploadPath, $wgScriptPath; // Add CSS & JS if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) { $wgOut->addModules( 'ext.quizGame' ); } else { $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/QuizGame/questiongame.css' ); $wgOut->addScriptFile( $wgScriptPath . '/extensions/QuizGame/js/QuizGame.js' ); } // Page either most or newest for everyone $type = $wgRequest->getVal( 'type' ); if( !$type ) { $type = 'newest'; } if( $type == 'newest' ) { $order = 'q_date'; } if( $type == 'most' ) { $order = 'q_answer_count'; } // Pagination $per_page = 20; $page = $wgRequest->getInt( 'page', 1 ); $limit = $per_page; $limitvalue = 0; // OFFSET for SQL queries if ( $limit > 0 && $page ) { $limitvalue = $page * $limit - ( $limit ); } $quizGameHome = SpecialPage::getTitleFor( 'QuizGameHome' ); $output = '<div class="view-quizzes-top-links"> <a href="' . $quizGameHome->escapeFullURL( 'questionGameAction=launchGame' ) . '">' . wfMsg( 'quiz-playneverending' ) . '</a> - <a href="' . $quizGameHome->escapeFullURL( 'questionGameAction=createForm' ) . '">' . wfMsg( 'quiz-viewquizzes-create' ) . '</a> <br /><br /> </div> <div class="view-quizzes-navigation"> <h2>' . wfMsg( 'quiz-leaderboard-order-menu' ) . '</h2>'; $dbr = wfGetDB( DB_MASTER ); $where = array(); $where[] = 'q_flag <> ' . QUIZGAME_FLAG_FLAGGED; // Display only a user's most or newest $user = $wgRequest->getVal( 'user' ); $user_link = ''; if ( $user ) { $where['q_user_name'] = $user; $user_link = '&user='******'newest' ) { $output .= '<p><b>' . wfMsg( 'quiz-newest' ) . '</b></p> <p><a href="' . $wgScriptPath . "/index.php?title=Special:ViewQuizzes&type=most{$user_link}\">" . wfMsg( 'quiz-popular' ) . '</a></p>'; } else { $output .= '<p><a href="' . $wgScriptPath . "/index.php?title=Special:ViewQuizzes&type=newest{$user_link}\">" . wfMsg( 'quiz-newest' ) . '</a></p> <p><b>' . wfMsg( 'quiz-popular' ) . '</b></p>'; } $output .= '</div>'; if ( $user ) { $wgOut->setPageTitle( wfMsg( 'quiz-viewquizzes-title-by-user', $user ) ); } else { $wgOut->setPageTitle( wfMsg( 'quiz-viewquizzes-title' ) ); } $res = $dbr->select( 'quizgame_questions', array( 'q_id', 'q_user_id', 'q_user_name', 'q_text', 'UNIX_TIMESTAMP(q_date) AS quiz_date', 'q_picture', 'q_answer_count' ), $where, __METHOD__, array( 'ORDER BY' => "$order DESC", 'LIMIT' => $limit, 'OFFSET' => $limitvalue ) ); $res_total = $dbr->select( 'quizgame_questions', 'COUNT(*) AS total_quizzes', $where, __METHOD__ ); $row_total = $dbr->fetchObject( $res_total ); $total = $row_total->total_quizzes; $output .= '<div class="view-quizzes">'; $x = ( ( $page - 1 ) * $per_page ) + 1; foreach ( $res as $row ) { $user_create = $row->q_user_name; $user_id = $row->q_user_id; $avatar = new wAvatar( $user_id, 'm' ); $quiz_title = $row->q_text; $quiz_date = $row->quiz_date; $quiz_answers = $row->q_answer_count; $quiz_id = $row->q_id; $row_id = "quizz-row-{$x}"; $url = $quizGameHome->escapeFullURL( array( 'questionGameAction' => 'renderPermalink', 'permalinkID' => $quiz_id ) ); $startHover = "QuizGame.doHover('{$row_id}')"; $endHover = "QuizGame.endHover('{$row_id}')"; if ( ( $x < $total ) && ( $x % $per_page != 0 ) ) { $output .= "<div class=\"view-quizzes-row\" id=\"{$row_id}\" onmouseover=\"{$startHover}\" onmouseout=\"{$endHover}\" onclick=\"window.location='" . $url . '\'">'; } else { $output .= "<div class=\"view-quizzes-row-bottom\" id=\"{$row_id}\" onmouseover=\"{$startHover}\" onmouseout=\"{$endHover}\" onclick=\"window.location='" . $url . '\'">'; } $output .= "<div class=\"view-quizzes-number\">{$x}.</div> <div class=\"view-quizzes-user-image\"><img src=\"{$wgUploadPath}/avatars/{$avatar->getAvatarImage()}\" alt=\"\" /></div> <div class=\"view-quizzes-user-name\">{$user_create}</div> <div class=\"view-quizzes-text\"> <p><b><u>{$quiz_title}</u></b></p> <p class=\"view-quizzes-num-answers\">" . wfMsgExt( 'quiz-answered', 'parsemag', $quiz_answers ) . '</p> <p class="view-quizzes-time">(' . wfMsg( 'quiz-ago', self::getTimeAgo( $quiz_date ) ) . ')</p> </div> <div class="cleared"></div> </div>'; $x++; } $output .= '</div> <div class="cleared"></div>'; $numofpages = $total / $per_page; if( $numofpages > 1 ) { $output .= '<div class="view-quizzes-page-nav">'; if( $page > 1 ) { $output .= '<a href="' . $wgScriptPath . "/index.php?title=Special:ViewQuizzes&type=most{$user_link}&page=" . ( $page - 1 ) . '">' . wfMsg( 'quiz-prev' ) . '</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="' . $wgScriptPath . "/index.php?title=Special:ViewQuizzes&type=most{$user_link}&page=$i\">$i</a> "; } } if( ( $total - ( $per_page * $page ) ) > 0 ) { $output .= ' <a href="' . $wgScriptPath . "/index.php?title=Special:ViewQuizzes&type=most{$user_link}&page=" . ( $page + 1 ) . '">' . wfMsg( 'quiz-nav-next' ) . '</a>'; } $output .= '</div>'; } $wgOut->addHTML( $output ); }
/** * Displays the form for adding a friend or a foe * @return $form Mixed: HTML code for the form */ function displayForm() { global $wgOut, $wgUploadPath; if ($this->relationship_type == 1) { $wgOut->setPageTitle(wfMsg('ur-add-title-friend', $this->user_name_to)); $add = wfMsg('ur-add-message-friend', $this->user_name_to); $button = wfMsg('ur-add-button-friend'); } else { $wgOut->setPageTitle(wfMsg('ur-add-title-foe', $this->user_name_to)); $add = wfMsg('ur-add-message-foe', $this->user_name_to); $button = wfMsg('ur-add-button-foe'); } $avatar = new wAvatar($this->user_id_to, 'l'); $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />'; $form = "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"form1\">\r\n\t\t\t<div class=\"relationship-action\">\r\n\t\t\t{$avatar_img}\r\n\t\t\t" . $add . '<div class="cleared"></div> </div> <div class="relationship-textbox-title">' . wfMsg('ur-add-personal-message') . '</div> <textarea name="message" id="message" rows="3" cols="50"></textarea> <div class="relationship-buttons"> <input type="button" class="site-button" value="' . $button . '" size="20" onclick="document.form1.submit()" /> <input type="button" class="site-button" value="' . wfMsg('ur-cancel') . '" size="20" onclick="history.go(-1)" /> </div> </form>'; return $form; }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUser, $wgOut, $wgRequest, $wgUploadPath, $wgUserGiftsScripts; $wgOut->addExtensionStyle($wgUserGiftsScripts . '/UserGifts.css'); $giftId = $wgRequest->getInt('gift_id'); if (!$giftId || !is_numeric($giftId)) { $wgOut->setPageTitle(wfMsg('g-error-title')); $wgOut->addHTML(wfMsg('g-error-message-invalid-link')); return false; } $gift = UserGifts::getUserGift($giftId); if ($gift) { if ($gift['status'] == 1) { if ($gift['user_name_to'] == $wgUser->getName()) { $g = new UserGifts($gift['user_name_to']); $g->clearUserGiftStatus($gift['id']); $g->decNewGiftCount($wgUser->getID()); } } // DB stuff $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('user_gift', array('DISTINCT ug_user_name_to', 'ug_user_id_to', 'ug_date'), array('ug_gift_id' => $gift['gift_id'], "ug_user_name_to <> '" . addslashes($gift['user_name_to']) . "'"), __METHOD__, array('GROUP BY' => 'ug_user_name_to', 'ORDER BY' => 'ug_date DESC', 'LIMIT' => 6)); $wgOut->setPageTitle(wfMsgExt('g-description-title', 'parsemag', $gift['user_name_to'], $gift['name'])); $output = '<div class="back-links"> <a href="' . Title::makeTitle(NS_USER, $gift['user_name_to'])->escapeFullURL() . '">' . wfMsg('g-back-link', $gift['user_name_to']) . '</a> </div>'; $user = Title::makeTitle(NS_USER, $gift['user_name_from']); $removeGiftLink = SpecialPage::getTitleFor('RemoveGift'); $giveGiftLink = SpecialPage::getTitleFor('GiveGift'); $avatar = new wAvatar($gift['user_id_from'], 's'); $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />'; $giftImage = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt="" />'; $message = $wgOut->parse(trim($gift['message']), false); $output .= '<div class="g-description-container">'; $output .= '<div class="g-description">' . $giftImage . '<div class="g-name">' . $gift['name'] . '</div> <div class="g-timestamp">(' . $gift['timestamp'] . ')</div> <div class="g-from">' . wfMsg('g-from', $user->escapeFullURL(), $gift['user_name_from']) . '</div>'; if ($message) { $output .= '<div class="g-user-message">' . $message . '</div>'; } $output .= '<div class="cleared"></div> <div class="g-describe">' . $gift['description'] . '</div> <div class="g-actions"> <a href="' . $giveGiftLink->escapeFullURL('gift_id=' . $gift['gift_id']) . '">' . wfMsg('g-to-another') . '</a>'; if ($gift['user_name_to'] == $wgUser->getName()) { $output .= ' '; $output .= wfMsgExt('pipe-separator', 'escapenoentities'); $output .= ' '; $output .= '<a href="' . $removeGiftLink->escapeFullURL('gift_id=' . $gift['id']) . '">' . wfMsg('g-remove-gift') . '</a>'; } $output .= '</div> </div>'; $output .= '<div class="g-recent"> <div class="g-recent-title">' . wfMsg('g-recent-recipients') . '</div> <div class="g-gift-count">' . wfMsgExt('g-given', 'parsemag', $gift['gift_count']) . '</div>'; foreach ($res as $row) { $userToId = $row->ug_user_id_to; $avatar = new wAvatar($userToId, 'ml'); $userNameLink = Title::makeTitle(NS_USER, $row->ug_user_name_to); $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('g-error-title')); $wgOut->addHTML(wfMsg('g-error-message-invalid-link')); } }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgOut, $wgScriptPath, $wgMemc, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserLevels, $wgUploadPath; // Load CSS $wgOut->addExtensionStyle($wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css'); $wgOut->setPageTitle(wfMsg('user-stats-alltime-title')); $count = 100; $realcount = 50; $user_list = array(); // Try cache $key = wfMemcKey('user_stats', 'top', 'points', $realcount); $data = $wgMemc->get($key); if ($data != '') { wfDebug("Got top users by points ({$count}) from cache\n"); $user_list = $data; } else { wfDebug("Got top users by points ({$count}) from DB\n"); $params['ORDER BY'] = 'stats_total_points DESC'; $params['LIMIT'] = $count; $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('user_stats', array('stats_user_id', 'stats_user_name', 'stats_total_points'), array('stats_user_id <> 0'), __METHOD__, $params); $loop = 0; foreach ($res as $row) { $user = User::newFromId($row->stats_user_id); if (!$user->isBlocked()) { $user_list[] = array('user_id' => $row->stats_user_id, 'user_name' => $row->stats_user_name, 'points' => $row->stats_total_points); $loop++; } if ($loop >= 50) { break; } } $wgMemc->set($key, $user_list, 60 * 5); } $recent_title = SpecialPage::getTitleFor('TopUsersRecent'); $out = '<div class="top-fan-nav"> <h1>' . wfMsg('top-fans-by-points-nav-header') . '</h1> <p><b>' . wfMsg('top-fans-total-points-link') . '</b></p>'; if ($wgUserStatsTrackWeekly) { $out .= '<p><a href="' . $recent_title->escapeFullURL('period=monthly') . '">' . wfMsg('top-fans-monthly-points-link') . '</a></p>'; } if ($wgUserStatsTrackMonthly) { $out .= '<p><a href="' . $recent_title->escapeFullURL('period=weekly') . '">' . wfMsg('top-fans-weekly-points-link') . '</a></p>'; } // Build nav of stats by category based on MediaWiki:Topfans-by-category $by_category_title = SpecialPage::getTitleFor('TopFansByStatistic'); $byCategoryMessage = wfMsgForContent('topfans-by-category'); $lines = explode("\n", $byCategoryMessage); if (count($lines) > 0 && !wfEmptyMsg('topfans-by-category', $byCategoryMessage)) { $out .= '<h1 style="margin-top:15px !important;">' . wfMsg('top-fans-by-category-nav-header') . '</h1>'; } foreach ($lines as $line) { if (strpos($line, '*') !== 0) { continue; } else { $line = explode('|', trim($line, '* '), 2); $stat = $line[0]; $link_text = $line[1]; $out .= '<p> <a href="' . $by_category_title->escapeFullURL("stat={$stat}") . "\">{$link_text}</a></p>"; } } $out .= '</div>'; $x = 1; $out .= '<div class="top-users">'; $last_level = ''; foreach ($user_list as $user) { $user_title = Title::makeTitle(NS_USER, $user['user_name']); $avatar = new wAvatar($user['user_id'], 'm'); $commentIcon = $avatar->getAvatarImage(); // Break list into sections based on User Level if it's defined for this site if (is_array($wgUserLevels)) { $user_level = new UserLevel(number_format($user['points'])); if ($user_level->getLevelName() != $last_level) { $out .= "<div class=\"top-fan-row\"><div class=\"top-fan-level\">\r\n\t\t\t\t\t\t{$user_level->getLevelName()}\r\n\t\t\t\t\t\t</div></div>"; } $last_level = $user_level->getLevelName(); } $out .= "<div class=\"top-fan-row\">\r\n\t\t\t\t<span class=\"top-fan-num\">{$x}.</span>\r\n\t\t\t\t<span class=\"top-fan\">\r\n\t\t\t\t\t<img src='{$wgUploadPath}/avatars/" . $commentIcon . "' alt='' border='' /> <a href='" . $user_title->escapeFullURL() . "'>" . $user['user_name'] . '</a> </span>'; $out .= '<span class="top-fan-points"><b>' . number_format($user['points']) . '</b> ' . wfMsg('top-fans-points') . '</span>'; $out .= '<div class="cleared"></div>'; $out .= '</div>'; $x++; } $out .= '</div><div class="cleared"></div>'; $wgOut->addHTML($out); }
/** * Main function to render a quiz game. * Also handles rendering a permalink. */ function launchGame() { global $wgRequest, $wgUser, $wgOut, $wgUploadPath, $wgScriptPath, $wgHooks; $on_load = 'QuizGame.showAnswers();'; // controls the maximum length of the previous game bar graphs $dbr = wfGetDB( DB_MASTER ); // previously this used to use addslashes + getVal and there was a var // called $isPermalink which was just an is_numeric() on this var // The if() loop around line 778 checked for $isPermalink instead of // $permalinkID...which caused a bug (wrong msg) to be displayed when // there were no questions *at all* in the DB (the permalink error msg // does not have a link that allows you to *create* a quiz...) $permalinkID = $wgRequest->getInt( 'permalinkID', 0 ); $lastid = addslashes( $wgRequest->getVal( 'lastid' ) ); $skipid = addslashes( $wgRequest->getVal( 'skipid' ) ); $isFixedlink = false; $permalinkOptions = -1; $backButton = ''; $editMenu = ''; $editLinks = ''; // Logged in user's stats $stats = new UserStats( $wgUser->getID(), $wgUser->getName() ); $current_user_stats = $stats->getUserStats(); if( !$current_user_stats['quiz_points'] ) { $current_user_stats['quiz_points'] = 0; } // Get users rank $quiz_rank = 0; $s = $dbr->selectRow( 'user_stats', array( 'COUNT(*) AS count' ), array( 'stats_quiz_points > ' . str_replace( ',', '', $current_user_stats['quiz_points'] ) ), __METHOD__ ); if ( $s !== false ) { $quiz_rank = $s->count + 1; } // This is assuming that lastId and permalinkId // are mutually exclusive if( $permalinkID ) { $question = $this->getQuestion( $permalinkID ); if( !$question ) { $this->renderPermalinkError(); return ''; } } else { $question = $this->getQuestion( $this->getNextQuestion(), $skipid ); if( !$question ) { $this->renderQuizOver(); return ''; } } global $wgQuizID; $wgQuizID = $question['id']; $timestampedViewed = 0; if( $wgUser->getName() != $question['user_name'] ) { // check to see if the user already had viewed this question global $wgMemc; $key = wfMemcKey( 'quizgame-user-view', $wgUser->getID(), $question['id'] ); $data = $wgMemc->get( $key ); if( $data > 0 ) { $timestampedViewed = $data; } else { // mark that they viewed for first time $wgMemc->set( $key, time() ); } $on_load .= "QuizGame.countDown({$timestampedViewed});"; } if ( is_numeric( $lastid ) ) { $prev_question = $this->getQuestion( $lastid ); } $wgOut->addScript( "<script type=\"text/javascript\">addOnloadHook( function() {" . $on_load . "} );</script>\n" ); $gameid = $question['id']; $wgOut->setPageTitle( $question['text'] ); if( strlen( $question['image'] ) > 0 ) { $image = wfFindFile( $question['image'] ); $imageThumb = ''; $imgWidth = 0; // If a file that is still being used on a quiz game is // independently deleted from the quiz game, poor users will // stumble upon nasty fatals without this check here. if ( is_object( $image ) ) { $imageThumb = $image->createThumb( 160 ); $imageThumb .= '?' . time(); if ( $image->getWidth() >= 160 ) { $imgWidth = 160; } else { $imgWidth = $image->getWidth(); } } $imageTag = " <div id=\"quizgame-picture\" class=\"quizgame-picture\"> <img src='" . $imageThumb . "' width='" . $imgWidth . "'></div>"; } else { $imageTag = ''; } $key = md5( $this->SALT . $gameid ); $user_name = $question['user_name']; $user_title = Title::makeTitle( NS_USER, $user_name ); $id = $question['user_id']; $avatar = new wAvatar( $id, 'l' ); $avatarID = $avatar->getAvatarImage(); $stats = new UserStats( $id, $user_name ); $stats_data = $stats->getUserStats(); $user_answer = $this->userAnswered( $wgUser->getName(), $gameid ); global $wgUseEditButtonFloat; if ( ( $wgUser->getID() == $question['user_id'] || ( $user_answer && $wgUser->isLoggedIn() && $wgUser->isAllowed( 'quizadmin' ) ) || $wgUser->isAllowed( 'quizadmin' ) ) && ( $wgUseEditButtonFloat == true ) ) { $editMenu = " <div class=\"edit-menu-quiz-game\"> <div class=\"edit-button-quiz-game\"> <img src=\"{$wgScriptPath}/extensions/QuizGame/images/editIcon.gif\" alt=\"\" /> <a href=\"javascript:QuizGame.showEditMenu()\">" . wfMsg( 'quiz-edit' ) . "</a> </div> </div>"; $editLinks = ' <a href="' . $this->getTitle()->escapeFullURL( 'questionGameAction=adminPanel' ) . '">' . wfMsg( 'quiz-admin-panel-title' ) . '</a> - <a href="javascript:QuizGame.protectImage()">' . wfMsg( 'quiz-protect' ) . '</a> - <a href="javascript:QuizGame.deleteQuestion()">' . wfMsg( 'quiz-delete' ) . '</a> -'; } if( $wgUser->isLoggedIn() ) { $leaderboard_title = SpecialPage::getTitleFor( 'QuizLeaderboard' ); $stats_box = '<div class="user-rank"> <h2>' . wfMsg( 'quiz-leaderboard-scoretitle' ) . '</h2> <p><b>' . wfMsg( 'quiz-leaderboard-quizpoints' ) . "</b></p> <p class=\"user-rank-points\">{$current_user_stats['quiz_points']}</p> <div class=\"cleared\"></div> <p><b>" . wfMsg( 'quiz-leaderboard-correct' ) . "</b></p> <p>{$current_user_stats['quiz_correct']}</p> <div class=\"cleared\"></div> <p><b>" . wfMsg( 'quiz-leaderboard-answered' ) . "</b></p> <p>{$current_user_stats['quiz_answered']}</p> <div class=\"cleared\"></div> <p><b>" . wfMsg( 'quiz-leaderboard-pctcorrect' ) . "</b></p> <p>{$current_user_stats['quiz_correct_percent']}%</p> <div class=\"cleared\"></div> <p><b>" . wfMsg( 'quiz-leaderboard-rank' ) . "</b></p> <p>{$quiz_rank} <span class=\"user-rank-link\"> <a href=\"{$leaderboard_title->getFullURL()}\">(" . wfMsg( 'quiz-leaderboard-link' ) . ")</a> </span></p> <div class=\"cleared\"></div> </div>"; } else { $stats_box = '<div class="user-rank"> <h2>' . wfMsg( 'quiz-leaderboard-scoretitle' ) . '</h2>' . wfMsgExt( 'quiz-login-or-create-to-climb', 'parse' ) . '</div>'; } $answers = ''; if( $user_answer ) { $answers .= "<div class=\"answer-percent-correct\">{$question['correct_percent']}" . wfMsg( 'quiz-pct-answered-correct' ) . '</div>'; if( $user_answer == $question['correct_answer'] ) { $answers .= '<div class="answer-message-correct">' . wfMsg( 'quiz-answered-correctly' ) . '</div>'; } else { if( $user_answer == -1 ) { $answers .= '<div class="answer-message-incorrect">' . wfMsg( 'quiz-skipped' ) . '</div>'; } else { $answers .= '<div class="answer-message-incorrect">' . wfMsg( 'quiz-answered-incorrectly' ) . '</div>'; } } } // User hasn't answered yet, so display the quiz options with the ability to play the question if( !$user_answer && $wgUser->getName() != $question['user_name'] ) { $answers .= '<ul>'; $x = 1; foreach( $question['choices'] as $choice ) { $answers .= "<li id=\"{$x}\"><a href=\"javascript:QuizGame.vote({$choice['id']});\">{$choice['text']}</a></li>"; $x++; } $answers .= '</ul>'; } else { // User has answered, so display the right answer, and how many // people picked what $x = 1; foreach( $question['choices'] as $choice ) { $bar_width = floor( 220 * ( $choice['percent'] / 100 ) ); if ( $choice['is_correct'] == 1 ) { $barColor = 'green'; } else { $barColor = 'red'; } $incorrectMsg = $correctMsg = ''; if ( $user_answer == $choice['id'] && $question['correct_answer'] != $choice['id'] ) { $incorrectMsg = '- <span class="answer-message-incorrect">' . wfMsg( 'quiz-your-answer' ) . '</span>'; } if ( $question['correct_answer'] == $choice['id'] ) { $correctMsg = '- <span class="answer-message-correct">' . wfMsg( 'quiz-correct-answer' ) . '</span>'; } $answers .= "<div id=\"{$x}\" class=\"answer-choice\">{$choice['text']}" . $incorrectMsg . $correctMsg . '</div>'; $answers .= "<div id=\"one-answer-bar\" style=\"margin-bottom:10px;\" class=\"answer-" . $barColor . "\"> <img border=\"0\" style=\"width:{$bar_width}px; height: 9px;\" id=\"one-answer-width\" src=\"{$wgScriptPath}/extensions/QuizGame/images/vote-bar-" . $barColor . ".gif\"/> <span class=\"answer-percent\">{$choice['percent']}%</span> </div>"; $x++; } } if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) { $wgOut->addModules( 'ext.quizGame.lightBox' ); } else { $wgOut->addScriptFile( $wgScriptPath . '/extensions/QuizGame/js/LightBox.js' ); } $wgHooks['MakeGlobalVariablesScript'][] = 'QuizGameHome::addJSGlobals'; $output = " <div id=\"quizgame-container\" class=\"quizgame-container\"> {$editMenu}"; $output .= "<div class=\"quizgame-left\"> <div id=\"quizgame-title\" class=\"quizgame-title\"> {$question['text']} </div>"; if( !$user_answer && $wgUser->getName() != $question['user_name'] ) { global $wgUserStatsPointValues; $output .= '<div class="time-box"> <div class="quiz-countdown"> <span id="time-countdown">-</span> ' . wfMsg( 'quiz-js-seconds' ) . '</div> <div class="quiz-points" id="quiz-points">' . wfMsg( 'quiz-points', $wgUserStatsPointValues['quiz_points'] ) . '</div> <div class="quiz-notime" id="quiz-notime"></div> </div>'; } $output .= '<div class="ajax-messages" id="ajax-messages"></div>'; $output .= " {$imageTag} <div id=\"loading-answers\">" . wfMsg( 'quiz-js-loading' ) . "</div> <div id=\"quizgame-answers\" style=\"display:none;\" class=\"quizgame-answers\"> {$answers} </div> <form name=\"quizGameForm\" id=\"quizGameForm\"> <input id=\"quizGameId\" name=\"quizGameId\" type=\"hidden\" value=\"{$gameid}\" /> <input id=\"quizGameKey\" name=\"quizGameKey\" type=\"hidden\" value=\"{$key}\" /> </form> <div class=\"navigation-buttons\"> {$backButton}"; if( !$user_answer && $wgUser->getName() != $question['user_name'] ) { $output .= '<a href="javascript:void(0);" onclick="javascript:QuizGame.skipQuestion();">' . wfMsg( 'quiz-skip' ) . '</a>'; } else { $output .= '<a href="' . $this->getTitle()->escapeFullURL( 'questionGameAction=launchGame' ) . '">' . wfMsg( 'quiz-next' ) . '</a>'; } $output .= '</div>'; if( !empty( $prev_question['id'] ) && !empty( $prev_question['user_answer'] ) ) { $output .= '<div id="answer-stats" class="answer-stats" style="display:block"> <div class="last-game"> <div class="last-question-heading">' . wfMsg( 'quiz-last-question' ) . ' - <a href="' . $this->getTitle()->escapeFullURL( "questionGameAction=renderPermalink&permalinkID={$prev_question['id']}" ) . "\">{$prev_question['text']}</a> <div class=\"last-question-count\">" . wfMsg( 'quiz-times-answered', $prev_question['answer_count'] ) . '</div> </div>'; $your_answer_status = ''; if( $prev_question['id'] && $prev_question['user_answer'] ) { // Get the choice text of what the user picked (and show how many points they got) foreach( $prev_question['choices'] as $choice ) { if( $choice['id'] == $prev_question['user_answer'] ) { $your_answer = $choice['text']; if( $choice['is_correct'] == 1 ) { $your_answer_status = '<div class="answer-status-correct">' . wfMsg( 'quiz-chose-correct', $prev_question['points'] ) . '</div>'; } else { $your_answer_status = '<div class="answer-status-incorrect">' . wfMsg( 'quiz-chose-incorrect' ) . '</div>'; } } } } $output .= "<div class=\"user-answer-status\"> {$your_answer_status} </div>"; foreach( $prev_question['choices'] as $choice ) { $bar_width = floor( 460 * ( $choice['percent'] / 100 ) ); if ( $choice['is_correct'] == 1 ) { $answerClass = 'correct'; $answerColor = 'green'; } else { $answerClass = 'incorrect'; $answerColor = 'red'; } $output .= "<div class=\"answer-bar\" id=\"answer-bar-one\" style=\"display:block\"> <div id=\"one-answer\" class=\"small-answer-" . $answerClass . "\">{$choice['text']}</div> <span id=\"one-answer-bar\" class=\"answer-" . $answerColor . "\"> <img border=\"0\" style=\"width:{$bar_width}px; height: 11px;\" id=\"one-answer-width\" src=\"{$wgScriptPath}/extensions/QuizGame/images/vote-bar-" . $answerColor . ".gif\"/> <span id=\"one-answer-percent\" class=\"answer-percent\">{$choice['percent']}%</span> </span> </div>"; } $output .= '</div> </div>'; } $output .= "</div> <div class=\"quizgame-right\"> <div class=\"create-link\"> <img border=\"0\" src=\"{$wgScriptPath}/extensions/QuizGame/images/addIcon.gif\" alt=\"\" /> <a href=\"" . $this->getTitle()->escapeFullURL( 'questionGameAction=createForm' ) . '">' . wfMsg( 'quiz-create-title' ) . "</a> </div> <div class=\"credit-box\" id=\"creditBox\"> <h1>" . wfMsg( 'quiz-submitted-by' ) . "</h1> <div id=\"submitted-by-image\" class=\"submitted-by-image\"> <a href=\"{$user_title->getFullURL()}\"> <img src=\"{$wgUploadPath}/avatars/{$avatarID}\" style=\"border:1px solid #d7dee8; width:50px; height:50px;\" alt=\"\" /> </a> </div> <div id=\"submitted-by-user\" class=\"submitted-by-user\"> <div id=\"submitted-by-user-text\"> <a href=\"" . Title::makeTitle( NS_USER, $user_name )->escapeFullURL() . "\">{$user_name}</a> </div> <ul> <li id=\"userstats-votes\"> <img src=\"{$wgScriptPath}/extensions/QuizGame/images/voteIcon.gif\" border=\"0\" alt=\"\" /> {$stats_data['votes']} </li> <li id=\"userstats-edits\"> <img src=\"{$wgScriptPath}/extensions/QuizGame/images/pencilIcon.gif\" border=\"0\" alt=\"\" /> {$stats_data['edits']} </li> <li id=\"userstats-comments\"> <img src=\"{$wgScriptPath}/extensions/QuizGame/images/commentsIcon.gif\" border=\"0\" alt=\"\" /> {$stats_data['comments']} </li> </ul> </div> <div class=\"cleared\"></div> {$stats_box} </div> <div class=\"bottom-links\" id=\"utility-buttons\"> <a href=\"javascript:QuizGame.flagQuestion()\">" . wfMsg( 'quiz-flag' ) . '</a> - '; // Protect & delete links for quiz administrators if ( $wgUser->isAllowed( 'quizadmin' ) ) { $output .= '<a href="' . $this->getTitle()->escapeFullURL( 'questionGameAction=adminPanel' ) . '">' . wfMsg( 'quiz-admin-panel-title' ) . '</a> - <a href="javascript:QuizGame.protectImage()">' . wfMsg( 'quiz-protect' ) . '</a> -' . '<a href="javascript:QuizGame.deleteQuestion()">' . wfMsg( 'quiz-delete' ) . '</a> - '; } $output .= "<a href=\"javascript:document.location='" . $this->getTitle()->escapeFullURL( 'questionGameAction=renderPermalink' ) . "&permalinkID=' + document.getElementById( 'quizGameId' ).value\">" . wfMsg( 'quiz-permalink' ) . "</a> <div id=\"flag-comment\" style=\"display:none;margin-top:5px;\">" . wfMsg( 'quiz-flagged-reason' ) . ": <input type=\"text\" size=\"20\" id=\"flag-reason\" /> <input type=\"button\" onclick=\"QuizGame.doFlagQuestion()\" value=\"" . wfMsg( 'quiz-submit' ) . "\" /></div> </div> </div> </div> <div class=\"cleared\"/> <div class=\"hiddendiv\" style=\"display:none\"> <img src=\"{$wgScriptPath}/extensions/QuizGame/images/overlay.png\" alt=\"\" /> </div> </div>"; $wgOut->addHTML( $output ); }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserLevels, $wgUploadPath, $wgScriptPath; // Load CSS $wgOut->addExtensionStyle($wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css'); $dbr = wfGetDB(DB_SLAVE); $statistic = $dbr->strencode(trim($wgRequest->getVal('stat'))); $column = "stats_{$statistic}"; // Error if the querystring value does not match our stat column if (!$dbr->fieldExists('user_stats', $column)) { $wgOut->setPageTitle(wfMsg('top-fans-bad-field-title')); $wgOut->addHTML(wfMsg('top-fans-bad-field-message')); return false; } // Fix i18n message key $fixedStatistic = str_replace('_', '-', $statistic); // Set page title $wgOut->setPageTitle(wfMsg('top-fans-by-category-title-' . $fixedStatistic)); $count = 50; $user_list = array(); // Get list of users // Try cache $key = wfMemcKey('user_stats', 'top', $statistic, $count); $data = $wgMemc->get($key); if ($data != '') { wfDebug("Got top users by {$statistic} ({$count}) from cache\n"); $user_list = $data; } else { wfDebug("Got top users by {$statistic} ({$count}) from DB\n"); $params['ORDER BY'] = "{$column} DESC"; $params['LIMIT'] = $count; $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('user_stats', array('stats_user_id', 'stats_user_name', $column), array('stats_user_id <> 0', "{$column} > 0"), __METHOD__, $params); foreach ($res as $row) { $user_list[] = array('user_id' => $row->stats_user_id, 'user_name' => $row->stats_user_name, 'stat' => $row->{$column}); } $wgMemc->set($key, $user_list, 60 * 5); } // Top nav bar $top_title = SpecialPage::getTitleFor('TopUsers'); $recent_title = SpecialPage::getTitleFor('TopUsersRecent'); $out = '<div class="top-fan-nav"> <h1>' . wfMsg('top-fans-by-points-nav-header') . '</h1> <p><a href="' . $top_title->escapeFullURL() . '">' . wfMsg('top-fans-total-points-link') . '</a></p>'; if ($wgUserStatsTrackWeekly) { $out .= '<p><a href="' . $recent_title->escapeFullURL('period=monthly') . '">' . wfMsg('top-fans-monthly-points-link') . '</a><p>'; } if ($wgUserStatsTrackMonthly) { $out .= '<p><a href="' . $recent_title->escapeFullURL('period=weekly') . '">' . wfMsg('top-fans-weekly-points-link') . '</a></p>'; } // Build nav of stats by category based on MediaWiki:Topfans-by-category $out .= '<h1 style="margin-top:15px !important;">' . wfMsg('top-fans-by-category-nav-header') . '</h1>'; $by_category_title = SpecialPage::getTitleFor('TopFansByStatistic'); $nav = array(); $lines = explode("\n", wfMsgForContent('topfans-by-category')); foreach ($lines as $line) { if (strpos($line, '*') !== 0) { continue; } else { $line = explode('|', trim($line, '* '), 2); $stat = $line[0]; $link_text = $line[1]; $out .= '<p><a href="' . $by_category_title->escapeFullURL("stat={$stat}") . '">' . $link_text . '</a></p>'; } } $out .= '</div>'; $x = 1; $out .= '<div class="top-users">'; foreach ($user_list as $user) { if ($user['user_name'] == substr($user['user_name'], 0, 22)) { $user_name = $user['user_name']; } else { $user_name = substr($user['user_name'], 0, 22) . wfMsg('ellipsis'); } $user_title = Title::makeTitle(NS_USER, $user['user_name']); $avatar = new wAvatar($user['user_id'], 'm'); $commentIcon = $avatar->getAvatarImage(); // Stats row // TODO: opinion_average isn't currently working, so it's not enabled in menus if ($statistic == 'opinion_average') { $statistics_row = number_format($row->opinion_average, 2); $lowercase_statistics_name = 'percent'; } else { global $wgLang; $statistics_row = number_format($user['stat']); $lowercase_statistics_name = $wgLang->lc(wfMsgExt("top-fans-stats-{$fixedStatistic}", 'parsemag', $user['stat'])); } $out .= '<div class="top-fan-row"> <span class="top-fan-num">' . $x . '.</span> <span class="top-fan"> <img src="' . $wgUploadPath . '/avatars/' . $commentIcon . '" alt="" border="" /> <a href="' . $user_title->escapeFullURL() . '">' . $user_name . '</a> </span> <span class="top-fan-points"><b>' . $statistics_row . '</b> ' . $lowercase_statistics_name . '</span> <div class="cleared"></div> </div>'; $x++; } $out .= '</div><div class="cleared"></div>'; $wgOut->addHTML($out); }
function display() { global $wgUser; global $wgLang; global $wgContLang; global $wgTitle; global $wgOut; global $wgParser; global $wgAnonName; $sk =& $wgUser->getSkin(); $dbr =& wfGetDB(DB_MASTER); $output = ""; $sql = "SELECT Comment_Username,comment_ip, comment_text,comment_date,Comment_user_id,\n\t\t\t\tCommentID,IFNULL(Comment_Plus_Count - Comment_Minus_Count,0) as Comment_Score,\n\t\t\t\tComment_Plus_Count as CommentVotePlus, \n\t\t\t\tComment_Minus_Count as CommentVoteMinus,\n\t\t\t\t(select count(*) FROM Comments_Vote WHERE Comment_Vote_ID = CommentID AND Comment_Vote_user_id=" . $wgUser->mId . ") as AlreadyVoted,\n\t\t\t\tComment_Parent_ID, CommentID,\n\t\t\t\tCASE Comment_Parent_ID WHEN 0 THEN CAST(replace(Comment_Parent_ID,0,CommentID) as UNSIGNED) else CAST(Comment_Parent_ID as UNSIGNED) end as thread"; if ($this->ShowUserRating == 1) { $sql .= ",vote_value"; } $sql .= " FROM Comments "; if ($this->ShowUserRating == 1) { $sql .= " LEFT JOIN Vote ON Comment_username=username and vote_page_id=" . $this->PageID; } $sql .= " WHERE comment_page_id = " . $this->PageID; if ($this->OrderBy == 0) { $sql .= " ORDER BY thread,Comment_Date"; } else { $sql .= " ORDER BY Comment_Score DESC"; } $res = $dbr->query($sql); $AFCounter = 1; $AFBucket = array(); while ($row = $dbr->fetchObject($res)) { $CommentScore = $row->Comment_Score; $this->Scorecard[$row->Comment_Username] += $CommentScore; if ($row->Comment_user_id != 0) { $title = Title::makeTitle(2, $row->Comment_Username); $CommentPoster = $sk->makeKnownLinkObj($title, $wgContLang->convertHtml($title->getText())); $CommentReplyTo = $row->Comment_Username; } else { if (!array_key_exists($row->Comment_Username, $AFBucket)) { $AFBucket[$row->Comment_Username] = $AFCounter; $AFCounter++; } $CommentPoster = $wgAnonName . " #" . $AFBucket[$row->Comment_Username]; $CommentReplyTo = $wgAnonName; } if ($row->Comment_user_id != 0) { $avatar = new wAvatar($row->Comment_user_id, "m"); $CommentIcon = $avatar->getAvatarImage(); } else { $CommentIcon = "af_m.gif"; } if ($row->Comment_Parent_ID == 0) { $Width1 = 629; $Width2 = 385; $class = "comment"; $moveleft = ""; } else { $Width1 = 520; $Width2 = 286; $class = "reply"; $moveleft = 'style="padding-left:109px"'; } $timeArray = $this->dateDiff(time(), $row->comment_date); $timeStr = ""; $timeStrD = $this->getTimeOffset($timeArray, "d", "day"); $timeStrH = $this->getTimeOffset($timeArray, "h", "hour"); $timeStrM = $this->getTimeOffset($timeArray, "m", "minute"); $timeStrS = $this->getTimeOffset($timeArray, "s", "second"); $timeStr = $timeStrD; if ($timeStr < 2) { $timeStr .= $timeStrH; $timeStr .= $timeStrM; if (!$timeStr) { $timeStr .= $timeStrS; } } $UserRating = ""; if ($this->ShowUserRating == 1) { $Vote = new VoteStars($this->PageID); $UserRating = ' ' . $Vote->displayRating($row->vote_value); } $output .= '<div ' . $moveleft . ' id="comment-' . $row->CommentID . '" ><table border="0" cellspacing="0" cellpadding="0" width="' . $Width1 . '" style="padding-bottom:15px;"> <tr> <td class="' . $class . 'top"><table border="0" cellpadding="0" cellspacing="0" width="' . $Width1 . '"> <tr> <td width="100" class="commenticon"><img src="images/avatars/' . $CommentIcon . '" alt="" border="0"/></td> <td width="' . $Width2 . '"> <table border="0" cellpadding="0" cellspacing="0" width="' . $Width2 . '"> <tr> <td class="username">' . $CommentPoster . $UserRating . '</td> </tr> <tr> <td class="commenttime">posted <b>' . $timeStr . '</b> ago</td> </tr> </table> </td> <td width="134"> <table border="0" cellpadding="0" cellspacing="0" width="134"> <tr> <td class="commentscore" nowrap="nowrap" height="35" valign="bottom">'; if ($this->AllowMinus == true || $this->AllowPlus == true) { $output .= "Score: <span id=\"Comment" . $row->CommentID . "\">" . $CommentScore . "</span>"; } $output .= "</td>"; $output .= "<td valign=\"bottom\">"; $output .= "<span class=\"CommentVote\">"; $output .= "<span id=\"CommentBtn" . $row->CommentID . "\">"; if ($row->AlreadyVoted == 0) { if ($wgUser->mName != $row->Comment_Username) { if ($this->AllowPlus == true) { $output .= $this->getVoteLink($row->CommentID, 1); //'<a href=javascript:cv(' . $row['CommentID'] . ',1,"' . $VoteKey . '","' . $this->Voting . '")>'; } if ($this->AllowMinus == true) { $output .= $this->getVoteLink($row->CommentID, -1); //'<a href=javascript:cv(' . $row['CommentID'] . ',1,"' . $VoteKey . '","' . $this->Voting . '")>'; } } else { $output .= '<span class="commentscore"><b>You</b></span>'; } } else { $output .= '<img src="images/myfeed.gif" align="bottom" hspace="2" alt="v" /><span class="commentscore">voted</span>'; } $output .= "</span>"; $output .= "</span>"; $output .= "</td>"; $output .= '</tr> </table> </td> </tr> </table> </td> </tr> <tr> <td class="commentmiddle" width="' . $Width1 . '" height="40">' . $this->getCommentText($row->comment_text) . '</td> </tr> <tr> <td class="' . $class . 'bottom"></td> </tr>'; $dlt = ""; if (in_array('staff', $wgUser->getGroups()) || $wgUser->mName == "Pean") { $dlt = ' <span ><a href="javascript:document.commentform.commentid.value=' . $row->CommentID . ';document.commentform.submit();" style="color:red">x</a></span> '; } $replyRow = ""; if ($row->Comment_Parent_ID == 0) { if ($replyRow) { $replyRow .= " | "; } $replyRow .= "<a href=\"#end\" class=\"reply\" onclick=\"javascript:Reply(" . $row->CommentID . ",'" . urlencode($CommentReplyTo) . "')\">reply</a>"; } if ($replyRow || $dlt) { $output .= "<tr><td align=\"right\">" . $dlt . " " . $replyRow . "</td></tr>"; } $output .= '</table></div>'; } $output .= '<a id="end" name="end"></a>'; return $output; }
/** * Get the relationships for a given user. * * @param $user_name String: name of the user whose relationships we want * to fetch * @param $rel_type Integer: 1 for friends, 2 (or anything else than 1) for * foes */ function getRelationships($user_name, $rel_type) { global $wgMemc, $wgUser, $wgUserProfileDisplay, $wgUploadPath; // If not enabled in site settings, don't display if ($rel_type == 1) { if ($wgUserProfileDisplay['friends'] == false) { return ''; } } else { if ($wgUserProfileDisplay['foes'] == false) { return ''; } } $output = ''; // Prevent E_NOTICE $count = 4; $rel = new UserRelationship($user_name); $key = wfMemcKey('relationship', 'profile', "{$rel->user_id}-{$rel_type}"); $data = $wgMemc->get($key); // Try cache if (!$data) { $friends = $rel->getRelationshipList($rel_type, $count); $wgMemc->set($key, $friends); } else { wfDebug("Got profile relationship type {$rel_type} for user {$user_name} from cache\n"); $friends = $data; } $stats = new UserStats($rel->user_id, $user_name); $stats_data = $stats->getUserStats(); $view_all_title = SpecialPage::getTitleFor('ViewRelationships'); if ($rel_type == 1) { $relationship_count = $stats_data['friend_count']; $relationship_title = wfMsg('user-friends-title'); } else { $relationship_count = $stats_data['foe_count']; $relationship_title = wfMsg('user-foes-title'); } if (count($friends) > 0) { $x = 1; $per_row = 4; $output .= '<div class="user-section-heading"> <div class="user-section-title">' . $relationship_title . '</div> <div class="user-section-actions"> <div class="action-right">'; if (intval(str_replace(',', '', $relationship_count)) > 4) { $output .= '<a href="' . $view_all_title->escapeFullURL('user='******'&rel_type=' . $rel_type) . '" rel="nofollow">' . wfMsg('user-view-all') . '</a>'; } $output .= '</div> <div class="action-left">'; if (intval(str_replace(',', '', $relationship_count)) > 4) { $output .= wfMsg('user-count-separator', $per_row, $relationship_count); } else { $output .= wfMsg('user-count-separator', $relationship_count, $relationship_count); } $output .= '</div> </div> <div class="cleared"></div> </div> <div class="cleared"></div> <div class="user-relationship-container">'; foreach ($friends as $friend) { $user = Title::makeTitle(NS_USER, $friend['user_name']); $avatar = new wAvatar($friend['user_id'], 'ml'); $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="" border="0" />'; // Chop down username that gets displayed $user_name = mb_substr($friend['user_name'], 0, 9); if ($user_name != $friend['user_name']) { $user_name .= '..'; } $output .= "<a href=\"" . $user->escapeFullURL() . "\" title=\"{$friend['user_name']}\" rel=\"nofollow\">\r\n\t\t\t\t\t{$avatar_img}<br />\r\n\t\t\t\t\t{$user_name}\r\n\t\t\t\t</a>"; if ($x == count($friends) || $x != 1 && $x % $per_row == 0) { $output .= '<div class="cleared"></div>'; } $x++; } $output .= '</div>'; } return $output; }
/** * Called on every poll page view. */ public function view() { global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgScriptPath, $wgUploadPath, $wgLang; global $wgSupressPageTitle, $wgNameSpacesWithEditMenu; // Perform no custom handling if the poll in question has been deleted if (!$this->getID()) { parent::view(); } $wgSupressPageTitle = true; $wgOut->setHTMLTitle($wgTitle->getText()); $wgOut->setPageTitle($wgTitle->getText()); $wgNameSpacesWithEditMenu[] = NS_POLL; $wgOut->addScript("<script type=\"text/javascript\">\n\t\t\t\$( function() { LightBox.init(); PollNY.show(); } );\n\t\t</script>\n"); $createPollObj = SpecialPage::getTitleFor('CreatePoll'); $wgOut->addHTML("<script type=\"text/javascript\">\n\t\t\tvar _POLL_OPEN_MESSAGE = \"" . addslashes(wfMsg('poll-open-message')) . "\";\n\t\t\tvar _POLL_CLOSE_MESSAGE = \"" . addslashes(wfMsg('poll-close-message')) . "\";\n\t\t\tvar _POLL_FLAGGED_MESSAGE = \"" . addslashes(wfMsg('poll-flagged-message')) . "\";\n\t\t\tvar _POLL_FINISHED = \"" . addslashes(wfMsg('poll-finished', $createPollObj->getFullURL(), $wgTitle->getFullURL())) . "\";\n\t\t</script>"); // Get total polls count so we can tell the user how many they have // voted for out of total $dbr = wfGetDB(DB_MASTER); $total_polls = 0; $s = $dbr->selectRow('poll_question', array('COUNT(*) AS count'), array(), __METHOD__); if ($s !== false) { $total_polls = number_format($s->count); } $stats = new UserStats($wgUser->getID(), $wgUser->getName()); $stats_current_user = $stats->getUserStats(); $sk = $wgUser->getSkin(); $p = new Poll(); $poll_info = $p->getPoll($wgTitle->getArticleID()); if (!isset($poll_info['id'])) { return ''; } // Set up submitter data $user_title = Title::makeTitle(NS_USER, $poll_info['user_name']); $avatar = new wAvatar($poll_info['user_id'], 'l'); $avatarID = $avatar->getAvatarImage(); $stats = new UserStats($poll_info['user_id'], $poll_info['user_name']); $stats_data = $stats->getUserStats(); $user_name_short = $wgLang->truncate($poll_info['user_name'], 27); $output = '<div class="poll-right">'; // Show the "create a poll" link to registered users if ($wgUser->isLoggedIn()) { $output .= '<div class="create-link"> <a href="' . $createPollObj->escapeFullURL() . '"> <img src="' . $wgScriptPath . '/extensions/PollNY/images/addIcon.gif" alt="" />' . wfMsg('poll-create') . '</a> </div>'; } $output .= '<div class="credit-box"> <h1>' . wfMsg('poll-submitted-by') . "</h1>\n\t\t\t\t\t<div class=\"submitted-by-image\">\n\t\t\t\t\t\t<a href=\"{$user_title->getFullURL()}\">\n\t\t\t\t\t\t\t<img src=\"{$wgUploadPath}/avatars/{$avatarID}\" style=\"border:1px solid #d7dee8; width:50px; height:50px;\"/>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"submitted-by-user\">\n\t\t\t\t\t\t<a href=\"{$user_title->getFullURL()}\">{$user_name_short}</a>\n\t\t\t\t\t\t<ul>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/voteIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['votes']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/pencilIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['edits']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/commentsIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['comments']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"cleared\"></div>\n\n\t\t\t\t\t<a href=\"" . SpecialPage::getTitleFor('ViewPoll')->escapeFullURL('user='******'user_name']) . '">' . wfMsgExt('poll-view-all-by', 'parsemag', $user_name_short) . '</a> </div>'; $output .= '<div class="poll-stats">'; if ($wgUser->isLoggedIn()) { $output .= wfMsgExt('poll-voted-for', 'parsemag', '<b>' . $stats_current_user['poll_votes'] . '</b>', $total_polls, number_format($stats_current_user['poll_votes'] * 5)); } else { $output .= wfMsgExt('poll-would-have-earned', 'parse', number_format($total_polls * 5)); } $output .= '</div>' . "\n"; $toggle_flag_label = $poll_info['status'] == 1 ? wfMsg('poll-flag-poll') : wfMsg('poll-unflag-poll'); $toggle_flag_status = $poll_info['status'] == 1 ? 2 : 1; if ($poll_info['status'] == 1) { // Creator and admins can change the status of a poll $toggle_label = $poll_info['status'] == 1 ? wfMsg('poll-close-poll') : wfMsg('poll-open-poll'); $toggle_status = $poll_info['status'] == 1 ? 0 : 1; } $output .= '<div class="poll-links">' . "\n"; // Poll administrators can access the poll admin panel if ($wgUser->isAllowed('polladmin')) { $output .= '<a href="' . SpecialPage::getTitleFor('AdminPoll')->escapeFullURL() . '">' . wfMsg('poll-admin-panel') . '</a> | '; } if ($poll_info['status'] == 1 && ($poll_info['user_id'] == $wgUser->getID() || $wgUser->isAllowed('polladmin'))) { $output .= "<a href=\"javascript:void(0)\" onclick=\"PollNY.toggleStatus({$toggle_status});\">{$toggle_label}</a> |"; } if ($poll_info['status'] == 1 || $wgUser->isAllowed('polladmin')) { $output .= " <a href=\"javascript:void(0)\" onclick=\"PollNY.toggleStatus({$toggle_flag_status});\">{$toggle_flag_label}</a>"; } $output .= "\n" . '</div>' . "\n"; // .poll-links $output .= '</div>' . "\n"; // .poll-right $output .= '<div class="poll">' . "\n"; $output .= "<h1 class=\"pagetitle\">{$wgTitle->getText()}</h1>\n"; if ($poll_info['image']) { $poll_image_width = 150; $poll_image = wfFindFile($poll_info['image']); $poll_image_url = $width = ''; if (is_object($poll_image)) { $poll_image_url = $poll_image->createThumb($poll_image_width); if ($poll_image->getWidth() >= $poll_image_width) { $width = $poll_image_width; } else { $width = $poll_image->getWidth(); } } $poll_image_tag = '<img width="' . $width . '" alt="" src="' . $poll_image_url . '"/>'; $output .= "<div class=\"poll-image\">{$poll_image_tag}</div>"; } // Display question and let user vote if (!$p->userVoted($wgUser->getName(), $poll_info['id']) && $poll_info['status'] == 1) { $output .= '<div id="loading-poll">' . wfMsg('poll-js-loading') . '</div>' . "\n"; $output .= '<div id="poll-display" style="display:none;">' . "\n"; $output .= '<form name="poll"><input type="hidden" id="poll_id" name="poll_id" value="' . $poll_info['id'] . '"/>' . "\n"; foreach ($poll_info['choices'] as $choice) { $output .= '<div class="poll-choice"> <input type="radio" name="poll_choice" onclick="PollNY.vote()" id="poll_choice" value="' . $choice['id'] . '" />' . $choice['choice'] . '</div>'; } $output .= '</form> </div>' . "\n"; $output .= '<div class="poll-timestamp">' . wfMsg('poll-createdago', Poll::getTimeAgo($poll_info['timestamp'])) . '</div>' . "\n"; $output .= "\t\t\t\t\t" . '<div class="poll-button"> <a href="javascript:PollNY.skip();">' . wfMsg('poll-skip') . '</a> </div>'; if ($wgRequest->getInt('prev_id')) { $p = new Poll(); $poll_info_prev = $p->getPoll($wgRequest->getInt('prev_id')); $poll_title = Title::makeTitle(NS_POLL, $poll_info_prev['question']); $output .= '<div class="previous-poll">'; $output .= '<div class="previous-poll-title">' . wfMsg('poll-previous-poll') . " - <a href=\"{$poll_title->getFullURL()}\">{$poll_info_prev['question']}</a></div>\n\t\t\t\t\t<div class=\"previous-sub-title\">" . wfMsgExt('poll-view-answered-times', 'parsemag', $poll_info_prev['votes']) . '</div>'; $x = 1; foreach ($poll_info_prev['choices'] as $choice) { if ($poll_info_prev['votes'] > 0) { $percent = round($choice['votes'] / $poll_info_prev['votes'] * 100); $bar_width = floor(360 * ($choice['votes'] / $poll_info_prev['votes'])); } else { $percent = 0; $bar_width = 0; } if (empty($choice['votes'])) { $choice['votes'] = 0; } $bar_img = '<img src="' . $wgScriptPath . '/extensions/PollNY/images/vote-bar-' . $x . '.gif" class="image-choice-' . $x . '" style="width:' . $bar_width . 'px;height:11px;"/>'; $output .= "<div class=\"previous-poll-choice\">\n\t\t\t\t\t\t\t\t<div class=\"previous-poll-choice-left\">{$choice['choice']} ({$percent}%)</div>"; $output .= "<div class=\"previous-poll-choice-right\">{$bar_img} <span class=\"previous-poll-choice-votes\">" . wfMsgExt('poll-votes', 'parsemag', $choice['votes']) . '</span></div>'; $output .= '</div>'; $x++; } $output .= '</div>'; } } else { $show_results = true; // Display message if poll has been closed for voting if ($poll_info['status'] == 0) { $output .= '<div class="poll-closed">' . wfMsg('poll-closed') . '</div>'; } // Display message if poll has been flagged if ($poll_info['status'] == 2) { $output .= '<div class="poll-closed">' . wfMsg('poll-flagged') . '</div>'; if (!$wgUser->isAllowed('polladmin')) { $show_results = false; } } if ($show_results) { $x = 1; foreach ($poll_info['choices'] as $choice) { if ($poll_info['votes'] > 0) { $percent = round($choice['votes'] / $poll_info['votes'] * 100); $bar_width = floor(480 * ($choice['votes'] / $poll_info['votes'])); } else { $percent = 0; $bar_width = 0; } // If it's not set, it means that no-one has voted for that // choice yet...it also means that we need to set it // manually here so that i18n displays properly if (empty($choice['votes'])) { $choice['votes'] = 0; } $bar_img = "<img src=\"{$wgScriptPath}/extensions/PollNY/images/vote-bar-{$x}.gif\" class=\"image-choice-{$x}\" style=\"width:{$bar_width}px;height:12px;\"/>"; $output .= "<div class=\"poll-choice\">\n\t\t\t\t\t<div class=\"poll-choice-left\">{$choice['choice']} ({$percent}%)</div>"; $output .= "<div class=\"poll-choice-right\">{$bar_img} <span class=\"poll-choice-votes\">" . wfMsgExt('poll-votes', 'parsemag', $choice['votes']) . '</span></div>'; $output .= '</div>'; $x++; } } $output .= '<div class="poll-total-votes">(' . wfMsgExt('poll-based-on-votes', 'parsemag', $poll_info['votes']) . ')</div> <div class="poll-timestamp">' . wfMsg('poll-createdago', Poll::getTimeAgo($poll_info['timestamp'])) . '</div> <div class="poll-button"> <input type="hidden" id="poll_id" name="poll_id" value="' . $poll_info['id'] . '" /> <a href="javascript:PollNY.loadingLightBox();PollNY.goToNewPoll();">' . wfMsg('poll-next-poll') . '</a> </div>'; } // "Embed this on a wiki page" feature $poll_embed_name = htmlspecialchars($wgTitle->getText(), ENT_QUOTES); $output .= '<br /> <table cellpadding="0" cellspacing="2" border="0"> <tr> <td> <b>' . wfMsg('poll-embed') . "</b>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<form name=\"embed_poll\">\n\t\t\t\t\t\t\t<input name='embed_code' style='width:300px;font-size:10px;' type='text' value='<pollembed title=\"{$poll_embed_name}\" />' onclick='javascript:document.embed_poll.embed_code.focus();document.embed_poll.embed_code.select();' readonly='readonly' />\n\t\t\t\t\t\t</form>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n"; $output .= '</div>' . "\n"; // .poll $output .= '<div class="cleared"></div>'; $wgOut->addHTML($output); global $wgPollDisplay; if ($wgPollDisplay['comments']) { $wgOut->addWikiText('<comments/>'); } }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgRequest, $wgOut, $wgUser, $wgUploadPath, $wgHooks, $wgPollScripts; // If the user doesn't have the required permission, display an error if (!$wgUser->isAllowed('polladmin')) { $wgOut->permissionRequired('polladmin'); return; } // Show a message if the database is in read-only mode if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } // If user is blocked, s/he doesn't need to access this page if ($wgUser->isBlocked()) { $wgOut->blockedPage(); return; } // Add CSS & JS $wgOut->addExtensionStyle($wgPollScripts . '/Poll.css'); $wgOut->addScriptFile($wgPollScripts . '/Poll.js'); // Add i18n JS variables via a hook (yes, this works, I've tested this) $wgHooks['MakeGlobalVariablesScript'][] = 'AdminPoll::addJSGlobals'; // Pagination $per_page = 20; $page = $wgRequest->getInt('page', 1); $current_status = $wgRequest->getVal('status'); if (!$current_status) { $current_status = 'all'; } $limit = $per_page; $nav = array('all' => wfMsg('poll-admin-viewall'), 'open' => wfMsg('poll-admin-open'), 'closed' => wfMsg('poll-admin-closed'), 'flagged' => wfMsg('poll-admin-flagged')); $output = '<div class="view-poll-top-links"> <a href="javascript:history.go(-1);">' . wfMsg('poll-take-button') . '</a> </div> <div class="view-poll-navigation"> <h2>' . wfMsg('poll-admin-status-nav') . '</h2>'; foreach ($nav as $status => $title) { $output .= '<p>'; if ($current_status != $status) { $output .= '<a href="' . $this->getTitle()->escapeFullURL("status={$status}") . "\">{$title}</a>"; } else { $output .= "<b>{$title}</b>"; } $output .= '</p>'; } $output .= '</div>'; $wgOut->setPageTitle(wfMsg('poll-admin-title-' . $current_status)); $params['ORDER BY'] = 'poll_date DESC'; if ($limit > 0) { $params['LIMIT'] = $limit; } if ($page) { $params['OFFSET'] = $page * $limit - $limit; } $status_int = -1; switch ($current_status) { case 'open': $status_int = 1; break; case 'closed': $status_int = 0; break; case 'flagged': $status_int = 2; break; } $where = array(); if ($status_int > -1) { $where['poll_status'] = $status_int; } $dbr = wfGetDB(DB_MASTER); $res = $dbr->select(array('poll_question', 'page'), array('poll_id', 'poll_user_id', 'UNIX_TIMESTAMP(poll_date) AS poll_time', 'poll_status', 'poll_vote_count', 'poll_user_name', 'poll_text', 'poll_page_id', 'page_id'), $where, __METHOD__, $params, array('page' => array('INNER JOIN', 'poll_page_id = page_id'))); if ($status_int > -1) { $where['poll_status'] = $status; } $s = $dbr->selectRow('poll_question', array('COUNT(*) AS count'), $where, __METHOD__, $params); $total = $s->count; $output .= '<div class="view-poll">'; $x = ($page - 1) * $per_page + 1; // If we have nothing, show an error(-ish) message, but don't return // because it could be that we have plenty of polls in the database, // but none of 'em matches the given criteria (status param in the URL) // For example, there are no flagged polls or closed polls. This msg // gets shown even then. if (!$dbr->numRows($res)) { $wgOut->addWikiMsg('poll-admin-no-polls'); } foreach ($res as $row) { $user_create = $row->poll_user_name; $user_id = $row->poll_user_id; $avatar = new wAvatar($user_id, 'm'); $poll_title = $row->poll_text; $poll_date = $row->poll_time; $poll_answers = $row->poll_vote_count; $rowId = "poll-row-{$x}"; $title = Title::makeTitle(NS_POLL, $poll_title); $p = new Poll(); $poll_choices = $p->getPollChoices($row->poll_id); if ($x < $dbr->numRows($res) && $x % $per_page != 0) { $output .= "<div class=\"view-poll-row\" id=\"{$rowId}\">"; } else { $output .= "<div class=\"view-poll-row-bottom\" id=\"{$rowId}\">"; } $output .= "<div class=\"view-poll-number\">{$x}.</div>\n\t\t\t\t\t<div class=\"view-poll-user-image\"><img src=\"{$wgUploadPath}/avatars/{$avatar->getAvatarImage()}\" alt=\"\" /></div>\n\t\t\t\t\t<div class=\"view-poll-user-name\">{$user_create}</div>\n\t\t\t\t\t<div class=\"view-poll-text\">\n\t\t\t\t\t<p><b><a href=\"{$title->escapeFullURL()}\">{$poll_title}</a></b></p>\n\t\t\t\t\t<p>"; foreach ($poll_choices as $choice) { $output .= "{$choice['choice']}<br />"; } $output .= '</p> <p class="view-poll-num-answers">' . wfMsgExt('poll-view-answered-times', 'parsemag', $poll_answers) . '</p> <p class="view-poll-time">(' . wfMsg('poll-ago', Poll::getTimeAgo($poll_date)) . ")</p>\n\t\t\t\t\t\t<div id=\"poll-{$row->poll_id}-controls\">"; if ($row->poll_status == 2) { $output .= "<a href=\"javascript:void(0)\" onclick=\"PollNY.poll_admin_status({$row->poll_id},1);\">" . wfMsg('poll-unflag-poll') . '</a>'; } if ($row->poll_status == 0) { $output .= " <a href=\"javascript:void(0)\" onclick=\"PollNY.poll_admin_status({$row->poll_id},1);\">" . wfMsg('poll-open-poll') . '</a>'; } if ($row->poll_status == 1) { $output .= " <a href=\"javascript:void(0)\" onclick=\"PollNY.poll_admin_status({$row->poll_id},0);\">" . wfMsg('poll-close-poll') . '</a>'; } $output .= " <a href=\"javascript:void(0)\" onclick=\"PollNY.poll_delete({$row->poll_id});\">" . wfMsg('poll-delete-poll') . '</a> </div> </div> <div class="cleared"></div> </div>'; $x++; } $output .= '</div> <div class="cleared"></div>'; $output .= $this->buildPagination($total, $per_page, $page); $wgOut->addHTML($output); }
/** * Displays the form for removing a friend or a foe * @return $form Mixed: HTML code for the form */ function displayForm() { global $wgOut, $wgUploadPath; $avatar = new wAvatar($this->user_id_to, 'l'); $avatar_img = '<img src="' . $wgUploadPath . '/avatars/' . $avatar->getAvatarImage() . '" alt="avatar" />'; if ($this->relationship_type == 1) { $title = wfMsg('ur-remove-relationship-title-friend', $this->user_name_to); $remove = wfMsg('ur-remove-relationship-message-friend', $this->user_name_to, wfMsg('ur-remove')); } else { $title = wfMsg('ur-remove-relationship-title-foe', $this->user_name_to); $remove = wfMsg('ur-remove-relationship-message-foe', $this->user_name_to, wfMsg('ur-remove')); } $wgOut->setPageTitle($title); $form = "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"form1\">\r\n\t\t\t<div class=\"relationship-action\">\r\n\t\t\t{$avatar_img}" . $remove . '<div class="relationship-buttons"> <input type="hidden" name="user" value="' . addslashes($this->user_name_to) . '" /> <input type="button" class="site-button" value="' . wfMsg('ur-remove') . '" size="20" onclick="document.form1.submit()" /> <input type="button" class="site-button" value="' . wfMsg('ur-cancel') . '" size="20" onclick="history.go(-1)" /> </div> <div class="cleared"></div> </div> </form>'; return $form; }
/** * Fetches the two images to be voted on * * @param $isPermalink Boolean: false by default * @param $imgID Integer: is present if rendering a permalink * @param $lastID Integer: optional; the last image ID the user saw */ function getImageDivs( $isPermalink = false, $imgID = -1, $lastID = -1 ) { global $wgRequest, $wgUser, $wgOut, $wgScriptPath, $wgUseEditButtonFloat, $wgUploadPath, $wgLang; $totalVotes = 0; $dbr = wfGetDB( DB_SLAVE ); // if imgID is -1 then we need some random IDs if( $imgID == -1 ) { $query = $dbr->select( 'picturegame_votes', 'picid', array( 'username' => $wgUser->getName() ), __METHOD__ ); $picIds = array(); foreach ( $query as $resultRow ) { $picIds[] = $resultRow->picid; } // If there are no picture games in the database, the above query // won't add anything to the picIds array, and trying to implode // an empty array...well, you'll get id NOT IN () which in turn is // invalid SQL. if ( !empty( $picIds ) ) { $res = $dbr->select( 'picturegame_images', '*', array( 'id NOT IN (' . implode( ',', $picIds ) . ')', 'flag <> ' . PICTUREGAME_FLAG_FLAGGED, "img1 <> ''", "img2 <> ''" ), __METHOD__, array( 'LIMIT' => 1 ) ); /*$sql = "SELECT * FROM picturegame_images WHERE picturegame_images.id NOT IN (SELECT picid FROM picturegame_votes WHERE picturegame_votes.username='******') AND flag <> " . PICTUREGAME_FLAG_FLAGGED . " AND img1 <> '' AND img2 <> '' LIMIT 1;"; $res = $dbr->query( $sql, __METHOD__ );*/ $row = $dbr->fetchObject( $res ); $imgID = isset( $row->id ) ? $row->id : 0; } $imgID = 0; } else { $res = $dbr->select( 'picturegame_images', '*', array( 'flag <> ' . PICTUREGAME_FLAG_FLAGGED, "img1 <> ''", "img2 <> ''", 'id' => $imgID ), __METHOD__ ); $row = $dbr->fetchObject( $res ); } // Early return here in case if we have *nothing* in the database to // prevent fatals etc. if( empty( $row ) ) { $wgOut->setPageTitle( wfMsg( 'picturegame-nomoretitle' ) ); // can't use addWikiMsg() because we can't make an internal link // to Special:PictureGameHome?picGameAction=startCreate :P $wgOut->addHTML( wfMsg( 'picturegame-empty', $this->getTitle()->escapeFullURL( 'picGameAction=startCreate' ) ) ); return; } $user_title = Title::makeTitle( NS_USER, $row->username ); if( $imgID ) { global $wgPictureGameID; $wgPictureGameID = $imgID; $toExclude = $dbr->select( 'picturegame_votes', 'picid', array( 'username' => $wgUser->getName() ), __METHOD__ ); $excludedImgIds = array(); foreach ( $toExclude as $excludedRow ) { $excludedImgIds[] = $excludedRow->picid; } $next_id = 0; if ( !empty( $excludedImgIds ) ) { $nextres = $dbr->select( 'picturegame_images', '*', array( "id <> {$imgID}", 'id NOT IN (' . implode( ',', $excludedImgIds ) . ')', 'flag != ' . PICTUREGAME_FLAG_FLAGGED, "img1 <> ''", "img2 <> ''" ), __METHOD__, array( 'LIMIT' => 1 ) ); /*$sql = "SELECT * FROM picturegame_images WHERE picturegame_images.id <> {$imgID} AND picturegame_images.id NOT IN (SELECT picid FROM picturegame_votes WHERE picturegame_votes.username='******') AND flag != " . PICTUREGAME_FLAG_FLAGGED . " AND img1 <> '' AND img2 <> '' LIMIT 1;"; $nextres = $dbr->query( $sql, __METHOD__ );*/ $nextrow = $dbr->fetchObject( $nextres ); $next_id = ( isset( $nextrow->id ) ? $nextrow->id : 0 ); } if( $next_id ) { $img_one = wfFindFile( $nextrow->img1 ); if( is_object( $img_one ) ) { $preload_thumb = $img_one->getThumbnail( 256 ); } if( is_object( $preload_thumb ) ) { $preload_one_tag = $preload_thumb->toHtml(); } $img_two = wfFindFile( $nextrow->img2 ); if( is_object( $img_two ) ) { $preload_thumb = $img_two->getThumbnail( 256 ); } if( is_object( $preload_thumb ) ) { $preload_two_tag = $preload_thumb->toHtml(); } $preload = $preload_one_tag . $preload_two_tag; } } if( ( $imgID < 0 ) || !is_numeric( $imgID ) || is_null( $row ) ) { $wgOut->setPageTitle( wfMsg( 'picturegame-nomoretitle' ) ); // @todo FIXME: fugly i18n $out = '<div>' . wfMsg( 'picturegame-nomore' ) . '<br />' . wfMsg( 'picturegame-nomore-2' ) . '<a href="' . $this->getTitle()->escapeFullURL( 'picGameAction=startCreate' ) . '">' . wfMsg( 'picturegame-nomorecreatelink' ) . '</a> ' . wfMsg( 'picturegame-nomoreor' ) . ' <a href="' . $wgScriptPath . '/index.php?title=Special:RandomPoll">' . wfMsg( 'picturegame-nomoretakepolls' ) . '</a> </div>'; return $out; } // snag the images to vote on and grab some thumbnails // modify this query so that if the current user has voted on this // image pair don't show it again $imgOneCount = $row->img0_votes; $imgTwoCount = $row->img1_votes; $user_name = $wgLang->truncate( $row->username, 20 ); $title_text_length = strlen( $row->title ); $title_text_space = stripos( $row->title, ' ' ); if( ( $title_text_space == false || $title_text_space >= '48' ) && $title_text_length > 48 ) { $title_text = substr( $row->title, 0, 48 ) . '<br />' . substr( $row->title, 48, 48 ); } elseif( $title_text_length > 48 && substr( $row->title, 48, 1 ) == ' ' ) { $title_text = substr( $row->title, 0, 48 ) . '<br />' . substr( $row->title, 48, 48 ); } elseif( $title_text_length > 48 && substr( $row->title, 48, 1 ) != ' ' ) { $title_text_lastspace = strrpos( substr( $row->title, 0, 48 ), ' ' ); $title_text = substr( $row->title, 0, $title_text_lastspace ) . '<br />' . substr( $row->title, $title_text_lastspace, 30 ); } else { $title_text = $row->title; } $x = 1; $img1_caption_text = ''; $img1caption_array = str_split( $row->img1_caption ); foreach( $img1caption_array as $img1_character ) { if( $x % 30 == 0 ) { $img1_caption_text .= $img1_character . '<br />'; } else { $img1_caption_text .= $img1_character; } $x++; } $x = 1; $img2_caption_text = ''; $img1caption_array = str_split( $row->img2_caption ); foreach( $img1caption_array as $img2_character ) { if( $x % 30 == 0 ) { $img2_caption_text .= $img2_character . '<br />'; } else { $img2_caption_text .= $img2_character; } $x++; } // I assume MediaWiki does some caching with these functions $img_one = wfFindFile( $row->img1 ); $thumb_one_url = ''; if( is_object( $img_one ) ) { $thumb_one_url = $img_one->createThumb( 256 ); $imageOneWidth = $img_one->getWidth(); } //$imgOne = '<img width="' . ( $imageOneWidth >= 256 ? 256 : $imageOneWidth ) . '" alt="" src="' . $thumb_one_url . ' "/>'; //$imageOneWidth = ( $imageOneWidth >= 256 ? 256 : $imageOneWidth ); //$imageOneWidth += 10; $imgOne = '<img style="width:100%;" alt="" src="' . $thumb_one_url . ' "/>'; $img_two = wfFindFile( $row->img2 ); $thumb_two_url = ''; if( is_object( $img_two ) ) { $thumb_two_url = $img_two->createThumb( 256 ); $imageTwoWidth = $img_two->getWidth(); } //$imgTwo = '<img width="' . ( $imageTwoWidth >= 256 ? 256 : $imageTwoWidth ) . '" alt="" src="' . $thumb_two_url . ' "/>'; //$imageTwoWidth = ( $imageTwoWidth >= 256 ? 256 : $imageTwoWidth ); //$imageTwoWidth += 10; $imgTwo = '<img style="width:100%;" alt="" src="' . $thumb_two_url . ' " />'; $title = $title_text; $img1_caption = $img1_caption_text; $img2_caption = $img2_caption_text; $vote_one_tag = ''; $vote_two_tag = ''; $imgOnePercent = ''; $barOneWidth = ''; $imgTwoPercent = ''; $barTwoWidth = ''; $permalinkJS = ''; $isShowVotes = false; if( $lastID > 0 ) { $res = $dbr->select( 'picturegame_images', '*', array( 'flag <> ' . PICTUREGAME_FLAG_FLAGGED, 'id' => $lastID ), __METHOD__ ); $row = $dbr->fetchObject( $res ); if( $row ) { $img_one = wfFindFile( $row->img1 ); $img_two = wfFindFile( $row->img2 ); $imgOneCount = $row->img0_votes; $imgTwoCount = $row->img1_votes; $isShowVotes = true; } } if( $isPermalink || $isShowVotes ) { if( is_object( $img_one ) ) { $vote_one_thumb = $img_one->getThumbnail( 40 ); } if( is_object( $vote_one_thumb ) ) { $vote_one_tag = $vote_one_thumb->toHtml(); } if( is_object( $img_two ) ) { $vote_two_thumb = $img_two->getThumbnail( 40 ); } if( is_object( $vote_two_thumb ) ) { $vote_two_tag = $vote_two_thumb->toHtml(); } $totalVotes = $imgOneCount + $imgTwoCount; if( $imgOneCount == 0 ) { $imgOnePercent = 0; $barOneWidth = 0; } else { $imgOnePercent = floor( $imgOneCount / $totalVotes * 100 ); $barOneWidth = floor( 200 * ( $imgOneCount / $totalVotes ) ); } if( $imgTwoCount == 0 ) { $imgTwoPercent = 0; $barTwoWidth = 0; } else { $imgTwoPercent = 100 - $imgOnePercent; $barTwoWidth = floor( 200 * ( $imgTwoCount / $totalVotes ) ); } $permalinkJS = "document.getElementById( 'voteStats' ).style.display = 'inline'; document.getElementById( 'voteStats' ).style.visibility = 'visible';"; } $output = ''; // set the page title //$wgOut->setPageTitle( $title_text ); // figure out if the user is an admin / the creator $editlinks = ''; if( $wgUser->isAllowed( 'picturegameadmin' ) ) { // If the user can edit, throw in some links $editlinks = ' - <a href="' . $this->getTitle()->escapeFullURL( 'picGameAction=adminPanel' ) . '"> ' . wfMsg( 'picturegame-adminpanel' ) . "</a> - <a href=\"javascript:PictureGame.protectImages('" . str_replace( "'", "\'", wfMsg( 'picturegame-protectimgconfirm' ) ) . "')\"> " . wfMsg( 'picturegame-protectimages' ) . '</a>'; } $createLink = ''; // Only registered users can create new picture games if( $wgUser->isLoggedIn() ) { $createLink = ' <div class="create-link"> <a href="' . $this->getTitle()->escapeFullURL( 'picGameAction=startCreate' ) . '"> <img src="' . $wgScriptPath . '/extensions/PictureGame/images/addIcon.gif" border="0" alt="" />' . wfMsg( 'picturegame-createlink' ) . '</a> </div>'; } $editLink = ''; if( $wgUser->isLoggedIn() && $wgUser->isAllowed( 'picturegameadmin' ) && $wgUseEditButtonFloat == true ) { $editLink .= '<div class="edit-menu-pic-game"> <div class="edit-button-pic-game"> <img src="' . $wgScriptPath . '/extensions/PictureGame/images/editIcon.gif" alt="" /> <a href="javascript:PictureGame.editPanel()">' . wfMsg( 'edit' ) . '</a> </div> </div>'; } $id = User::idFromName( $user_title->getText() ); $avatar = new wAvatar( $id, 'l' ); $avatarID = $avatar->getAvatarImage(); $stats = new UserStats( $id, $user_title->getText() ); $stats_data = $stats->getUserStats(); $preload = ''; $wgOut->setHTMLTitle( wfMsg( 'pagetitle', $title ) ); $wgOut->addScriptFile( $wgScriptPath . '/extensions/PictureGame/picturegame/LightBox.js' ); $next_id = ( isset( $next_id ) ? $next_id : 0 ); $output .= " <script type=\"text/javascript\">var next_id = \"{$next_id}\";</script> {$editLink} <div class=\"editDiv\" id=\"editDiv\" style=\"display: none\"> </div> <div class=\"serverMessages\" id=\"serverMessages\"></div> <div class=\"imgContent\" id=\"imgContent\"> <div class=\"imgTitle\" id=\"imgTitle\">" . $title . "</div> <div class=\"imgContainer\" id=\"imgContainer\" style=\"width:45%;\"> <div class=\"imgCaption\" id=\"imgOneCaption\">" . $img1_caption . "</div> <div class=\"imageOne\" id=\"imageOne\" style=\"padding:5px;\" onclick=\"PictureGame.castVote(0)\" onmouseover=\"PictureGame.doHover('imageOne')\" onmouseout=\"PictureGame.endHover('imageOne')\"> " . $imgOne . " </div> </div> <div class=\"imgContainer\" id=\"imgContainer\" style=\"width:45%;\"> <div class=\"imgCaption\" id=\"imgTwoCaption\">" . $img2_caption . "</div> <div class=\"imageTwo\" id=\"imageTwo\" style=\"padding:5px;\" onclick=\"PictureGame.castVote(1)\" onmouseover=\"PictureGame.doHover('imageTwo')\" onmouseout=\"PictureGame.endHover('imageTwo')\"> " . $imgTwo . " </div> </div> <div class=\"cleared\"></div> <div class=\"pic-game-navigation\"> <ul> <li id=\"backButton\" style=\"display:" . ( $lastID > 0 ? 'block' : 'none' ) . "\"> <a href=\"javascript:window.parent.document.location='" . $this->getTitle()->escapeFullURL( 'picGameAction=renderPermalink' ) . "&id=' + document.getElementById('lastid').value\">" . wfMsg( 'picturegame-backbutton' ) . "</a> </li> <li id=\"skipButton\" style=\"display:" . ( $next_id > 0 ? 'block' : 'none' ) . "\"> <a href=\"" . $this->getTitle()->escapeFullURL( 'picGameAction=startGame' ) . '">' . wfMsg( 'picturegame-skipbutton' ) . '</a> </li> </ul> </div> <form id="picGameVote" name="picGameVote" method="post" action="' . $this->getTitle()->escapeFullURL( 'picGameAction=castVote' ) . "\"> <input id=\"key\" name=\"key\" type=\"hidden\" value=\"" . md5( $imgID . $this->SALT ) . "\" /> <input id=\"id\" name=\"id\" type=\"hidden\" value=\"" . $imgID . "\" /> <input id=\"lastid\" name=\"lastid\" type=\"hidden\" value=\"" . $lastID . "\" /> <input id=\"nextid\" name=\"nextid\" type=\"hidden\" value=\"" . $next_id . "\" /> <input id=\"img\" name=\"img\" type=\"hidden\" value=\"\" /> </form> </div> <div class=\"other-info\"> {$createLink} <div class=\"credit-box\" id=\"creditBox\"> <h1>" . wfMsg( 'picturegame-submittedby' ) . "</h1> <div class=\"submitted-by-image\"> <a href=\"{$user_title->getFullURL()}\"> <img src=\"{$wgUploadPath}/avatars/{$avatarID}\" style=\"border:1px solid #d7dee8; width:50px; height:50px;\" alt=\"\" /> </a> </div> <div class=\"submitted-by-user\"> <a href=\"{$user_title->getFullURL()}\">{$user_name}</a> <ul> <li> <img src=\"{$wgScriptPath}/extensions/PictureGame/images/voteIcon.gif\" border=\"0\" alt=\"\" /> {$stats_data['votes']} </li> <li> <img src=\"{$wgScriptPath}/extensions/PictureGame/images/pencilIcon.gif\" border=\"0\" alt=\"\" /> {$stats_data['edits']} </li> <li> <img src=\"{$wgScriptPath}/extensions/PictureGame/images/commentsIcon.gif\" border=\"0\" alt=\"\" /> {$stats_data['comments']} </li> </ul> </div> <div class=\"cleared\"></div> </div> <div class=\"voteStats\" id=\"voteStats\" style=\"display:none\"> <div id=\"vote-stats-text\"> <h1>" . wfMsg( 'picturegame-previousgame' ) . " ({$totalVotes})</h1></div> <div class=\"vote-bar\"> <span class=\"vote-thumbnail\" id=\"one-vote-thumbnail\">{$vote_one_tag}</span> <span class=\"vote-percent\" id=\"one-vote-percent\">{$imgOnePercent}%</span> <span class=\"vote-blue\"> <img src=\"{$wgScriptPath}/extensions/PictureGame/images/vote-bar-blue.gif\" id=\"one-vote-width\" border=\"0\" style=\"width:{$barOneWidth}px;height:11px;\" alt=\"\" /> </span> </div> <div class=\"vote-bar\"> <span class=\"vote-thumbnail\" id=\"two-vote-thumbnail\">{$vote_two_tag}</span> <span class=\"vote-percent\" id=\"two-vote-percent\">{$imgTwoPercent}%</span> <span class=\"vote-red\"> <img src=\"{$wgScriptPath}/extensions/PictureGame/images/vote-bar-red.gif\" id=\"two-vote-width\" border=\"0\" style=\"width:{$barTwoWidth}px;height:11px;\" alt=\"\" /> </span> </div> </div> <div class=\"utilityButtons\" id=\"utilityButtons\"> <a href=\"javascript:PictureGame.flagImg('" . str_replace( "'", "\'", wfMsg( 'picturegame-flagimgconfirm' ) ) . "')\">" . wfMsg( 'picturegame-reportimages' ) . " </a> - <a href=\"javascript:window.parent.document.location='" . $this->getTitle()->escapeFullURL( 'picGameAction=renderPermalink' ) . "&id=' + document.getElementById('id').value\">" . wfMsg( 'picturegame-permalink' ) . '</a>' . $editlinks . " </div> </div> <div class=\"cleared\"></div> <script language=\"javascript\">{$permalinkJS}</script> <div id=\"preload\" style=\"display:none\"> {$preload} <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"75\" height=\"75\" title=\"hourglass\"> <param name=\"movie\" value=\"" . $wgScriptPath . "/extensions/PictureGame/picturegame/ajax-loading.swf\" /> <param name=\"quality\" value=\"high\" /> <param name=\"wmode\" value=\"transparent\" /> <param name=\"bgcolor\" value=\"#ffffff\" /> <embed src=\"" . $wgScriptPath . "/extensions/PictureGame/picturegame/ajax-loading.swf\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#ffffff\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"100\" height=\"100\"> </embed> </object> </div>"; // fix syntax coloring return $output; }
function execute() { global $wgUser, $wgOut, $wgRequest; $out = ""; $dbr =& wfGetDB(DB_SLAVE); $sql = " SELECT challenge.challenge_id, challenge_username1, challenge_username2, challenge_info, challenge_description, challenge_event_date, challenge_status, challenge_winner_username,challenge_winner_user_id,\n\t\t\tchallenge_rate_score, challenge_rate_comment\n\t\t\tFROM challenge LEFT JOIN challenge_rate ON challenge_rate.challenge_id=challenge.challenge_id WHERE 1=1 "; if ($_GET["user"]) { $title1 = Title::newFromDBkey($_GET["user"]); $dbr =& wfGetDB(DB_SLAVE); $s = $dbr->selectRow('user', array('user_id'), array('user_name' => $title1->getText()), $fname); if ($s === false) { $userid = 0; } else { $userid = $s->user_id; $avatar = new wAvatar($title1->getText(), "l"); $pos = $this->getRate(1, $userid); $neg = $this->getRate(-1, $userid); $neu = $this->getRate(0, $userid); $total = $pos + $neg + $neu; $percent = 0; if ($pos) { $percent = $pos / $total * 100; } $out .= "<br><table cellpadding=3 cellspacing=0><tr><td>\n\t\t\t\t\t<img src='images/avatars/" . $avatar->getAvatarImage() . "'>\n\t\t\t\t\t</td>"; $out .= "<td><span class=pagetitle>" . $title1->getText() . " Challenge History</span></td></tr></table>"; $out .= "<b>Overall Record</b>: (" . $this->getRecord($userid) . ")<br><br>"; $out .= "<b>Ratings When Loser</b>: <br>"; $out .= "<span class=challenge-rate-positive>Positive</span>: " . $pos . " (" . $percent . "%)<br>"; $out .= "<span class=challenge-rate-negative>Negative</span>: " . $neg . "<br>"; $out .= "<span class=challenge-rate-neutral>Neutral</span>: " . $neu . "<br><br>"; } $sql .= " and (challenge_user_id_1 = " . $userid . " OR challenge_user_id_2 = " . $userid . ") "; } else { $sql .= " and challenge_status <> -2 "; $out .= "<br><span class=pagetitle>Recent ArmchairGM Challenges</span><br><br>"; } if (isset($_GET["status"])) { $sql .= " and challenge_status = " . $_GET["status"]; } $sql .= " order by challenge_date DESC limit 0,50"; if ($title1) { if ($title1->getText() && $title1->getText() != $wgUser->mName) { $out .= '<input type="button" class="createbox" value="Challenge This User" style="color:#78BA5D;padding-right:3px;" onclick=window.location="index.php?title=Special:ChallengeUser&user='******'" /> '; } } $out .= "filter:\n\t\t\t<select style='font-size:10px' name=status-filter onChange=changeFilter('" . $_GET["user"] . "',this.value)>\n\t\t\t<option value='' " . ($_GET["status"] == "" && strlen($_GET["status"]) == 0 ? "selected" : "") . ">All</option>\n\t\t\t<option value=0 " . ($_GET["status"] == 0 && strlen($_GET["status"]) == 1 ? "selected" : "") . ">Awaiting Acceptance</option>\n\t\t\t<option value=1 " . ($_GET["status"] == 1 ? "selected" : "") . ">In progress</option>\n\t\t\t<option value=-1 " . ($_GET["status"] == -1 ? "selected" : "") . ">Rejected</option>\n\t\t\t<option value=3 " . ($_GET["status"] == 3 ? "selected" : "") . ">Completed</option>\n\t\t\t</select><br><br>\n\t\t\t\n\t\t\t<table cellpadding=3 cellspacing=0 border=0><tr>\n\t\t\t<td class=challenge-history-title>event</td>\n\t\t\t<td class=challenge-history-title>challenger description</td>\n\t\t\t<td class=challenge-history-title>challenger</td>\n\t\t\t<td class=challenge-history-title>target</td>\n\t\t\t<td class=challenge-history-title>status</td>\n\t\t\t\n\t\t\t<td class=challenge-history-title>loser's rating</td>\n\t\t\t</tr>"; $res = $dbr->query($sql); while ($row = $dbr->fetchObject($res)) { $avatar1 = new wAvatar($row->challenge_username1, "s"); $avatar2 = new wAvatar($row->challenge_username2, "s"); $title1 = Title::makeTitle(NS_USER, $row->challenge_username1); $title2 = Title::makeTitle(NS_USER, $row->challenge_username2); $user1Info = ""; $user2Info = ""; $user1Icon = ""; $user2Icon = ""; if ($row->challenge_winner_user_id != 0) { if ($row->challenge_username1 == $row->challenge_winner_username) { $user1Info = " style='font-weight:800'"; $user1Icon = "<img src=http://www.development.wikiscripts.org/images/winner-check.gif align=absmiddle>"; } else { $user2Info = " style='font-weight:800'"; $user2Icon = "<img src=http://www.development.wikiscripts.org/images/winner-check.gif align=absmiddle>"; } } $out .= "<tr>\n\t\t\t\t\t\t\t<td class=challenge-data><a href=index.php?title=Special:ChallengeView&id=" . $row->challenge_id . ">" . $row->challenge_info . " [" . $row->challenge_event_date . "]</a></td>\n\t\t\t\t\t\t\t<td class=challenge-data width=200>" . $row->challenge_description . "</td>\n\t\t\t\t\t\t\t<td class=challenge-data " . $user1Info . "><img src='images/avatars/" . $avatar1->getAvatarImage() . "' align=absmiddle><a href=index.php?title=Special:ChallengeHistory&user="******">" . $row->challenge_username1 . "</a> " . $user1Icon . "</td>\n\t\t\t\t\t\t\t<td class=challenge-data " . $user2Info . "><img src='images/avatars/" . $avatar2->getAvatarImage() . "' align=absmiddle><a href=index.php?title=Special:ChallengeHistory&user="******">" . $row->challenge_username2 . "</a> " . $user2Icon . "</td>\n\t\t\t\t\t\t\t<td class=challenge-data>"; switch ($row->challenge_status) { case -1: $out .= "<span class=challenge-rejected>rejected</span>"; break; case -2: $out .= "<span class=challenge-rejected>removed</span>"; break; case 0: $out .= "awaiting acceptance"; break; case 1: if (1 == 2) { $out .= "accepted"; } else { $out .= "in progress"; } break; case 3: $out .= "<span style='font-weight:800' class=challenge-status-complete>completed</span>"; break; } $out .= "</td><td class=challenge-data>"; if ($row->challenge_rate_score == NULL) { $out .= "-"; } else { switch ($row->challenge_rate_score) { case 0: $out .= "<span class=challenge-rate-neutral>neutral</span>"; break; case 1: $out .= "<span class=challenge-rate-positive>positive</span>"; break; case -1: $out .= "<span class=challenge-rate-negative>negative</span>"; break; } } $out .= "</td>\n\t\t\t\t\t\t</tr>"; } $out .= "</table>"; $wgOut->addScript("<script type=\"text/javascript\" src=\"extensions/Challenge/Challenge.js\"></script>\n"); $wgOut->addHTML($out); }