/** * Adds or updates the flagged revision table for this page/id set * @param Revision $rev The revision to be accepted * @param FlaggedRevision $oldFrev Currently accepted version of $rev or null * @throws MWException * @return bool|array true on success, array of errors on failure */ private function approveRevision(Revision $rev, FlaggedRevision $oldFrev = null) { wfProfileIn(__METHOD__); # Revision rating flags $flags = $this->dims; $quality = 0; // quality tier from flags if (FlaggedRevs::isQuality($flags)) { $quality = FlaggedRevs::isPristine($flags) ? 2 : 1; } # Our template/file version pointers list($tmpVersions, $fileVersions) = self::getIncludeVersions($this->templateParams, $this->imageParams); # If this is an image page, store corresponding file info $fileData = array('name' => null, 'timestamp' => null, 'sha1' => null); if ($this->page->getNamespace() == NS_FILE && $this->fileVersion) { # Stable upload version for file pages... $data = explode('#', $this->fileVersion, 2); if (count($data) == 2) { $fileData['name'] = $this->page->getDBkey(); $fileData['timestamp'] = $data[0]; $fileData['sha1'] = $data[1]; } } # Get current stable version ID (for logging) $oldSv = FlaggedRevision::newFromStable($this->page, FR_MASTER); # Is this a duplicate review? if ($oldFrev && $oldFrev->getTags() == $flags && $oldFrev->getFileSha1() == $fileData['sha1'] && $oldFrev->getFileTimestamp() == $fileData['timestamp'] && $oldFrev->getTemplateVersions(FR_MASTER) == $tmpVersions && $oldFrev->getFileVersions(FR_MASTER) == $fileVersions) { wfProfileOut(__METHOD__); return true; // don't record if the same } # The new review entry... $flaggedRevision = new FlaggedRevision(array('rev' => $rev, 'user_id' => $this->user->getId(), 'timestamp' => wfTimestampNow(), 'quality' => $quality, 'tags' => FlaggedRevision::flattenRevisionTags($flags), 'img_name' => $fileData['name'], 'img_timestamp' => $fileData['timestamp'], 'img_sha1' => $fileData['sha1'], 'templateVersions' => $tmpVersions, 'fileVersions' => $fileVersions, 'flags' => '')); # Delete the old review entry if it exists... if ($oldFrev) { $oldFrev->delete(); } # Insert the new review entry... if (!$flaggedRevision->insert()) { throw new MWException("Flagged revision with ID {$rev->getId()} exists with unexpected fr_page_id"); } # Update the article review log... $oldSvId = $oldSv ? $oldSv->getRevId() : 0; FlaggedRevsLog::updateReviewLog($this->page, $this->dims, $this->oldFlags, $this->comment, $this->oldid, $oldSvId, true); # Get the new stable version as of now $sv = FlaggedRevision::determineStable($this->page, FR_MASTER); # Update recent changes... self::updateRecentChanges($rev, 'patrol', $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 = $flaggedRevision->getTimestamp(); wfProfileOut(__METHOD__); return true; }