function wfVoteStarsDelete($pageId) { global $wgUser; if (!$wgUser->isAllowed('voteny')) { return ''; } $vote = new VoteStars($pageId); $vote->delete(); return $vote->display(); }
function execute() { global $wgUser, $wgOut, $wgVoteDirectory, $wgCommentsDirectory, $IP; require_once "{$wgVoteDirectory}/VoteClass.php"; require_once "{$wgVoteDirectory}/Publish.php"; require_once "{$wgVoteDirectory}/RSS.php"; require_once "{$wgCommentsDirectory}/CommentClass.php"; if ($_POST["mk"] == md5($_POST["pid"] . 'pants' . $wgUser->mName)) { require_once "{$IP}/extensions/UserStats/UserStatsClass.php"; $stats = new UserStatsTrack(1, $wgUser->mId, $wgUser->mName); if (($_GET["Action"] == 1 || $_GET["Action"] == 2) && is_numeric($_POST["pid"]) && (is_numeric($_POST["TheVote"]) || $_GET["Action"] == 2)) { //echo 'test2'; $Vote = new Vote($_POST["pid"]); $Vote->setUser($wgUser->mName, $wgUser->mId); if ($_GET["Action"] == 1) { $Vote->insert($_POST["TheVote"]); $stats->incVoteCount(); } else { $Vote->delete(); } $CommentList = new Comment($_POST["pid"]); $publish = new Publish(); $publish->PageID = $_POST["pid"]; $publish->VoteCount = $Vote->count(1); $publish->CommentCount = $CommentList->count(); $publish->check_score(); echo $Vote->count(1); } if ($_GET["Action"] == 3) { $Vote = new VoteStars($_POST["pid"]); $Vote->setUser($wgUser->mName, $wgUser->mId); $Vote->insert($_POST["TheVote"]); $stats->incVoteCount(); echo $Vote->display(); } if ($_GET["Action"] == 4) { $Vote = new VoteStars($_POST["pid"]); $Vote->setUser($wgUser->mName, $wgUser->mId); $Vote->delete(); echo $Vote->display(); } } // This line removes the navigation and everything else from the // page, if you don't set it, you get what looks like a regular wiki // page, with the body you defined above. $wgOut->setArticleBodyOnly(true); }
/** * Show the special page * * @param mixed|null $par Parameter passed to the special page or null */ public function execute($par) { // Set the page title, robot policies, etc. $this->setHeaders(); $out = $this->getOutput(); $user = $this->getUser(); $categoryName = $namespace = ''; // Parse the parameters passed to the special page // Make sure that the limit parameter passed to the special page is // an integer and that it's less than 100 (performance!) if (isset($par) && is_numeric($par) && $par < 100) { $limit = intval($par); } elseif (isset($par) && !is_numeric($par)) { // $par is a string...assume that we can explode() it $exploded = explode('/', $par); $categoryName = $exploded[0]; $namespace = isset($exploded[1]) ? intval($exploded[1]) : $namespace; $limit = isset($exploded[2]) ? intval($exploded[2]) : 50; } else { $limit = 50; } // Add CSS $out->addModuleStyles('ext.voteNY.styles'); /* scroll down some lines to see why I'm not including JS here anymore if ( $user->isAllowed( 'voteny' ) ) { $out->addModules( 'ext.voteNY.scripts' ); } */ $ratings = array(); $output = ''; $dbr = wfGetDB(DB_SLAVE); $tables = $where = $joinConds = array(); $whatToSelect = array('DISTINCT vote_page_id'); // By default we have no category and no namespace $tables = array('Vote'); $where = array('vote_page_id <> 0'); // isset(), because 0 is a totally valid NS if (!empty($categoryName) && isset($namespace)) { $tables = array('Vote', 'page', 'categorylinks'); $where = array('vote_page_id <> 0', 'cl_to' => str_replace(' ', '_', $categoryName), 'page_namespace' => $namespace); $joinConds = array('categorylinks' => array('INNER JOIN', 'cl_from = page_id'), 'page' => array('INNER JOIN', 'page_id = vote_page_id')); } // Perform the SQL query with the given conditions; the basic idea is // that we get $limit (however, 100 or less) unique page IDs from the // Vote table. If a category and a namespace have been given, we also // do an INNER JOIN with page and categorylinks table to get the // correct data. $res = $dbr->select($tables, $whatToSelect, $where, __METHOD__, array('LIMIT' => intval($limit)), $joinConds); foreach ($res as $row) { // Add the results to the $ratings array and get the amount of // votes the given page ID has // For example: $ratings[1] = 11 = page with the page ID 1 has 11 // votes $ratings[$row->vote_page_id] = (int) $dbr->selectField('Vote', 'SUM(vote_value)', array('vote_page_id' => $row->vote_page_id), __METHOD__); } // If we have some ratings, start building HTML output if (!empty($ratings)) { /* XXX dirrrrrrty hack! because when we include this page, the JS * is not included, but we want things to work still * Actually, this is way harder than what it looks like. * The JS uses wgArticleId but when directly viewing Special:TopRatings, * wgArticleId is zero, because special pages aren't articles. * As for including the special page, then wgArticleId would likely * point at the ID of the page that includes {{Special:TopRatings}}, * which would be stupid and wrong. * Besides, shouldn't you check out the images/pages that you're gonna * vote for? Yeah, that's what I thought, too. if ( $this->including() && $user->isAllowed( 'voteny' ) ) { global $wgExtensionAssetsPath; $output .= '<script type="text/javascript" src="' . $wgExtensionAssetsPath . '/VoteNY/Vote.js"></script>'; } */ // yes, array_keys() is needed foreach (array_keys($ratings) as $discardThis => $pageId) { $titleObj = Title::newFromId($pageId); if (!$titleObj instanceof Title) { continue; } $vote = new VoteStars($pageId); $output .= '<div class="user-list-rating">' . Linker::link($titleObj, $titleObj->getPrefixedText()) . $this->msg('word-separator')->escaped() . $this->msg('parentheses', $ratings[$pageId])->escaped() . '</div>'; $id = mt_rand(); // AFAIK these IDs are and originally were totally random... $output .= "<div id=\"rating_stars_{$id}\">" . $vote->displayStars($id, self::getAverageRatingForPage($pageId), false) . '</div>'; $output .= "<div id=\"rating_{$id}\" class=\"rating-total\">" . $vote->displayScore() . '</div>'; } } else { // Nothing? Well, display an informative error message rather than // a blank page or somesuch. $output .= $this->msg('topratings-no-pages')->escaped(); } // Output everything! $out->addHTML($output); }
/** * Show the special page * * @param $par Mixed: parameter passed to the special page or null */ public function execute( $par ) { global $wgOut, $wgScriptPath; // Set the page title, robot policies, etc. $this->setHeaders(); $categoryName = $namespace = ''; // Parse the parameters passed to the special page // Make sure that the limit parameter passed to the special page is // an integer and that it's less than 100 (performance!) if ( isset( $par ) && is_numeric( $par ) && $par < 100 ) { $limit = intval( $par ); } elseif ( isset( $par ) && !is_numeric( $par ) ) { // $par is a string...assume that we can explode() it $exploded = explode( '/', $par ); $categoryName = $exploded[0]; $namespace = ( isset( $exploded[1] ) ? intval( $exploded[1] ) : $namespace ); $limit = ( isset( $exploded[2] ) ? intval( $exploded[2] ) : 50 ); } else { $limit = 50; } // Add JS (and CSS) -- needed so that users can vote on this page and // so that their browsers' consoles won't be filled with JS errors ;-) $wgOut->addModules( 'ext.voteNY' ); $ratings = array(); $output = ''; $dbr = wfGetDB( DB_SLAVE ); $tables = $where = $joinConds = array(); $whatToSelect = array( 'DISTINCT vote_page_id' ); // By default we have no category and no namespace $tables = array( 'Vote' ); $where = array( 'vote_page_id <> 0' ); // isset(), because 0 is a totally valid NS if ( !empty( $categoryName ) && isset( $namespace ) ) { $tables = array( 'Vote', 'page', 'categorylinks' ); $where = array( 'vote_page_id <> 0', 'cl_to' => str_replace( ' ', '_', $categoryName ), 'page_namespace' => $namespace ); $joinConds = array( 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ), 'page' => array( 'INNER JOIN', 'page_id = vote_page_id' ) ); } // Perform the SQL query with the given conditions; the basic idea is // that we get $limit (however, 100 or less) unique page IDs from the // Vote table. If a category and a namespace have been given, we also // do an INNER JOIN with page and categorylinks table to get the // correct data. $res = $dbr->select( $tables, $whatToSelect, $where, __METHOD__, array( 'LIMIT' => intval( $limit ) ), $joinConds ); foreach ( $res as $row ) { // Add the results to the $ratings array and get the amount of // votes the given page ID has // For example: $ratings[1] = 11 = page with the page ID 1 has 11 // votes $ratings[$row->vote_page_id] = (int)$dbr->selectField( 'Vote', 'SUM(vote_value)', array( 'vote_page_id' => $row->vote_page_id ), __METHOD__ ); } // If we have some ratings, start building HTML output if ( !empty( $ratings ) ) { /* XXX dirrrrrrty hack! because when we include this page, the JS is not included, but we want things to work still */ if ( $this->including() ) { $output .= '<script type="text/javascript" src="' . $wgScriptPath . '/extensions/VoteNY/Vote.js"></script>'; } // yes, array_keys() is needed foreach ( array_keys( $ratings ) as $discardThis => $pageId ) { $titleObj = Title::newFromId( $pageId ); if ( !( $titleObj instanceof Title ) ) { continue; } $vote = new VoteStars( $pageId ); $output .= '<div class="user-list-rating">' . Linker::link( $titleObj, $titleObj->getPrefixedText() // prefixed, so that the namespace shows! ) . wfMsg( 'word-separator' ) . // i18n overkill? ya betcha... wfMsg( 'parentheses', $ratings[$pageId] ) . '</div>'; $id = mt_rand(); // AFAIK these IDs are and originally were totally random... $output .= "<div id=\"rating_stars_{$id}\">" . $vote->displayStars( $id, self::getAverageRatingForPage( $pageId ), false ) . '</div>'; $output .= "<div id=\"rating_{$id}\" class=\"rating-total\">" . $vote->displayScore() . '</div>'; } } else { // Nothing? Well, display an informative error message rather than // a blank page or somesuch. $output .= wfMsg( 'topratings-no-pages' ); } // Output everything! $wgOut->addHTML( $output ); }
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; }
function displayListDB() { global $wgUser; global $wgLang; global $wgContLang; global $wgTitle; global $wgOut; $sk =& $wgUser->getSkin(); $dbr =& wfGetDB(DB_SLAVE); //echo $this->buildSQL(); $res = $dbr->query($this->buildSQL()); if ($dbr->numRows($res) == 0) { return htmlspecialchars("No pages found."); } $output = ""; $output .= "<div id=\"ListPages" . $this->listid . "\">"; $output .= "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>" . "\n"; $ListCount = 0; $ListCountShow = 0; while ($row = $dbr->fetchObject($res)) { if ($ListCountShow < $this->ShowCount - 1) { $title = Title::makeTitle($row->page_namespace, $row->page_title); $output .= "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"listpageItem\">"; // ** MAIN ROW // Picture (optional) + Title $output .= "<tr>"; if ($this->ShowPic == 1) { $PageImage = $this->getPageImage($row->page_id); if ($PageImage) { $output .= "<td class=\"listpage\" rowspan=\"5\" valign=\"top\" style='padding-right:20px'>"; $img = Image::newFromName($PageImage); $img_tag = '<img src="' . $img->getURL() . '" alt="' . $PageImage . '" width="65"/>'; $output .= $img_tag; //str_replace("</p>","",str_replace("<p>","",$img->getText())); $output .= "</td>"; } } if ($this->ShowVoteBox == 1) { $output .= "<td width=\"30\">" . $this->getVoteBox($row->vote_count) . "</td><td width=\"8\"></td>"; } if ($this->ShowCommentBox == 1) { $output .= "<td width=\"30\">" . $this->getCommentBox($row->comment_count) . "</td><td width=\"8\"></td>"; } if ($this->ShowDetails == 1) { $output .= '<td class="showdetails" ' . ($this->ShowVoteBox == 1 || $this->ShowCommentBox == 1 ? 'valign="top"' : '') . '>'; } else { $output .= '<td class="hidedetails" ' . ($this->ShowVoteBox == 1 || $this->ShowCommentBox == 1 ? 'valign="top"' : '') . '>'; } // ** Display Link if ($row->page_namespace != 6) { //$output .= $sk->makeKnownLinkObj($title, $wgContLang->convertHtml($title->getText())); $output .= '<a href="' . $title->getFullURL() . '" title="' . $title->getText() . '">' . $title->getText() . '</a>'; } else { $CommentParser = new Parser(); $img = $CommentParser->parse("[[Image:" . $row->page_title . "|75px]]", $wgTitle, $wgOut->mParserOptions, true); $output .= $img->getText(); } $output .= "</td>"; $output .= "</tr>"; // ** END Main Row // ** Display Create Date if ($this->ShowDate == 1) { $output .= "<tr>"; $output .= '<td class="listdate">'; $output .= "(created " . $this->getTimeStr($row->page_id) . " ago)"; //date("D m/d/y, g:i a T",$this->getCreateDate($row->page_id) - (60 * 60 * 1)); $output .= '</td>'; $output .= "</tr>"; } // ** Display Average Score + Stars Graphics if ($this->ShowRating == 1) { $Vote = new VoteStars($row->page_id); $output .= "<tr>"; $output .= '<td class="listrating">'; $output .= "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td><span class=\"listrating-score-title\">Score:</span> <span class=\"listrating-score\">" . number_format($row->vote_avg, 2) . "</span></td><td>" . $Vote->displayRating($row->vote_avg) . "</td></tr></table>"; $output .= "</td>"; $output .= "</tr>"; } // ** Display Blurb of N Characters (stored in ShowBlurb) if ($this->ShowBlurb > 0) { $output .= "<tr>"; $output .= "<td class=\"listblurb\">"; $output .= $this->getBlurb($row->page_title); $output .= '</td>'; $output .= "</tr>"; } // ** Show most popular categories for current page if ($this->ShowCtg == 1) { $output .= "<tr>"; $output .= "<td class=\"categorylinks\">"; $output .= $this->getCategoryLinks($row->page_id, 3); $output .= '</td>'; $output .= "</tr>"; } // ** Show Stats for page if ($this->ShowStats == 1) { $output .= "<tr>"; $output .= '<td class="liststats"><span class="liststatstitle">stats</span>: '; if ($this->Order != 'VOTES') { $output .= '<img src="images/voteIcon.gif" alt="v" /> ' . $row->vote_count . ' votes'; } if ($this->Order == 'PAGEVIEWS') { $output .= ' [' . $row->page_counter . ' Views]'; } if ($this->Order == 'VOTES') { $output .= '<img src="images/voteIcon.gif" alt="v" /> ' . $row->vote_count . ' votes'; } if ($this->Order == 'EDITS') { $output .= ' [' . $row->Num_Edits . ' Edits]'; } if ($this->Order == 'LATEST') { $output .= ' [Updated ' . wfTimestamp(TS_RFC2822, $row->page_touched) . ']'; } if ($this->ShowRating == 1) { $CommentLabel = "reviews"; } else { $CommentLabel = "comments"; } $output .= ' <img src="images/commentIcon.gif" alt="c" /> ' . $row->comment_count . ' ' . $CommentLabel . '</td>'; $output .= "</tr>"; } $ListCountShow++; $output .= "</table>"; } $ListCount++; } if ($this->ShowNav == 1) { $output .= "<div id=\"listpagesnav\">"; if ($this->PageNo == 1) { $output .= $this->getNavLink("Prev", 0); } else { $output .= $this->getNavLink("Prev", -1); } $output .= " "; if ($ListCount > $ListCountShow) { $output .= $this->getNavLink("Next", 1); } else { $output .= $this->getNavLink("Next", 0); } $output .= "</div>"; } $output .= "</td></tr></table>"; $output .= "</div>"; return $output; }