Exemple #1
0
 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 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;
 }