/** * 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); }
/** * Callback function for the <pollembed> tag. * * @param $input Mixed: user input * @param $args Array: arguments supplied to the pollembed tag * @param $parser Object: instance of Parser class * @return HTML or nothing */ public static function renderEmbedPoll($input, $args, $parser) { $poll_name = $args['title']; if ($poll_name) { global $wgOut, $wgUser, $wgScriptPath; // Load CSS for non-Monaco skins - Monaco's ny.css already contains // PollNY's styles (and more) if (get_class($wgUser->getSkin()) !== 'SkinMonaco') { $wgOut->addExtensionStyle($wgScriptPath . '/extensions/PollNY/Poll.css'); } // Disable caching; this is important so that we don't cause subtle // bugs that are a bitch to fix. $wgOut->enableClientCache(false); $parser->disableCache(); $poll_title = Title::newFromText($poll_name, NS_POLL); $poll_title = PollNYHooks::followPollID($poll_title); $poll_page_id = $poll_title->getArticleID(); if ($poll_page_id > 0) { $p = new Poll(); $poll_info = $p->getPoll($poll_page_id); $output = "\t\t" . '<div class="poll-embed-title">' . $poll_info['question'] . '</div>' . "\n"; if ($poll_info['image']) { $poll_image_width = 100; $poll_image = wfFindFile($poll_info['image']); $width = $poll_image_url = ''; 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 .= "\t\t<div class=\"poll-image\">{$poll_image_tag}</div>\n"; } // If the user hasn't voted for this poll yet and the poll is open // for votes, display the question and let the user vote if (!$p->userVoted($wgUser->getName(), $poll_info['id']) && $poll_info['status'] == 1) { $wgOut->addScriptFile($wgScriptPath . '/extensions/PollNY/Poll.js'); $wgOut->addScript("<script type=\"text/javascript\">\$( function() { PollNY.showEmbedPoll({$poll_info['id']}); } );</script>\n"); $output .= "<div id=\"loading-poll_{$poll_info['id']}\">" . wfMsg('poll-js-loading') . '</div>'; $output .= "<div id=\"poll-display_{$poll_info['id']}\" style=\"display:none;\">"; $output .= "<form name=\"poll_{$poll_info['id']}\"><input type=\"hidden\" id=\"poll_id_{$poll_info['id']}\" name=\"poll_id_{$poll_info['id']}\" value=\"{$poll_info['id']}\"/>"; foreach ($poll_info['choices'] as $choice) { $output .= "<div class=\"poll-choice\">\n\t\t\t\t\t\t<input type=\"radio\" name=\"poll_choice\" onclick=\"PollNY.pollEmbedVote({$poll_info['id']}, {$poll_page_id})\" id=\"poll_choice\" value=\"{$choice['id']}\">{$choice['choice']}\n\t\t\t\t\t\t</div>"; } $output .= '</div> </form>'; } else { // Display message if poll has been closed for voting if ($poll_info['status'] == 0) { $output .= '<div class="poll-closed">' . wfMsg('poll-closed') . '</div>'; } $x = 1; foreach ($poll_info['choices'] as $choice) { //$percent = round( $choice['votes'] / $poll_info['votes'] * 100 ); if ($poll_info['votes'] > 0) { $bar_width = floor(480 * ($choice['votes'] / $poll_info['votes'])); } $bar_img = "<img src=\"{$wgScriptPath}/extensions/PollNY/images/vote-bar-{$x}.gif\" border=\"0\" class=\"image-choice-{$x}\" style=\"width:{$choice['percent']}%;height:12px;\" alt=\"\" />"; $output .= "<div class=\"poll-choice\">\n\t\t\t\t\t\t<div class=\"poll-choice-left\">{$choice['choice']} ({$choice['percent']}%)</div>"; // If the amount of votes is not set, set it to 0 // This fixes an odd bug where "votes" would be shown // instead of "0 votes" when using the pollembed tag. if (empty($choice['votes'])) { $choice['votes'] = 0; } $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>'; $output .= '<div><a href="' . $poll_title->escapeFullURL() . '">' . wfMsg('poll-discuss') . '</a></div>'; $output .= '<div class="poll-timestamp">' . wfMsg('poll-createdago', Poll::getTimeAgo($poll_info['timestamp'])) . '</div>'; } return $output; } else { // Poll doesn't exist or is unavailable for some other reason $output = '<div class="poll-embed-title">' . wfMsg('poll-unavailable') . '</div>'; return $output; } } return ''; }
/** * 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, $wgScriptPath, $wgPollScripts; // Add CSS & JS $wgOut->addExtensionStyle( $wgPollScripts . '/Poll.css' ); $wgOut->addScriptFile( $wgPollScripts . '/Poll.js' ); // Page either most or newest for everyone $type = $wgRequest->getVal( 'type' ); if( !$type ) { $type = 'most'; } // ORDER BY for SQL query if( $type == 'newest' ) { $order = 'poll_id'; } if( $type == 'most' ) { $order = 'poll_vote_count'; } // Display only a user's most or newest $user_link = ''; // Pagination $per_page = 20; $page = $wgRequest->getInt( 'page', 1 ); $limit = $per_page; $limitvalue = 0; if ( $limit > 0 && $page ) { $limitvalue = $page * $limit - ( $limit ); } // Safelinks $random_poll_link = SpecialPage::getTitleFor( 'RandomPoll' ); $output = ' <div class="view-poll-top-links"> <a href="' . $random_poll_link->escapeFullURL() . '">' . wfMsg( 'poll-take-button' ) . '</a> </div> <div class="view-poll-navigation"> <h2>' . wfMsg( 'poll-view-order' ) . '</h2>'; $dbr = wfGetDB( DB_SLAVE ); $where = array(); $user = $wgRequest->getVal( 'user' ); if ( $user ) { $where['poll_user_name'] = $dbr->strencode( $user ); $user_link = '&user='******'newest' ) { $output .= '<p><a href="' . $wgScriptPath . "/index.php?title=Special:ViewPoll&type=most{$user_link}\">" . wfMsg( 'poll-view-popular' ) . '</a></p><p><b>' . wfMsg( 'poll-view-newest' ) . '</b></p>'; } else { $output .= '<p><b>' . wfMsg( 'poll-view-popular' ) . '</b></p><p><a href="' . $wgScriptPath . "/index.php?title=Special:ViewPoll&type=newest{$user_link}\">" . wfMsg( 'poll-view-newest' ) . '</a></p>'; } $output .= '</div>'; if ( isset( $user ) ) { $wgOut->setPageTitle( wfMsgExt( 'poll-view-title', 'parsemag', $user ) ); } else { $wgOut->setPageTitle( wfMsgHtml( 'viewpoll' ) ); } $res = $dbr->select( array( 'poll_question', 'page' ), array( 'poll_user_id', 'UNIX_TIMESTAMP(poll_date) AS poll_time', 'poll_vote_count', 'poll_user_name', 'poll_text', 'poll_page_id', 'page_id' ), $where, __METHOD__, array( 'ORDER BY' => "$order DESC", 'LIMIT' => $limit, 'OFFSET' => $limitvalue ), array( 'page' => array( 'INNER JOIN', 'poll_page_id = page_id' ) ) ); $res_total = $dbr->select( 'poll_question', 'COUNT(*) AS total_polls', ( ( $user ) ? array( 'poll_user_name' => $dbr->strencode( $user ) ) : array() ), __METHOD__ ); $row_total = $dbr->fetchObject( $res_total ); $total = $row_total->total_polls; $output .= '<div class="view-poll">'; $x = ( ( $page - 1 ) * $per_page ) + 1; 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; $row_id = "poll-row-{$x}"; $title = Title::makeTitle( NS_POLL, $poll_title ); if( ( $x < $dbr->numRows( $res ) ) && ( $x % $per_page != 0 ) ) { $output .= "<div class=\"view-poll-row\" id=\"{$row_id}\" onmouseover=\"PollNY.doHover('{$row_id}')\" onmouseout=\"PollNY.endHover('{$row_id}')\" onclick=\"window.location='{$title->escapeFullURL()}'\">"; } else { $output .= "<div class=\"view-poll-row-bottom\" id=\"{$row_id}\" onmouseover=\"PollNY.doHover('{$row_id}')\" onmouseout=\"PollNY.endHover('{$row_id}')\" onclick=\"window.location='{$title->escapeFullURL()}'\">"; } $output .= "<div class=\"view-poll-number\">{$x}.</div> <div class=\"view-poll-user-image\"> {$avatar->getAvatarURL()} </div> <div class=\"view-poll-user-name\">{$user_create}</div> <div class=\"view-poll-text\"> <p><b><u>{$poll_title}</u></b></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> </div> <div class="cleared"></div> </div>'; $x++; } $output .= '</div> <div class="cleared"></div>'; $numofpages = $total / $per_page; if( $numofpages > 1 ) { $output .= '<div class="view-poll-page-nav">'; if( $page > 1 ) { $output .= '<a href="' . $wgScriptPath . '/index.php?title=Special:ViewPoll&type=most' . $user_link . '&page=' . ( $page - 1 ) . '">' . wfMsg( 'poll-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:ViewPoll&type=most' . $user_link . '&page=' . $i . '">' . $i . '</a> '; } } if( ( $total - ( $per_page * $page ) ) > 0 ) { $output .= ' <a href="' . $wgScriptPath . '/index.php?title=Special:ViewPoll&type=most' . $user_link . '&page=' . ( $page + 1 ) . '">' . wfMsg( 'poll-next' ) . '</a>'; } $output .= '</div>'; } $wgOut->addHTML( $output ); }