/**
  * @param FlaggedRevision $frev
  * Removes flagged revision data for this page/id set
  * @return bool
  */
 private function unapproveRevision(FlaggedRevision $frev)
 {
     wfProfileIn(__METHOD__);
     # Get current stable version ID (for logging)
     $oldSv = FlaggedRevision::newFromStable($this->page, FR_MASTER);
     # Delete from flaggedrevs table
     $frev->delete();
     # Update the article review log
     $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
     FlaggedRevsLog::updateReviewLog($this->page, $this->dims, $this->oldFlags, $this->comment, $this->oldid, $oldSvId, false);
     # Get the new stable version as of now
     $sv = FlaggedRevision::determineStable($this->page, FR_MASTER);
     # Update recent changes
     self::updateRecentChanges($frev->getRevision(), 'unpatrol', $sv);
     # Update page and tracking tables and clear cache
     $changed = FlaggedRevs::stableVersionUpdates($this->page, $sv, $oldSv);
     if ($changed) {
         FlaggedRevs::HTMLCacheUpdates($this->page);
         // purge pages that use this page
     }
     # Caller may want to get the change time
     $this->newLastChangeTime = '';
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * Get the stable version of a file
  * @param Title $title
  * @return array (MW timestamp/'0', sha1/'')
  */
 public function getStableFileVersion(Title $title)
 {
     $dbKey = $title->getDBkey();
     $time = '0';
     // missing
     $sha1 = false;
     # All NS_FILE, no need to check namespace
     if (isset($this->stableVersions['files'][$dbKey])) {
         $time = $this->stableVersions['files'][$dbKey]['time'];
         $sha1 = $this->stableVersions['files'][$dbKey]['sha1'];
         return array($time, $sha1);
     }
     $srev = FlaggedRevision::newFromStable($title);
     if ($srev && $srev->getFileTimestamp()) {
         $time = $srev->getFileTimestamp();
         $sha1 = $srev->getFileSha1();
     }
     $this->stableVersions['files'][$dbKey] = array();
     $this->stableVersions['files'][$dbKey]['time'] = $time;
     $this->stableVersions['files'][$dbKey]['sha1'] = $sha1;
     return array($time, $sha1);
 }
 /**
  * Automatically review an revision and add a log entry in the review log.
  *
  * This is called during edit operations after the new revision is added
  * and the page tables updated, but before LinksUpdate is called.
  *
  * $auto is here for revisions checked off to be reviewed. Auto-review
  * triggers on edit, but we don't want those to count as just automatic.
  * This also makes it so the user's name shows up in the page history.
  *
  * If $flags is given, then they will be the review tags. If not, the one
  * from the stable version will be used or minimal tags if that's not possible.
  * If no appropriate tags can be found, then the review will abort.
  */
 public static function autoReviewEdit(WikiPage $article, $user, Revision $rev, array $flags = null, $auto = true)
 {
     wfProfileIn(__METHOD__);
     $title = $article->getTitle();
     // convenience
     # Get current stable version ID (for logging)
     $oldSv = FlaggedRevision::newFromStable($title, FR_MASTER);
     $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
     # Set the auto-review tags from the prior stable version.
     # Normally, this should already be done and given here...
     if (!is_array($flags)) {
         if ($oldSv) {
             # Use the last stable version if $flags not given
             if ($user->isAllowed('bot')) {
                 $flags = $oldSv->getTags();
                 // no change for bot edits
             } else {
                 # Account for perms/tags...
                 $flags = self::getAutoReviewTags($user, $oldSv->getTags());
             }
         } else {
             // new page?
             $flags = self::quickTags(FR_CHECKED);
             // use minimal level
         }
         if (!is_array($flags)) {
             wfProfileOut(__METHOD__);
             return false;
             // can't auto-review this revision
         }
     }
     # Get review property flags
     $propFlags = $auto ? array('auto') : array();
     # Note: this needs to match the prepareContentForEdit() call WikiPage::doEditContent.
     # This is for consistency and also to avoid triggering a second parse otherwise.
     $editInfo = $article->prepareContentForEdit($rev->getContent(), null, $user, $rev->getContentFormat());
     $poutput = $editInfo->output;
     // revision HTML output
     # Get the "review time" versions of templates and files.
     # This tries to make sure each template/file version either came from the stable
     # version of that template/file or was a "review time" version used in the stable
     # version of this page. If a pending version of a template/file is currently vandalism,
     # we try to avoid storing its ID as the "review time" version so it won't show up when
     # someone views the page. If not possible, this stores the current template/file.
     if (FlaggedRevs::inclusionSetting() === FR_INCLUDES_CURRENT) {
         $tVersions = $poutput->getTemplateIds();
         $fVersions = $poutput->getFileSearchOptions();
     } else {
         $tVersions = $oldSv ? $oldSv->getTemplateVersions() : array();
         $fVersions = $oldSv ? $oldSv->getFileVersions() : array();
         foreach ($poutput->getTemplateIds() as $ns => $pages) {
             foreach ($pages as $dbKey => $revId) {
                 if (!isset($tVersions[$ns][$dbKey])) {
                     $srev = FlaggedRevision::newFromStable(Title::makeTitle($ns, $dbKey));
                     if ($srev) {
                         // use stable
                         $tVersions[$ns][$dbKey] = $srev->getRevId();
                     } else {
                         // use current
                         $tVersions[$ns][$dbKey] = $revId;
                     }
                 }
             }
         }
         foreach ($poutput->getFileSearchOptions() as $dbKey => $info) {
             if (!isset($fVersions[$dbKey])) {
                 $srev = FlaggedRevision::newFromStable(Title::makeTitle(NS_FILE, $dbKey));
                 if ($srev && $srev->getFileTimestamp()) {
                     // use stable
                     $fVersions[$dbKey]['time'] = $srev->getFileTimestamp();
                     $fVersions[$dbKey]['sha1'] = $srev->getFileSha1();
                 } else {
                     // use current
                     $fVersions[$dbKey]['time'] = $info['time'];
                     $fVersions[$dbKey]['sha1'] = $info['sha1'];
                 }
             }
         }
     }
     # If this is an image page, get the corresponding file version info...
     $fileData = array('name' => null, 'timestamp' => null, 'sha1' => null);
     if ($title->getNamespace() == NS_FILE) {
         # We must use WikiFilePage process cache on upload or get bitten by slave lag
         $file = $article instanceof WikiFilePage || $article instanceof ImagePage ? $article->getFile() : wfFindFile($title, array('bypassCache' => true));
         // skip cache; bug 31056
         if (is_object($file) && $file->exists()) {
             $fileData['name'] = $title->getDBkey();
             $fileData['timestamp'] = $file->getTimestamp();
             $fileData['sha1'] = $file->getSha1();
         }
     }
     # Our review entry
     $flaggedRevision = new FlaggedRevision(array('rev' => $rev, 'user_id' => $user->getId(), 'timestamp' => $rev->getTimestamp(), 'quality' => FlaggedRevs::getQualityTier($flags, 0), 'tags' => FlaggedRevision::flattenRevisionTags($flags), 'img_name' => $fileData['name'], 'img_timestamp' => $fileData['timestamp'], 'img_sha1' => $fileData['sha1'], 'templateVersions' => $tVersions, 'fileVersions' => $fVersions, 'flags' => implode(',', $propFlags)));
     $flaggedRevision->insert();
     # Update the article review log
     FlaggedRevsLog::updateReviewLog($title, $flags, array(), '', $rev->getId(), $oldSvId, true, $auto);
     # Update page and tracking tables and clear cache
     FlaggedRevs::stableVersionUpdates($article);
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * Automatically review an revision and add a log entry in the review log.
  *
  * This is called during edit operations after the new revision is added
  * and the page tables updated, but before LinksUpdate is called.
  *
  * $auto is here for revisions checked off to be reviewed. Auto-review
  * triggers on edit, but we don't want those to count as just automatic.
  * This also makes it so the user's name shows up in the page history.
  *
  * If $flags is given, then they will be the review tags. If not, the one
  * from the stable version will be used or minimal tags if that's not possible.
  * If no appropriate tags can be found, then the review will abort.
  */
 public static function autoReviewEdit(Page $article, $user, Revision $rev, array $flags = null, $auto = true)
 {
     wfProfileIn(__METHOD__);
     $title = $article->getTitle();
     // convenience
     # Get current stable version ID (for logging)
     $oldSv = FlaggedRevision::newFromStable($title, FR_MASTER);
     $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
     # Set the auto-review tags from the prior stable version.
     # Normally, this should already be done and given here...
     if (!is_array($flags)) {
         if ($oldSv) {
             # Use the last stable version if $flags not given
             if ($user->isAllowed('bot')) {
                 $flags = $oldSv->getTags();
                 // no change for bot edits
             } else {
                 # Account for perms/tags...
                 $flags = self::getAutoReviewTags($user, $oldSv->getTags());
             }
         } else {
             // new page?
             $flags = self::quickTags(FR_CHECKED);
             // use minimal level
         }
         if (!is_array($flags)) {
             wfProfileOut(__METHOD__);
             return false;
             // can't auto-review this revision
         }
     }
     # Get review property flags
     $propFlags = $auto ? array('auto') : array();
     # Rev ID is not put into parser on edit, so do the same here.
     # Also, a second parse would be triggered otherwise.
     $editInfo = $article->prepareTextForEdit($rev->getText());
     $poutput = $editInfo->output;
     // revision HTML output
     # If this is an image page, store corresponding file info
     $fileData = array('name' => null, 'timestamp' => null, 'sha1' => null);
     if ($title->getNamespace() == NS_FILE) {
         # We must use WikiFilePage process cache on upload or get bitten by slave lag
         $file = $article instanceof WikiFilePage || $article instanceof ImagePage ? $article->getFile() : wfFindFile($title, array('bypassCache' => true));
         // skip cache; bug 31056
         if (is_object($file) && $file->exists()) {
             $fileData['name'] = $title->getDBkey();
             $fileData['timestamp'] = $file->getTimestamp();
             $fileData['sha1'] = $file->getSha1();
         }
     }
     # Our review entry
     $flaggedRevision = new FlaggedRevision(array('rev' => $rev, 'user_id' => $user->getId(), 'timestamp' => $rev->getTimestamp(), 'quality' => FlaggedRevs::getQualityTier($flags, 0), 'tags' => FlaggedRevision::flattenRevisionTags($flags), 'img_name' => $fileData['name'], 'img_timestamp' => $fileData['timestamp'], 'img_sha1' => $fileData['sha1'], 'templateVersions' => $poutput->getTemplateIds(), 'fileVersions' => $poutput->getFileSearchOptions(), 'flags' => implode(',', $propFlags)));
     $flaggedRevision->insert();
     # Update the article review log
     FlaggedRevsLog::updateReviewLog($title, $flags, array(), '', $rev->getId(), $oldSvId, true, $auto);
     # Update page and tracking tables and clear cache
     FlaggedRevs::stableVersionUpdates($title);
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * Hook-Handler for Hook 'BSStateBarBeforeBodyViewAdd'
  * @param StateBar $oStateBar
  * @param array $aBodyViews
  * @return boolean Always true to keep hook running
  */
 public function onStateBarBeforeBodyViewAdd($oStateBar, &$aBodyViews, $oUser, $oTitle)
 {
     $text = '';
     $oRev = BsReviewProcess::newFromPid($oTitle->getArticleID());
     $pages = BsReviewProcess::listReviews($oUser->getId());
     if ($oRev === false) {
         return true;
     }
     $oReviewView = new ViewStateBarBodyElementReview();
     $oReviewView->setReview($oRev);
     $oReviewView->addButton('bs-review-dismiss', 'bs-icon-decline', wfMessage('bs-review-i-dismiss')->plain(), wfMessage('bs-review-i-dismiss')->plain());
     $oReviewView->addButton('bs-review-ok', 'bs-icon-accept', wfMessage('bs-review-i-agree')->plain(), wfMessage('bs-review-i-agree')->plain());
     if ($res = $oRev->isFinished()) {
         //$text = wfMessage( 'bs-review-review-finished' )->plain();
         $oReviewView->setStatusText(wfMessage('bs-review-review-finished')->plain());
         if ($oRev->isSequential()) {
             switch ($res) {
                 case 'date':
                     $text .= wfMessage('bs-review-date')->plain();
                     break;
                 case 'status':
                     $text .= wfMessage('bs-review-agreed')->plain();
                     break;
                 case 'denied':
                     $text .= wfMessage('bs-review-denied-disagreed')->plain();
                     break;
             }
         } else {
             $res = $oRev->currentStatus();
             $res = explode(';', $res);
             if ($res[2]) {
                 $text .= "<br />" . wfMessage('bs-review-accepted', $res[2])->plain();
             }
             if ($res[1]) {
                 $text .= "<br />" . wfMessage('bs-review-rejected', $res[1])->plain();
             }
             if ($res[0]) {
                 $text .= "<br />" . wfMessage('bs-review-abstain', $res[0])->plain();
             }
         }
         $oReviewView->setStatusReasonText($text);
     } else {
         $text = wfMessage('bs-review-reviewed-till', $oRev->getStartdate(), $oRev->getEnddate())->plain();
         $user = User::newFromId($oRev->owner);
         $sName = BsCore::getUserDisplayName($user);
         $text .= '<br />' . wfMessage('bs-review-reviewed-till-extra', $user->getName(), $sName)->text();
         $oReviewView->setStatusText($text);
     }
     // Flagged Revision: Only show the "not accepted" icon on the template page an not on the released page, which is accepted.
     $obj = false;
     $bResult = false;
     wfRunHooks('checkPageIsReviewable', array($oTitle, &$bResult));
     if ($bResult) {
         $obj = FlaggedRevision::newFromStable($oTitle);
     }
     $aComments = array();
     foreach ($oRev->steps as $_step) {
         if (!empty($_step->comment) && $_step->status != -1) {
             $aComments[] = $_step->comment;
         }
     }
     $oReviewView->setPreceedingCommentsList($aComments);
     if (empty($pages) || !in_array($oTitle->getArticleID(), $pages)) {
         $aBodyViews['statebarbodyreview'] = $oReviewView;
         return true;
     }
     $step = $oRev->currentStep($oUser->getId());
     if (!is_object($step)) {
         return true;
     }
     $oReviewView->setVotable(true);
     $sUserName = BsCore::getUserDisplayName($oUser);
     $oReviewView->setComment("<em>{$sUserName}:</em> {$step->comment}");
     wfRunHooks('BsReview::checkStatus::afterMessage', array($step, $oReviewView));
     if ($oTitle->userCan("workflowview", $oUser)) {
         $aBodyViews['statebarbodyreview'] = $oReviewView;
     }
     return true;
 }
Пример #6
0
 protected function update_flaggedpages($start = null)
 {
     $this->output("Populating and correcting flaggedpages/flaggedpage_config columns\n");
     $BATCH_SIZE = 300;
     $db = wfGetDB(DB_MASTER);
     if ($start === null) {
         $start = $db->selectField('page', 'MIN(page_id)', false, __METHOD__);
     }
     $end = $db->selectField('page', 'MAX(page_id)', false, __METHOD__);
     if (is_null($start) || is_null($end)) {
         $this->output("...flaggedpages table seems to be empty.\n");
         return;
     }
     # Do remaining chunk
     $end += $BATCH_SIZE - 1;
     $blockStart = $start;
     $blockEnd = $start + $BATCH_SIZE - 1;
     $count = $deleted = $fixed = 0;
     while ($blockEnd <= $end) {
         $this->output("...doing page_id from {$blockStart} to {$blockEnd}\n");
         $cond = "page_id BETWEEN {$blockStart} AND {$blockEnd}";
         $res = $db->select('page', array('page_id', 'page_namespace', 'page_title', 'page_latest'), $cond, __METHOD__);
         # Go through and update the de-normalized references...
         $db->begin();
         foreach ($res as $row) {
             $title = Title::newFromRow($row);
             $article = new FlaggableWikiPage($title);
             $oldFrev = FlaggedRevision::newFromStable($title, FR_MASTER);
             $frev = FlaggedRevision::determineStable($title, FR_MASTER);
             # Update fp_stable, fp_quality, and fp_reviewed
             if ($frev) {
                 $article->updateStableVersion($frev, $row->page_latest);
                 $changed = !$oldFrev || $oldFrev->getRevId() != $frev->getRevId();
                 # Somethings broke? Delete the row...
             } else {
                 $article->clearStableVersion();
                 if ($db->affectedRows() > 0) {
                     $deleted++;
                 }
                 $changed = (bool) $oldFrev;
             }
             # Get the latest revision
             $revRow = $db->selectRow('revision', '*', array('rev_page' => $row->page_id), __METHOD__, array('ORDER BY' => 'rev_timestamp DESC'));
             # Correct page_latest if needed (import/files made plenty of bad rows)
             if ($revRow) {
                 $revision = new Revision($revRow);
                 if ($article->updateIfNewerOn($db, $revision)) {
                     $fixed++;
                 }
             }
             if ($changed) {
                 # Lazily rebuild dependancies on next parse (we invalidate below)
                 FlaggedRevs::clearStableOnlyDeps($title);
                 $title->invalidateCache();
             }
             $count++;
         }
         $db->freeResult($res);
         # Remove manual config settings that simply restate the site defaults
         $db->delete('flaggedpage_config', array("fpc_page_id BETWEEN {$blockStart} AND {$blockEnd}", 'fpc_override' => intval(FlaggedRevs::isStableShownByDefault()), 'fpc_level' => ''), __METHOD__);
         $deleted = $deleted + $db->affectedRows();
         $db->commit();
         $blockStart += $BATCH_SIZE;
         $blockEnd += $BATCH_SIZE;
         wfWaitForSlaves(5);
     }
     $this->output("flaggedpage columns update complete ..." . " {$count} rows [{$fixed} fixed] [{$deleted} deleted]\n");
 }