public static function revertTips($user, $cutoff, $cutoff2, $unpatrol_limit) { global $wgLang, $wgOut; //max number of possible unpatrols $limit = array(); if (!empty($unpatrol_limit)) { $limit = array('LIMIT' => $unpatrol_limit); } $dbw = wfGetDB(DB_MASTER); $options = array('tw_user' => $user->getID(), "tw_timestamp > '{$cutoff}'"); if ($cutoff2) { $options[] = "tw_timestamp < '{$cutoff2}'"; } $res = $dbw->select('tipsandwarnings_log', array('tw_id', 'tw_rev_this'), $options, __METHOD__, $limit); $tipIds = array(); while ($row = $dbw->fetchObject($res)) { $tipIds[$row->tw_id] = $row->tw_rev_this; } wfRunHooks('UnpatrolTips', array(&$tipIds)); $count = sizeof($tipIds); foreach ($tipIds as $tipId => $revId) { // undo the tip $success = TipsPatrol::undoTip($tipId); if ($revId) { $revision = Revision::newFromId($revId); $title = $revision->getTitle(); if (!$success) { $wgOut->addHTML("failed to undo tip: {$tipId} with revId: {$revId} with Title: {$title}<br>"); continue; } $wgOut->addHTML("undid approved tip: {$tipId} with revId: {$revId} with Title: {$title}<br>"); } else { $wgOut->addHTML("undid rejected tip: {$tipId} <br>"); } } //log the change $logTitle = Title::newFromText('Special:UnpatrolTips'); $logPage = new LogPage('undotips', false); $logData = array(); $logMessage = "[[User:"******"]]: {$count} tip patrols undone"; $logPage->addEntry('unpatrol', $logTitle, $logMessage, $logData); // set the original logs to be deleted unset($options); $options = array('log_user' => $user->getID(), 'log_type' => 'newtips', "log_timestamp > '{$cutoff}'", 'log_deleted' => 0); if ($cutoff2) { $options[] = "tw_timestamp < '{$cutoff2}'"; } $res = $dbw->update('logging', array('log_deleted' => 1), $options, __METHOD__, $limit); return $count; }
function printData() { global $wgOut, $wgRequest; $coachEnabled = TipsPatrol::isTPCoachEnabled(); $vars['disableDisplay'] = $coachEnabled ? "block" : "none"; $vars['enableDisplay'] = $coachEnabled ? "none" : "block"; $vars['scores'] = $this->getScores(); $vars['tests'] = $this->getTests(); $vars['days'] = $wgRequest->getVal("days", 7); $vars['css'] = HtmlSnips::makeUrlTags('css', array('tpcoachadmin.css'), 'extensions/wikihow/tipsandwarnings', true); $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('tpcoachadmin.js'), 'extensions/wikihow/tipsandwarnings', true)); $html = EasyTemplate::html('TPCoachAdmin', $vars); $wgOut->addHTML($html); }
function revertTips($user, $cutoff, $cutoff2, $revert, $print = true) { $dbw = wfGetDB(DB_MASTER); $options = array('tw_user' => $user->getID(), "tw_timestamp > " . $dbw->addQuotes($cutoff)); if ($cutoff2) { $options[] = "tw_timestamp < '{$cutoff2}'"; } $res = $dbw->select('tipsandwarnings_log', array('tw_id', 'tw_qc_id'), $options, __METHOD__); $tipIds = array(); foreach ($res as $row) { if ($row->tw_qc_id) { $tipIds[$row->tw_id] = $row->tw_qc_id; } } wfRunHooks('UnpatrolTips', array(&$tipIds)); $count = sizeof($tipIds); if ($print) { $this->getOutput()->addHTML("<br/>"); foreach ($tipIds as $tipId => $qcId) { $this->getOutput()->addHTML("<p>tip with tip_id {$tipId} and qc_id {$qcId} <br/></p>"); } } if ($revert) { $count = 0; foreach ($tipIds as $tipId => $qcId) { $success = TipsPatrol::undoTip($tipId, $qcId, $user->getId()); if ($success) { $this->getOutput()->addHTML("undid tip {$tipId} <br/>"); $count++; } else { $this->getOutput()->addHTML("could not undo tip {$tipId} <br/>"); } } //log the change if ($count > 0) { $logTitle = Title::newFromText('Special:UnpatrolTips'); $logPage = new LogPage('undotips', false); $logData = array(); $logMessage = "[[User:"******"]]: {$count} tip patrols undone"; $logPage->addEntry('unpatrol', $logTitle, $logMessage, $logData); } } return $count; }
static function undoTip($tipId, $qcId, $userId) { if (!$tipId || !$qcId) { return false; } // tip is is QC, remove it from there QCRuleTip::deleteIfNotPatrolled($qcId, $userId); // we just need to get the tip page and the tip from here $tipData = TipsPatrol::getTipLogRow($tipId); // tip data to add back to tipsandwarnings table $data = array("tw_page" => $tipData['tw_page'], "tw_tip" => $tipData['tw_tip'], "tw_user" => $userId, "tw_timestamp" => wfTimestampNow()); // now delete the tips with this id from the log and put it back into the main queue $dbw = wfGetDB(DB_MASTER); $dbw->insert('tipsandwarnings', $data, __METHOD__, array('IGNORE')); $dbw->delete('tipsandwarnings_log', array('tw_id' => $tipId)); return true; }
function applyChange($qcid) { //grab tip data from tip id $dbr = wfGetDB(DB_SLAVE); $tipid = $dbr->selectField('qc', array('qc_extra'), array('qc_id' => $qcid)); list($tip_user, $the_tip, $tip_page) = self::getTipData($tipid); //use TipsPatrol's functions $res = TipsPatrol::keepTip($tipid, $tip_page, $the_tip); if ($res) { TipsPatrol::deleteTip($tipid, $tip_page, $the_tip, true, true); } return $res; }
function getNextToPatrolHTML() { global $wgOut; if (!$this->mResult) { // nothing to patrol return null; } // construct the HTML to reply // load the page $t = $this->mTitle; // 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::newFromTitle($t); if (!$r) { return "Error creating revision"; } $html = ""; //grab all that good tip stuff $tipData = TipsPatrol::getTipData($this->mResult->qc_extra, $this->mResult->qc_user); $the_tip = $tipData['tw_tip']; $tip_page = $tipData['tw_page']; $approvedby = self::getChangedBy("Tip approved by: ", "qc_approvedby", $tip_user); $html = '<h3>New Tip</h3><br />' . '<div class="wh_block"><ul><li>' . $the_tip . '</li></ul></div>'; $html = "<div id='qc_box'>" . $addedby . $approvedby . $html . "</div>"; $wgOut->clearHTML(); $html .= "<div id='quickeditlink'></div>"; $popts = $wgOut->parserOptions(); $popts->setTidy(true); $magic = WikihowArticleHTML::grabTheMagic($r->getText()); $html .= WikihowArticleHTML::processArticleHTML($wgOut->parse($r->getText(), $t, $popts), array('no-ads' => 1, 'ns' => $t->getNamespace(), 'magic-word' => $magic)); $html .= "<input type='hidden' name='qc_id' value='{$this->mResult->qc_id}'/>"; $html .= "<div id='numqcusers'>{$this->mUsers}</div>"; return $html; }
function undoTip($tipId) { $tipData = TipsPatrol::getTipLogRow($tipId); $action = $tipData['tw_action']; if ($action == TipsPatrol::TIP_ACTION_KEEP) { // undo the revision $success = TipsPatrol::revertTipOnArticle($tipData['tw_page'], $tipData['tw_rev_this']); if (!$success) { return false; } } // tip data to add back to tipsandwarnings table $data = array("tw_page" => $tipData['tw_page'], "tw_tip" => $tipData['tw_tip'], "tw_user" => 0, "tw_timestamp" => wfTimestampNow()); $dbw = wfGetDB(DB_MASTER); if ($action != TipsPatrol::TIP_ACTION_SKIP) { $dbw->insert('tipsandwarnings', $data, __METHOD__, array('IGNORE')); } $dbw->delete('tipsandwarnings_log', array('tw_id' => $tipId)); return true; }