/** * Grab the last good patrol * - return true if the last edit on the article was patrolled */ public static function patrolledGood($title) { // start with basic check to make sure we're dealing // with a real article if (!$title) { return false; } // get the last revision $a = new Article($title); $a->loadLastEdit(); $last_rev = $a->mLastRevision; // get the last good revision $goodRev = self::newFromTitle($title); $last_good_rev = $goodRev->latestGood(); return $last_rev->mId == $last_good_rev; }
function rollbackChange($qcid) { // try to rollback the last edit if we can $dbr = wfGetDB(DB_SLAVE); $result = $dbr->selectRow('qc', '*', array('qc_id' => $qcid)); $t = self::getTitleFromQCID($qcid); $a = new Article($t); $a->loadLastEdit(); $last_rev = $a->mLastRevision; // is this it them most recent revision? if so, we can roll it back wfDebug("GOT " . print_r($a, true) . " {$last_rev->mId} vs {$result->qc_rev_id}\n"); if ($last_rev->mId == $result->qc_rev_id) { $a->commitRollback($last_rev->mUserText, wfMsg('qc_editsummary_rollback', $last_rev->mUserText), false, $result); } 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; } }
function execute($par) { global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname; global $wgRequest, $wgSitename, $wgLanguageCode, $IP; global $wgScript, $wgFilterCallback, $wgScriptPath; $this->setHeaders(); require_once "{$IP}/extensions/wikihow/EditPageWrapper.php"; require_once "{$IP}/includes/EditPage.php"; $target = isset($par) ? $par : $wgRequest->getVal('target'); if (!$target) { $wgOut->addHTML("No target specified. In order to thank a group of authors, a page must be provided."); return; } $title = Title::newFromDBKey($target); $me = Title::makeTitle(NS_SPECIAL, "ThankAuthors"); if (!$wgRequest->getVal('token')) { $sk = $wgUser->getSkin(); $talk_page = $title->getTalkPage(); $token = $this->getToken1(); $thanks_msg = wfMsg('thank-you-kudos', $title->getFullURL(), wfMsg('howto', $title->getText())); // add the form HTML $wgOut->addHTML(<<<EOHTML \t\t\t\t<script type='text/javascript'> \t\t\t\t\tfunction submitThanks () { \t\t\t\t\t\tvar message = \$('#details').val(); \t\t\t\t\t\tif(message == "") { \t\t\t\t\t\t\talert("Please enter a message."); \t\t\t\t\t\t\treturn false; \t\t\t\t\t\t} \t\t\t\t\t\tvar url = '{$me->getFullURL()}?token=' + \$('#token')[0].value + '&target=' + \$('#target')[0].value + '&details=' + \$('#details')[0].value; \t\t\t\t\t\tvar form = \$('#thanks_form'); \t\t\t\t\t\tform.html(\$('#thanks_response').html()); \t\t\t\t\t\t\$.get(url); \t\t\t\t\t\treturn true; \t\t\t\t\t} \t\t\t\t</script> \t\t\t\t<div id="thanks_response" style="display:none;">{$thanks_msg}</div> \t\t\t\t<div id="thanks_form"><div class="section_text"> EOHTML ); $wgOut->addWikiText(wfMsg('enjoyed-reading-article', $title->getFullText(), $talk_page->getFullText())); $wgOut->addHTML("<input id=\"target\" type=\"hidden\" name=\"target\" value=\"{$target}\"/>\n\t\t\t\t<input id=\"token\" type=\"hidden\" name=\"{$token}\" value=\"{$token}\"/>\n\t\t\t\t"); $wgOut->addHTML("<br />\n\t\t\t\t<textarea style='width:98%;' id=\"details\" rows=\"5\" cols=\"100\" name=\"details\"></textarea><br/>\n\t\t\t\t<br /><button onclick='submitThanks();' class='button primary'>" . wfMsg('submit') . "</button>\n\t\t\t\t</div></div>"); } else { // this is a post, accept the POST data and create the // Request article wfLoadExtensionMessages('Postcomment'); $wgOut->setArticleBodyOnly(true); $article = new Article($title); // stupid bug that doesn't load the last edit unless you ask it to $article->loadLastEdit(); $contributors = $article->getContributors(0, 0, true); $user = $wgUser->getName(); $real_name = User::whoIsReal($wgUser->getID()); if ($real_name == "") { $real_name = $user; } $dateStr = $wgLang->timeanddate(wfTimestampNow()); $comment = $wgRequest->getVal("details"); $text = $title->getFullText(); wfDebug("STA: got text..."); // filter out links $preg = "/[^\\s]*\\.[a-z][a-z][a-z]?[a-z]?/i"; $matches = array(); if (preg_match($preg, $comment, $matches) > 0) { $wgOut->addHTML(wfMsg('no_urls_in_kudos', $matches[0])); return; } $comment = strip_tags($comment); $formattedComment = wfMsg('postcomment_formatted_thanks', $dateStr, $user, $real_name, $comment, $text); wfDebug("STA: comment {$formattedComment}\n"); wfDebug("STA: Checking blocks..."); $tmp = ""; if ($wgUser->isBlocked()) { $this->blockedIPpage(); return; } if (!$wgUser->getID() && $wgWhitelistEdit) { $this->userNotLoggedInPage(); return; } if ($target == "Spam-Blacklist") { $wgOut->readOnlyPage(); return; } wfDebug("STA: checking read only\n"); if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } wfDebug("STA: checking rate limiter\n"); if ($wgUser->pingLimiter('userkudos')) { $wgOut->rateLimited(); return; } wfDebug("STA: checking blacklist\n"); if ($wgFilterCallback && $wgFilterCallback($title, $comment, "")) { // Error messages or other handling should be // performed by the filter function return; } wfDebug("STA: checking tokens\n"); $usertoken = $wgRequest->getVal('token'); $token1 = $this->getToken1(); $token2 = $this->getToken2(); if ($usertoken != $token1 && $usertoken != $token2) { wfDebug("STA: User kudos token doesn't match user: {$usertoken} token1: {$token1} token2: {$token2}"); return; } wfDebug("STA: going through contributors\n"); foreach ($contributors as $c) { $id = $c[0]; $u = $c[1]; wfDebug("STA: going through contributors {$u} {$id}\n"); if ($id == "0") { continue; } // forget the anon users. $t = Title::newFromText("User_kudos:" . $u); $a = new Article($t); $update = $t->getArticleID() > 0; $text = ""; if ($update) { $text = $a->getContent(true); $text .= "\n\n" . $formattedComment; if ($wgFilterCallback && $wgFilterCallback($t, $text, $text)) { // Error messages or other handling should be // performed by the filter function return; } } if ($update) { $a->updateArticle($text, "", true, false, false, '', false); } else { $a->insertNewArticle($text, "", true, false, false, false, false); } } wfDebug("STA: done\n"); $wgOut->addHTML("Done."); $wgOut->redirect(''); } }