function showDiffPage($diffOnly = false) { global $wgUser, $wgOut, $wgUseExternalEditor, $wgUseRCPatrol, $wgRequest, $wgTitle, $wgLanguageCode; $fname = 'DifferenceEngine::showDiffPage'; wfProfileIn($fname); # If external diffs are enabled both globally and for the user, # we'll use the application/x-external-editor interface to call # an external diff tool like kompare, kdiff3, etc. if ($wgUseExternalEditor && $wgUser->getOption('externaldiff')) { global $wgInputEncoding, $wgServer, $wgScript, $wgLang; $wgOut->disable(); header("Content-type: application/x-external-editor; charset=" . $wgInputEncoding); $url1 = $this->mTitle->getFullURL("action=raw&oldid=" . $this->mOldid); $url2 = $this->mTitle->getFullURL("action=raw&oldid=" . $this->mNewid); $special = $wgLang->getNsText(NS_SPECIAL); $control = <<<CONTROL [Process] Type=Diff text Engine=MediaWiki Script={$wgServer}{$wgScript} Special namespace={$special} [File] Extension=wiki URL={$url1} [File 2] Extension=wiki URL={$url2} CONTROL; echo $control; return; } $wgOut->setArticleFlag(false); if (!$this->loadRevisionData()) { $t = $this->mTitle->getPrefixedText() . " (Diff: {$this->mOldid}, {$this->mNewid})"; $wgOut->setPagetitle(wfMsg('errorpagetitle')); $wgOut->addWikiMsg('missingarticle', "<nowiki>{$t}</nowiki>"); wfProfileOut($fname); return; } wfRunHooks('DiffViewHeader', array($this, $this->mOldRev, $this->mNewRev)); if ($this->mNewRev->isCurrent()) { $wgOut->setArticleFlag(true); } # mOldid is false if the difference engine is called with a "vague" query for # a diff between a version V and its previous version V' AND the version V # is the first version of that article. In that case, V' does not exist. if ($this->mOldid === false && false) { $this->showFirstRevision(); $this->renderNewRevision(); // should we respect $diffOnly here or not? wfProfileOut($fname); return; } $wgOut->suppressQuickbar(); if (!$this->mOldPage) { $this->mOldPage = $this->mNewPage; } $oldTitle = $this->mOldPage->getPrefixedText(); $newTitle = $this->mNewPage->getPrefixedText(); if ($oldTitle == $newTitle) { $wgOut->setPageTitle($newTitle); } else { $wgOut->setPageTitle($oldTitle . ', ' . $newTitle); } $wgOut->setSubtitle(wfMsg('difference')); $wgOut->setRobotpolicy('noindex,nofollow'); if (!($this->mOldPage->userCanRead() && $this->mNewPage->userCanRead())) { $wgOut->loginToUse(); $wgOut->output(); wfProfileOut($fname); exit; } $sk = $wgUser->getSkin(); if ($this->mNewRev->isCurrent() && $wgUser->isAllowed('rollback') && $this->mTitle->userCanEdit()) { $rollback = $sk->generateRollback($this->mNewRev); } else { $rollback = ''; } // Prepare a change patrol link, if applicable if ($wgUseRCPatrol && $wgUser->isAllowed('patrol')) { // If we've been given an explicit change identifier, use it; saves time if ($this->mRcidMarkPatrolled) { $rcid = $this->mRcidMarkPatrolled; } else { // Look for an unpatrolled change corresponding to this diff $db = wfGetDB(DB_SLAVE); $change = RecentChange::newFromConds(array('rc_user_text' => $this->mNewRev->getRawUserText(), 'rc_timestamp' => $db->timestamp($this->mNewRev->getTimestamp()), 'rc_this_oldid' => $this->mNewid, 'rc_last_oldid' => $this->mOldid, 'rc_patrolled' => 0), __METHOD__); if ($change instanceof RecentChange) { $rcid = $change->mAttribs['rc_id']; } else { // None found $rcid = 0; } } // Build the link if ($rcid) { //XXCHANGED for recent changes patrolling $show_namespace = $wgRequest->getVal('show_namespace'); $invert = $wgRequest->getVal('invert'); $featured = $wgRequest->getVal('featured'); $reverse = $wgRequest->getVal('reverse'); //XXCHANGED $fromrc = ""; if ($wgRequest->getVal('fromrc', null) != null) { $fromrc = "&fromrc=1"; } if ($this->mRcidMarkPatrolledCount > 1) { $msg = wfMsg('markaspatrolleddiff_multiple', $this->mRcidMarkPatrolledCount); $patrol = '[' . $sk->makeKnownLinkObj($this->mTitle, $msg, "action=markpatrolled&rcid={$this->mRcidMarkPatrolled}&show_namespace={$show_namespace}" . "&invert={$invert}&reverse={$reverse}&featured={$featured}" . "&rchi={$this->mRcidMarkPatrolledMax}&rclow={$this->mRcidMarkPatrolledMin}{$fromrc}", '', '', "accesskey='p'") . ']'; $patrol .= '[' . $sk->makeKnownLinkObj($this->mTitle, wfMsg('skip'), "action=markpatrolled&rcid={$this->mRcidMarkPatrolled}&show_namespace={$show_namespace}" . "&invert={$invert}&reverse={$reverse}&featured={$featured}" . "&rchi={$this->mRcidMarkPatrolledMax}&rclow={$this->mRcidMarkPatrolledMin}{$fromrc}&skip=1", '', '', "") . ']'; } else { $patrol = '[' . $sk->makeKnownLinkObj($this->mTitle, wfMsg('markaspatrolleddiff'), "action=markpatrolled&rcid={$rcid}&show_namespace={$show_namespace}&invert={$invert}&reverse={$reverse}&featured={$featured}{$fromrc}", '', '', "accesskey='p'") . ']'; $patrol .= ' [' . $sk->makeKnownLinkObj($this->mTitle, wfMsg('skip'), "action=markpatrolled&rcid={$this->mRcidMarkPatrolled}&show_namespace={$show_namespace}&invert={$invert}&reverse={$reverse}&featured={$featured}&skip=1{$fromrc}") . ']'; } $patrol = "<span id='markaspatrolledlinks'>{$patrol}</span>"; //XXADDED } else { $patrol = ''; } } else { $patrol = ''; } //XXADDED if ($wgUser->isAllowed('rollback') && $this->mTitle->userCanEdit()) { //$rollback .= '<br/> <strong>' . SpamDiffTool::getDiffLink($this->mTitle) . '</strong>'; } $prevlink = $sk->makeKnownLinkObj($this->mTitle, wfMsgHtml('previousdiff'), 'diff=prev&oldid=' . $this->mOldid, '', '', 'id="differences-prevlink"'); if ($this->mNewRev->isCurrent()) { $nextlink = ''; } else { $nextlink = $sk->makeKnownLinkObj($this->mTitle, wfMsgHtml('nextdiff'), 'diff=next&oldid=' . $this->mNewid, '', '', 'id="differences-nextlink"'); } $oldminor = ''; $newminor = ''; if ($this->mOldRev->mMinorEdit == 1) { $oldminor = wfElement('span', array('class' => 'minor'), wfMsg('minoreditletter')) . ' '; } if ($this->mNewRev->mMinorEdit == 1) { $newminor = wfElement('span', array('class' => 'minor'), wfMsg('minoreditletter')) . ' '; } $rdel = ''; $ldel = ''; if ($wgUser->isAllowed('deleterevision')) { $revdel = SpecialPage::getTitleFor('Revisiondelete'); if (!$this->mOldRev->userCan(Revision::DELETED_RESTRICTED)) { // If revision was hidden from sysops $ldel = wfMsgHtml('rev-delundel'); } else { $ldel = $sk->makeKnownLinkObj($revdel, wfMsgHtml('rev-delundel'), 'target=' . urlencode($this->mOldRev->mTitle->getPrefixedDbkey()) . '&oldid=' . urlencode($this->mOldRev->getId())); // Bolden oversighted content if ($this->mOldRev->isDeleted(Revision::DELETED_RESTRICTED)) { $ldel = "<strong>{$ldel}</strong>"; } } $ldel = " <tt>(<small>{$ldel}</small>)</tt> "; // We don't currently handle well changing the top revision's settings if ($this->mNewRev->isCurrent()) { // If revision was hidden from sysops $rdel = wfMsgHtml('rev-delundel'); } else { if (!$this->mNewRev->userCan(Revision::DELETED_RESTRICTED)) { // If revision was hidden from sysops $rdel = wfMsgHtml('rev-delundel'); } else { $rdel = $sk->makeKnownLinkObj($revdel, wfMsgHtml('rev-delundel'), 'target=' . urlencode($this->mNewRev->mTitle->getPrefixedDbkey()) . '&oldid=' . urlencode($this->mNewRev->getId())); // Bolden oversighted content if ($this->mNewRev->isDeleted(Revision::DELETED_RESTRICTED)) { $rdel = "<strong>{$rdel}</strong>"; } } } $rdel = " <tt>(<small>{$rdel}</small>)</tt> "; } if ($this->mOldRev) { /*$oldHeader = '<div id="mw-diff-otitle1"><strong>'.$this->mOldtitle.'</strong></div>' . '<div id="mw-diff-otitle2">' . $sk->revUserTools( $this->mOldRev, true ) . "</div>" . '<div id="mw-diff-otitle3">' . $oldminor . $sk->revComment( $this->mOldRev, !$diffOnly, true ) . $ldel . "</div>" . '<div id="mw-diff-otitle4">' . $prevlink .'</div>';*/ $comment = $oldminor . $sk->revComment($this->mOldRev, !$diffOnly, true) . $ldel; //INTL: Avatar database data doesn't exist for sites other than English if ($wgLanguageCode == 'en') { $av = '<img src="' . Avatar::getAvatarURL($this->mOldRev->mUserText) . '" class="diff_avatar" />'; } //$userToolsString = $sk->revUserTools( $this->mOldRev, true ); //$userParts = explode("(", $userToolsString, 2); //$userName = $userParts[0]; //$userTools = "(" . $userParts[1]; $userName = $sk->userLink($this->mOldRev->getUser(), $this->mOldRev->getUserText()); $userTools = $sk->userToolLinks($this->mOldRev->getUser(), $this->mOldRev->getUserText()); $oldHeader = '<div id="mw-diff-otitle1"><h4>' . $prevlink . $this->mOldtitle . '</h4></div>' . '<div class="diff_details">' . $av . '<div id="mw-diff-otitle1a">' . wfMsg('diff_by') . ' ' . $userName . '</div>' . '<div id="mw-diff-otitle2">' . $this->mOldDate . "</div>" . '<div id="mw-diff-otitle2b">' . $userTools . "</div>"; if ($comment != "") { $oldHeader .= '<div id="mw-diff-otitle3" class="rccomment"><div class="">' . $comment . '</div></div>'; } $oldHeader .= '</div>'; } else { $oldHeader = wfMsg('diff_noprev'); } /*$newHeader = '<div id="mw-diff-ntitle1"><strong>'.$this->mNewtitle.'</strong></div>' . '<div id="mw-diff-ntitle2">' . $sk->revUserTools( $this->mNewRev, true ) . "</div>" . '<div id="mw-diff-ntitle2a">' . $rollback . "</div>" . '<div id="mw-diff-ntitle3">' . $newminor . $sk->revComment( $this->mNewRev, !$diffOnly, true ) . $rdel . "</div>" . '<div id="mw-diff-ntitle4">' . $nextlink . $patrol . '</div>';*/ $comment = $newminor . $sk->revComment($this->mNewRev, !$diffOnly, true) . $rdel; //INTL: Avatar database data doesn't exist for sites other than English if ($wgLanguageCode == 'en') { $av = '<img src="' . Avatar::getAvatarURL($this->mNewRev->mUserText) . '" class="diff_avatar" />'; } //$userToolsString = $sk->revUserTools( $this->mNewRev, true ); //$userParts = explode("(", $userToolsString, 2); //$userName = $userParts[0]; //$userTools = "(" . $userParts[1]; $userName = $sk->userLink($this->mNewRev->getUser(), $this->mNewRev->getUserText()); $userTools = $sk->userToolLinks($this->mNewRev->getUser(), $this->mNewRev->getUserText()); $thumbsHtml = ""; $thumbHeader = ""; $th_diff_div = ""; if ($wgUser->getId() != 0 && $wgTitle->getText() != "RCPatrol" && $wgTitle->getText() != "RCPatrolGuts" && $this->mNewRev->getTitle()->getNamespace() == NS_MAIN) { $oldId = $this->mNewRev->getPrevious(); $oldId = $oldId ? $oldId->getId() : -1; // Only show thumbs up for diffs that look back one revision if (class_exists('ThumbsUp')) { if ($oldId == -1 || $this->mOldRev && $oldId == $this->mOldRev->getId()) { $params = array('title' => $this->mNewRev->getTitle(), 'new' => $this->mNewid, 'old' => $oldId, 'vandal' => 0); $thumbsHtml = ThumbsUp::getThumbsUpButton($params, true); //$thumbHeader = 'class="th_diff_h4"'; $th_diff_div = 'class="th_diff_div"'; } } } $newHeader = '<div id="mw-diff-ntitle1" ' . $th_diff_div . '><h4 ' . $thumbHeader . '>' . $this->mNewtitle . ' ' . $nextlink . '</h4></div>' . '<div class="diff_details">' . $av . $thumbsHtml . '<div id="mw-diff-ntitle1a">' . wfMsg('diff_by') . ' ' . $userName . '</div>' . '<div id="mw-diff-ntitle2">' . $this->mNewDate . "</div>" . '<div id="mw-diff-ntitle2b">' . $userTools . "</div>" . '<div id="mw-diff-ntitle4" style="text-align:left">' . $rollback . $nextlink . $patrol . '</div>'; if ($comment != "") { $newHeader .= '<div id="mw-diff-ntitle3" class="rccomment"><div class="">' . $comment . '</div></div>'; } $newHeader .= '</div>'; $this->showDiff($oldHeader, $newHeader); if (!$diffOnly) { $this->renderNewRevision(); } wfProfileOut($fname); }
function sendNotifications() { $dbr = wfGetDB(DB_SLAVE); $lookBack = wfTimestamp() - 12 * 60 * 60; $lookBack = wfTimestamp(TS_DB, $lookBack); $sql = "SELECT DISTINCT thumb_recipient_text FROM thumbs WHERE thumb_timestamp > '{$lookBack}'"; $res = $dbr->query($sql, __METHOD__); while ($row = $dbr->fetchObject($res)) { $userText = $row->thumb_recipient_text; $u = User::newFromName($userText); if ($u) { $email = $u->getEmail(); if (empty($email) || ThumbsUp::getEmailOption($u->getId()) == 1) { continue; } $content = self::getNotificationsEmailContent($userText, $lookBack); self::sendEmail($u, $content); } } $dbr->freeResult($res); }
function getNewThumbsUp() { $this->load(); return class_exists('ThumbsNotifications') && isset($_COOKIE['wiki_shared_session']) && ThumbsUp::getThumbsTalkOption($this->getId()) == 0; }
/** * Deletes the item and all votes for it. * * @return void */ public function delete() { // Delete all registered votes for this item $sth = ThumbsUp::db()->prepare('DELETE FROM ' . ThumbsUp::config('database_table_prefix') . 'votes WHERE item_id = ?'); $sth->execute(array($this->id)); // Delete the item itself $sth = ThumbsUp::db()->prepare('DELETE FROM ' . ThumbsUp::config('database_table_prefix') . 'items WHERE id = ?'); $sth->execute(array($this->id)); }
function onDifferenceEngineNewHeader($differenceEngine, &$newHeader, $formattedRevisionTools, $nextlink, $rollback, $newminor, $diffOnly, $rdel, $unhide) { global $wgLanguageCode, $wgTitle; $user = $differenceEngine->getUser(); $newRevisionHeader = $differenceEngine->getRevisionHeader($differenceEngine->mNewRev, 'complete', 'new') . ' ' . implode(' ', $formattedRevisionTools); $newDaysAgo = wfTimeAgo($differenceEngine->mNewRev->getTimestamp()); //INTL: Avatar database data doesn't exist for sites other than English if ($wgLanguageCode == 'en') { $av = '<img src="' . Avatar::getAvatarURL($differenceEngine->mNewRev->getUserText()) . '" class="diff_avatar" />'; } $thumbsHtml = ""; $thumbHeader = ""; $th_diff_div = ""; if ($user->getId() != 0 && $wgTitle->getText() != "RCPatrol" && $wgTitle->getText() != "RCPatrolGuts" && $differenceEngine->mNewRev->getTitle()->getNamespace() == NS_MAIN) { $oldId = $differenceEngine->mNewRev->getPrevious(); $oldId = $oldId ? $oldId->getId() : -1; // Only show thumbs up for diffs that look back one revision if (class_exists('ThumbsUp')) { if ($oldId == -1 || $differenceEngine->mOldRev && $oldId == $differenceEngine->mOldRev->getId()) { $params = array('title' => $differenceEngine->mNewRev->getTitle(), 'new' => $differenceEngine->mNewid, 'old' => $oldId, 'vandal' => 0); $thumbsHtml = ThumbsUp::getThumbsUpButton($params, true); $th_diff_div = 'class="th_diff_div"'; } } } $newHeader = '<div id="mw-diff-ntitle1" ' . $th_diff_div . '><h4 ' . $thumbHeader . '>' . $newRevisionHeader . $nextlink . '</h4></div>' . '<div id="mw-diff-ntitle2">' . $av . $thumbsHtml . '<div id="mw-diff-oinfo">' . Linker::revUserTools($differenceEngine->mNewRev, !$unhide) . " {$rollback} " . '<br /><div id="mw-diff-ndaysago">' . $newDaysAgo . '</div>' . "</div>" . '<div id="mw-diff-ntitle4">' . $differenceEngine->markPatrolledLink() . '</div>' . "</div>" . '<div id="mw-diff-ntitle3" class="rccomment">' . $newminor . Linker::revComment($differenceEngine->mNewRev, !$diffOnly, !$unhide) . $rdel . '</div>'; return true; }
function writeOutput($par) { global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname; global $wgRequest, $wgSitename, $wgLanguageCode; global $wgFeedClasses, $wgFilterCallback, $wgWhitelistEdit, $wgParser; wfLoadExtensionMessages('Postcomment'); $wgOut->setRobotpolicy("noindex,nofollow"); $fname = "wfSpecialPostcomment"; //echo "topic: " . $wgRequest->getVal("topic_name") . "<BR>"; //echo "title: " . $wgRequest->getVal("title") . "<BR>"; //echo "comment: " . $wgRequest->getVal("comment_text") . "<BR>"; //echo "new_topic id " . $wgRequest->getVal("new_topic") . "<BR>"; $target = !empty($par) ? $par : $wgRequest->getVal("target"); $t = Title::newFromDBKey($target); $update = true; if (!$t || !$t->userCanEdit()) { return; } if (!$wgUser->isAllowed('edit')) { return; } if ($t == null) { $wgOut->errorPage('postcomment', 'postcomment_invalidrequest'); return; } $article = new Article($t); $user = $wgUser->getName(); $real_name = User::whoIsReal($wgUser->getID()); if ($real_name == "") { $real_name = $user; } $dateStr = $wgLang->timeanddate(wfTimestampNow()); $comment = $wgRequest->getVal("comment_text"); foreach ($wgRequest->getValues() as $key => $value) { if (strpos($key, "comment_text") === 0) { $comment = $value; break; } } $topic = $wgRequest->getVal("topic_name"); //echo "$dateStr<br/>"; // remove leading space, tends to be a problem with a lot of talk page comments as it breaks the // HTML on the page $comment = preg_replace('/\\n[ ]*/', "\n", trim($comment)); // Check to see if the user is also getting a thumbs up. If so, append the thumbs message and give a thumbs up if ($wgRequest->getVal('thumb')) { $comment .= "\n\n" . wfMsg('qn_thumbs_up'); $userName = explode(":", $wgRequest->getVal('target')); ThumbsUp::quickNoteThumb($wgRequest->getVal('revold'), $wgRequest->getVal('revnew'), $wgRequest->getVal('pageid'), $userName[1]); } $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $user, $real_name, $comment); if ($wgRequest->getVal('fromajax') == 'true') { $wgOut->setArticleBodyOnly(true); } $text = ""; $r = Revision::newFromTitle($t); if ($r) { $text = $r->getText(); } $text .= "\n\n{$formattedComment}\n\n"; $wgOut->setStatusCode(500); //echo "updating with text:<br/> $text"; //exit; $tmp = ""; if ($wgUser->isBlocked()) { $wgOut->blockedPage(); return; } if (!$wgUser->getID() && $wgWhitelistEdit) { $this->userNotLoggedInPage(); return; } if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } if ($target == "Spam-Blacklist") { $wgOut->readOnlyPage(); return; } if ($wgUser->pingLimiter()) { $wgOut->rateLimited(); return; } if ($wgFilterCallback && $wgFilterCallback($t, $text, $tmp)) { # Error messages or other handling should be performed by the filter function return; } $matches = array(); $preg = "/http:\\/\\/[^] \n'\">]*/"; $mod = str_ireplace('http://www.wikihow.com', '', $comment); preg_match_all($preg, $mod, $matches); if (sizeof($matches[0]) > 2) { $wgOut->errorPage("postcomment", "postcomment_urls_limit"); return; } if (trim(strip_tags($comment)) == "") { $wgOut->errorpage("postcomment", "postcomment_nopostingtoadd"); return; } if (!$t->userCanEdit()) { $wgOut->errorpage("postcomment", "postcomment_discussionprotected"); return; } $watch = false; if ($wgUser->getID() > 0) { $watch = $wgUser->isWatched($t); } $fc = new FancyCaptcha(); $pass_captcha = $fc->passCaptcha(); if (!$pass_captcha && $wgUser->getID() == 0) { $wgOut->addHTML("Sorry, please enter the correct word. Click <a onclick='window.location.reload(true);'>here</a> to get a new one.<br/><br/>"); return; } $article->doEdit($text, ""); if ($wgRequest->getVal('jsonresponse') == 'true') { $article->loadLastEdit(true); $this->revId = $article->getRevIdFetched(); } //XX Vu added to notify users of usertalk updates if ($t->getNamespace() == NS_USER_TALK) { AuthorEmailNotification::notifyUserTalk($t->getArticleID(), $wgUser->getID(), $comment); } $wgOut->setStatusCode(200); if ($wgRequest->getVal('fromajax') == 'true') { $wgOut->redirect(''); $wgTitle = $t; $formattedComment = $wgParser->preSaveTransform($formattedComment, $t, $wgUser, new ParserOptions()); $wgOut->addHTML($wgOut->parse("\n" . $formattedComment)); return; } }
//]]> </script> <?php } } // Make sure we have add_action() if (!function_exists('add_action')) { $wp_root = '../../..'; if (file_exists($wp_root . '/wp-load.php')) { require_once $wp_root . '/wp-load.php'; } else { require_once $wp_root . '/wp-config.php'; } } // Our global object variable for use in the rest of the functions. $thumbs = new ThumbsUp(); $post_id = intval($_POST['post_id']); $vote = intval($_POST['vote']); $ip = $_POST['ip']; $user = $_POST['user']; if ($post_id && $vote && $ip) { $thumbs->processVote($post_id, $vote, $ip, $user); } global $thumbs; function thumbs_install() { //global $thumbs; $thumbs; $thumbs->installThumbsUp(); } function thumbs_init()
static function getThumbsUpButton($result, &$rcTest) { $button = ""; if (class_exists('RCTest') && RCTest::isEnabled()) { if ($rcTest && $rcTest->isTestTime()) { $result = $rcTest->getResultParams(); } } if (class_exists('ThumbsUp')) { $button = ThumbsUp::getThumbsUpButton($result); } return $button; }
<?php /** * ThumbsUp * * @author Geert De Deckere <*****@*****.**> * @link http://geertdedeckere.be/shop/thumbsup/ * @copyright Copyright 2009-2010 */ sleep(1); // The path pointing to the thumbsup directory. // We chop off the "admin" part here. define('THUMBSUP_DOCROOT', substr(realpath(dirname(__FILE__)), 0, -5)); // Load the required ThumbsUp classes require THUMBSUP_DOCROOT . 'classes/thumbsup.php'; require THUMBSUP_DOCROOT . 'classes/thumbsup_cookie.php'; require THUMBSUP_DOCROOT . 'classes/thumbsup_admin.php'; require THUMBSUP_DOCROOT . 'classes/thumbsup_item.php'; require THUMBSUP_DOCROOT . 'classes/thumbsup_template.php'; // Debug mode is enabled if (ThumbsUp::config('debug')) { // Enable all error reporting ThumbsUp::debug_mode(); } // Enable support for json functions ThumbsUp::json_support(); // Power to the admin class! new ThumbsUp_Admin(empty($_GET['action']) ? NULL : (string) $_GET['action']);
<?php /** * ThumbsUp * * @author Geert De Deckere <*****@*****.**> * @link http://geertdedeckere.be/shop/thumbsup/ * @copyright Copyright 2009-2010 */ // The path pointing to this thumbsup directory define('THUMBSUP_DOCROOT', realpath(dirname(__FILE__)) . '/'); // Load the required ThumbsUp classes require THUMBSUP_DOCROOT . 'classes/thumbsup.php'; require THUMBSUP_DOCROOT . 'classes/thumbsup_cookie.php'; require THUMBSUP_DOCROOT . 'classes/thumbsup_item.php'; require THUMBSUP_DOCROOT . 'classes/thumbsup_items.php'; require THUMBSUP_DOCROOT . 'classes/thumbsup_template.php'; // Debug mode is enabled if (ThumbsUp::config('debug')) { // Enable all error reporting ThumbsUp::debug_mode(); // Show an error if the headers are already sent if (headers_sent()) { trigger_error('thumbsup/init.php must be included before any output has been sent. Include it at the very top of your page.'); } } // Enable support for json functions ThumbsUp::json_support(); // Register new votes if any ThumbsUp::catch_vote();
function getNextToPatrolHTML() { global $wgOut; if (!$this->mResult) { // nothing to patrol return null; } // construct the HTML to reply // load the page $t = Title::newFromID($this->mResult->qc_page); if (!$t) { $this->deleteBad($this->mResult->qc_page); return "<!--{$this->mResult->qc_page}-->error creating title, oops, please <a href='#' onclick='window.location.reload()'>refresh</a>"; } // get current revsion $r = Revision::newFromId($this->mResult->qc_rev_id); if (!$r) { return "Error creating revision"; } // grab the intro image $text = $r->getText(); $intro = Article::getSection($text, 0); //ignore if we have a {{nointroimg}} template in there $a = new Article($t); $templates = $a->getUsedTemplates(); if (in_array('Template:Nointroimg', $templates)) { $this->deleteBad($this->mResult->qc_page); return "<!--{$this->mResult->qc_page}--><p></p><p>Intro images have been disabled for this article. Please <a href='#' onclick='window.location.reload()'>refresh</a> for the next article.</p>"; } $html = ""; $changedby = self::getChangedBy("Image added by: "); $pic = self::getPicture($intro); if ($pic) { //make sure it's not too big if ($pic->width > 600) { $pic = $pic->getThumbnail(600); } if ($r->getPrevious()) { $old = $r->getPrevious()->getID(); } else { $old = -1; } $thumbresult['new'] = $r->getID(); $thumbresult['old'] = $old; $thumbresult['title'] = $t; $pic_width = (632 - $pic->width) / 2 + $pic->width - 32; //31px = thumbbutton width $thumbs = ThumbsUp::getThumbsUpButton($thumbresult); $style = " style='margin-left:" . $pic_width . "px;'"; $thumbs = "<div class='qc_changedby_inset'{$style}>{$thumbs}</div>"; $html .= "<div id='qc_bigpic'>\n\t\t\t\t\t\t" . $thumbs . "\n\t\t\t\t\t\t<img class='qc_bigpic_img' src='" . $pic->getURL() . "' width='" . $pic->width . "' height='" . $pic->height . "' />\n\t\t\t\t\t\t</div>"; } else { $html .= "<br />" . wfMsg('qc_nothing_found'); } $html = "<div id='quickeditlink'></div>"; $html .= "<div id='qc_box'>" . $changedby . $html . "</div>"; $popts = $wgOut->parserOptions(); $popts->setTidy(true); $html .= WikihowArticleHTML::processArticleHTML($wgOut->parse($text, $t, $popts), array('ns' => $t->getNamespace())); $html .= "<input type='hidden' name='qc_id' value='{$this->mResult->qc_id}'/>"; $html .= "<div id='numqcusers'>{$this->mUsers}</div>"; return $html; }
function getThumbsUpButton(&$result, $diffPage = false) { global $wgUser; wfLoadExtensionMessages('RCPatrol'); $link = ""; $r = Revision::newFromId($result['new']); $t = $result['title']; $diffClass = $diffPage ? ' th_diff' : ''; if (class_exists('ThumbsUp') && wfMsg('thumbs_feature') == 'on') { // Don't show a thumbs up if the user has already given a thumb to the most recent revision if (ThumbsUp::isThumbedByCurrentUser($result['new'])) { $link = "<input type='button' class='button thumbbutton alreadyThumbed {$diffClass}'/>"; } else { if ($r && $result['vandal'] != 1 && $wgUser->getID() != $r->getUser() && $t->getNamespace() == NS_MAIN) { /* Show a thumbs up button for: - NS_MAIN titles only - non-anon revision authors who have accounts - thumb givers that are logged in - revisions that are not already thumbed by the current giver/user - revisions that aren't authored by the current giver/user - revisions that don't appear to be vandalism */ $link = "<input type='button' title='" . wfMsg('rcpatrol_thumb_title') . "' class='button secondary thumbbutton {$diffClass}'/>"; $link .= "<script type='text/javascript' src='" . wfGetPad('/extensions/min/f/extensions/wikihow/thumbsup/thumbsup.js?') . WH_SITEREV . "'></script>"; $link .= "<div id='thumbUp'>/Special:ThumbsUp?revold=" . $result['old'] . "&revnew=" . $result['new'] . "&pageid=" . $t->getArticleID() . "</div>"; $langKeys = array('rcpatrol_thumb_msg_pending', 'rcpatrol_thumb_msg_complete'); $link .= Wikihow_i18n::genJSMsgs($langKeys); } else { // Display a disabled thumb up button. This isn't an article that can be thumbed up $link = "<input type='button' class='button disabledThumb {$diffClass}'/>"; } } } return $link; }
/** * Looks at the POST data to catch a possible new vote. If one, the vote is * completely validated first before being registered. * * @return boolean TRUE if a new vote was cast; FALSE otherwise */ public static function catch_vote() { // Immediately get out of here if no valid vote was cast. // All required POST keys must be present. if (!isset($_POST['thumbsup_id']) or !isset($_POST['thumbsup_vote']) or !isset($_POST['thumbsup_format'])) { return FALSE; } // Has somebody been messing with the form? // Well, we won't let them mess with us! if (!preg_match('/^[0-9]++$/D', (string) $_POST['thumbsup_id']) or !is_string($format = $_POST['thumbsup_format'])) { return FALSE; } // Clean form input $id = (int) $_POST['thumbsup_id']; $vote = (int) $_POST['thumbsup_vote']; // Attempt to load the relevant ThumbsUp item. // If the item doesn't exist, the id is invalid. if (!($item = ThumbsUp_Item::load($id))) { $error = 'invalid_id'; } elseif ($item->closed) { $error = 'closed'; } elseif ($item->user_voted) { $error = 'already_voted'; } elseif (ThumbsUp::config('user_login_required') and !self::get_user_id()) { $error = 'login_required'; } // All checks passed, yay! if (empty($error)) { // Update the vote count in the items table, and recalculate the vote results $item->cast_vote($vote); } // Send an ajax response if (self::is_ajax()) { // Send the item back in JSON format header('Content-Type: application/json; charset=utf-8'); if (!empty($error)) { // Send back the error echo json_encode(array('error' => $error)); } else { // Format the result using the same format the item was created with $item->format($format); // Send back the updated item. // Note: all the public properties of $item will be included. echo json_encode(array('item' => $item)); } } // A new vote has been cast successfully return empty($error); }
function writeOutput($par) { global $wgLang, $wgMemc, $wgDBname, $wgUser; global $wgSitename, $wgLanguageCode; global $wgFeedClasses, $wgFilterCallback, $wgWhitelistEdit, $wgParser; $this->getOutput()->setRobotpolicy("noindex,nofollow"); $target = !empty($par) ? $par : $this->getRequest()->getVal("target"); $t = Title::newFromDBKey($target); $update = true; if (!$t || !$t->userCan('edit')) { return; } if (!$this->getUser()->isAllowed('edit')) { return; } $article = new Article($t); $user = $this->getUser()->getName(); $real_name = User::whoIsReal($this->getUser()->getID()); if ($real_name == "") { $real_name = $user; } $dateStr = $wgLang->timeanddate(wfTimestampNow()); $comment = $this->getRequest()->getVal("comment_text"); foreach ($this->getRequest()->getValues() as $key => $value) { if (strpos($key, "comment_text") === 0) { $comment = $value; break; } } $topic = $this->getRequest()->getVal("topic_name"); //echo "$dateStr<br/>"; // remove leading space, tends to be a problem with a lot of talk page comments as it breaks the // HTML on the page $comment = preg_replace('/\\n[ ]*/', "\n", trim($comment)); // Check to see if the user is also getting a thumbs up. If so, append the thumbs message and give a thumbs up if ($this->getRequest()->getVal('thumb')) { $comment .= "\n\n" . wfMsg('qn_thumbs_up'); $userName = explode(":", $this->getRequest()->getVal('target')); ThumbsUp::quickNoteThumb($this->getRequest()->getVal('revold'), $this->getRequest()->getVal('revnew'), $this->getRequest()->getVal('pageid'), $userName[1]); } $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $user, $real_name, $comment); if ($this->getRequest()->getVal('fromajax') == 'true') { $this->getOutput()->setArticleBodyOnly(true); } $text = ""; $r = Revision::newFromTitle($t); if ($r) { $text = $r->getText(); } $text .= "\n\n{$formattedComment}\n\n"; $this->getOutput()->setStatusCode(409); //echo "updating with text:<br/> $text"; //exit; $tmp = ""; if ($this->getUser()->isBlocked()) { $this->getOutput()->blockedPage(); return; } if (!$this->getUser()->getID() && $wgWhitelistEdit) { $this->userNotLoggedInPage(); return; } if (wfReadOnly()) { $this->getOutput()->readOnlyPage(); return; } if ($target == "Spam-Blacklist") { $this->getOutput()->readOnlyPage(); return; } if ($this->getUser()->pingLimiter()) { $this->getOutput()->rateLimited(); return; } $editPage = new EditPage($article); $contentModel = $t->getContentModel(); $handler = ContentHandler::getForModelID($contentModel); $contentFormat = $handler->getDefaultFormat(); $content = ContentHandler::makeContent($text, $t, $contentModel, $contentFormat); $status = Status::newGood(); if (!wfRunHooks('EditFilterMergedContent', array($this->getContext(), $content, &$status, '', $wgUser, false))) { return; } if (!$status->isGood()) { $errors = $status->getErrorsArray(true); foreach ($errors as $error) { if (is_array($error)) { $error = count($error) ? $error[0] : ''; } if (preg_match('@^spamprotection@', $error)) { $message = 'Error: found spam link'; $this->getOutput()->addHTML($message); return; } } $message = 'EditFilterMergedContent returned an error -- cannot post comment'; return; } $matches = array(); $preg = "/http:\\/\\/[^] \n'\">]*/"; $mod = str_ireplace('http://www.wikihow.com', '', $comment); preg_match_all($preg, $mod, $matches); if (sizeof($matches[0]) > 2) { $this->getOutput()->showErrorPage("postcomment", "postcomment_urls_limit"); return; } if (trim(strip_tags($comment)) == "") { $this->getOutput()->showErrorPage("postcomment", "postcomment_nopostingtoadd"); return; } if (!$t->userCan('edit')) { $this->getOutput()->showErrorPage("postcomment", "postcomment_discussionprotected"); return; } $watch = false; if ($this->getUser()->getID() > 0) { $watch = $this->getUser()->isWatched($t); } $fc = new FancyCaptcha(); $pass_captcha = $fc->passCaptcha(); if (!$pass_captcha && $this->getUser()->getID() == 0) { $this->getOutput()->addHTML("Sorry, please enter the correct word. Click <a onclick='window.location.reload(true);'>here</a> to get a new one.<br/><br/>"); return; } $article->doEdit($text, ""); if ($this->getRequest()->getVal('jsonresponse') == 'true') { $this->revId = $article->getRevIdFetched(); } // Notify users of usertalk updates if ($t->getNamespace() == NS_USER_TALK) { AuthorEmailNotification::notifyUserTalk($t->getArticleID(), $this->getUser()->getID(), $comment); } $this->getOutput()->setStatusCode(200); if ($this->getRequest()->getVal('fromajax') == 'true') { $this->getOutput()->redirect(''); $this->getContext()->setTitle($t); $formattedComment = $wgParser->preSaveTransform($formattedComment, $t, $this->getUser(), new ParserOptions()); $this->getOutput()->addHTML($this->getOutput()->parse("\n" . $formattedComment)); return; } }
<link rel="stylesheet" href="<?php echo ThumbsUp::config('url') . 'admin/css/admin.css'; ?> " /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script> $(document).ready(function() { // Total items found count var $total_items = $('#total_items'); // Spinner image var spinner = '<img class="spinner" alt="" src="<?php echo ThumbsUp::config('url') . 'images/spinner_small.gif'; ?> " />'; // Auto-submit pagination forms $('#page, #items_per_page').change(function() { $(this).closest('form').submit(); }); // Delete an item $('a.delete').click(function() { var $this = $(this), $row = $this.closest('tr'); // Show a spinner $this.html(spinner);
* * @author Geert De Deckere <*****@*****.**> * @link http://geertdedeckere.be/shop/thumbsup/ * @copyright Copyright 2009-2010 */ ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>ThumbsUp Admin</title> <link rel="stylesheet" href="<?php echo ThumbsUp::config('url') . 'admin/css/admin.css'; ?> " /> </head> <body class="login"> <noscript> <p class="center"><strong>The ThumbsUp admin area requires JavaScript to be enabled.</strong></p> </noscript> <form id="login" method="post"> <h1>ThumbsUp Admin</h1> <?php
/** * Helper function to create the URL for an admin page. * * @param mixed string or array containing query string contents * @param boolean automatically add existing GET parameters again * @return string complete url */ public static function url($params = NULL, $preserve_get = TRUE) { $url = ThumbsUp::config('url') . 'admin/'; // Convert to params to an array if (!is_array($params)) { parse_str((string) $params, $params); } // Add existing GET params to the query string if ($preserve_get) { $params += $_GET; } // Only prepend "?" if the query string is not empty $query = rtrim('?' . http_build_query($params, '', '&'), '?'); return $url . $query; }
/** * Generates and executes the query. * * @return array array of items */ public function get() { // Start building the query $sql = 'SELECT id, name, closed, date, votes_up, votes_down, '; $sql .= 'votes_up - votes_down AS votes_balance, '; $sql .= 'votes_up + votes_down AS votes_total, '; $sql .= 'votes_up / (votes_up + votes_down) * 100 AS votes_pct_up, '; $sql .= 'votes_down / (votes_up + votes_down) * 100 AS votes_pct_down '; $sql .= 'FROM ' . ThumbsUp::config('database_table_prefix') . 'items '; // Select only either open or closed items if ($this->closed !== NULL) { $where[] = 'closed = ' . (int) $this->closed; } // Select only either open or closed items if ($this->name !== NULL) { // Note: substr() is used to chop off the wrapping quotes $where[] = 'name LIKE "%' . substr(ThumbsUp::db()->quote($this->name), 1, -1) . '%"'; } // Append all query conditions if any if (!empty($where)) { $sql .= ' WHERE ' . implode(' AND ', $where); } // We need to order the results if ($this->orderby) { $sql .= ' ORDER BY ' . $this->orderby; } else { // Default order $sql .= ' ORDER BY name '; } // A limit has been set if ($this->limit) { $sql .= ' LIMIT ' . (int) $this->limit; } // Wrap this in an try/catch block just in case something goes wrong try { // Execute the query $sth = ThumbsUp::db()->prepare($sql); $sth->execute(array($this->name)); } catch (PDOException $e) { // Rethrow the exception in debug mode if (ThumbsUp::config('debug')) { throw $e; } // Otherwise, fail silently and just return an empty item array return array(); } // Initialize the items array that will be returned $items = array(); // Fetch all results while ($row = $sth->fetch(PDO::FETCH_OBJ)) { // Return an item_id => item_name array $items[] = array('id' => (int) $row->id, 'name' => $row->name, 'closed' => (bool) $row->closed, 'date' => (int) $row->date, 'votes_up' => (int) $row->votes_up, 'votes_down' => (int) $row->votes_down, 'votes_pct_up' => (double) $row->votes_pct_up, 'votes_pct_down' => (double) $row->votes_pct_down, 'votes_balance' => (int) $row->votes_balance, 'votes_total' => (int) $row->votes_total); } return $items; }
/** * Deletes the cookie completely. * * @return boolean was setcookie() successful or not? */ public static function delete() { // Delete cookie contents self::$cookie = ''; unset($_COOKIE[ThumbsUp::config('cookie_name')]); // If any output has been sent, setcookie() will fail. // If we're not in debug mode, we'll fail silently. if (headers_sent() and !ThumbsUp::config('debug')) { return FALSE; } // Setting a cookie with a value of FALSE will try to delete it return setcookie(ThumbsUp::config('cookie_name'), FALSE, time() - 86400, ThumbsUp::config('cookie_path'), ThumbsUp::config('cookie_domain')); }
static function getThumbsUpButton($result, &$rcTest) { $button = ""; if (class_exists('RCTest') && RCTest::isEnabled()) { if ($rcTest && $rcTest->isTestTime()) { $result = $rcTest->getResultParams(); } } if (class_exists('ThumbsUp')) { //-1 is a secret code to our thumbs up function $result['old'] = $result['old'] != 0 ? $result['old'] : -1; $button = ThumbsUp::getThumbsUpButton($result); } return $button; }