/**
  * Adds a notice saying that this revision is pending review
  * @param FlaggedRevision $srev The stable version
  * @param string $diffToggle either "" or " <diff toggle><diff div>"
  * @return void
  */
 public function setPendingNotice(FlaggedRevision $srev, $diffToggle = '')
 {
     $this->load();
     $time = $this->getLang()->date($srev->getTimestamp(), true);
     $revsSince = $this->article->getPendingRevCount();
     $msg = $srev->getQuality() ? 'revreview-newest-quality' : 'revreview-newest-basic';
     $msg .= $revsSince == 0 ? '-i' : '';
     # Add bar msg to the top of the page...
     $css = 'flaggedrevs_preview plainlinks';
     $msgHTML = wfMsgExt($msg, 'parseinline', $srev->getRevId(), $time, $revsSince);
     $this->reviewNotice .= "<div id='mw-fr-reviewnotice' class='{$css}'>" . "{$msgHTML}{$diffToggle}</div>";
 }
 /**
  * Updates the flagging tracking tables for this page
  * @param FlaggedRevision $srev The new stable version
  * @param int|null $latest The latest rev ID (optional)
  * @return bool Updates were done
  */
 public function updateStableVersion(FlaggedRevision $srev, $latest = null)
 {
     $rev = $srev->getRevision();
     if (!$this->exists() || !$rev) {
         return false;
         // no bogus entries
     }
     # Get the latest revision ID if not set
     if (!$latest) {
         $latest = $this->mTitle->getLatestRevID(Title::GAID_FOR_UPDATE);
     }
     $dbw = wfGetDB(DB_MASTER);
     # Get the highest quality revision (not necessarily this one)...
     if ($srev->getQuality() === FlaggedRevs::highestReviewTier()) {
         $maxQuality = $srev->getQuality();
         // save a query
     } else {
         $maxQuality = $dbw->selectField(array('flaggedrevs', 'revision'), 'fr_quality', array('fr_page_id' => $this->getId(), 'rev_id = fr_rev_id', 'rev_page = fr_page_id', 'rev_deleted & ' . Revision::DELETED_TEXT => 0), __METHOD__, array('ORDER BY' => 'fr_quality DESC', 'LIMIT' => 1));
         $maxQuality = max($maxQuality, $srev->getQuality());
         // sanity
     }
     # Get the timestamp of the first edit after the stable version (if any)...
     $nextTimestamp = null;
     if ($rev->getId() != $latest) {
         $timestamp = $dbw->timestamp($rev->getTimestamp());
         $nextEditTS = $dbw->selectField('revision', 'rev_timestamp', array('rev_page' => $this->getId(), "rev_timestamp > " . $dbw->addQuotes($timestamp)), __METHOD__, array('ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1));
         if ($nextEditTS) {
             // sanity check
             $nextTimestamp = $nextEditTS;
         }
     }
     # Get the new page sync status...
     $synced = !($nextTimestamp !== null || $srev->findPendingTemplateChanges() || $srev->findPendingFileChanges('noForeign'));
     # Alter table metadata
     $dbw->replace('flaggedpages', array('fp_page_id'), array('fp_page_id' => $this->getId(), 'fp_stable' => $rev->getId(), 'fp_reviewed' => $synced ? 1 : 0, 'fp_quality' => $maxQuality === false ? null : $maxQuality, 'fp_pending_since' => $dbw->timestampOrNull($nextTimestamp)), __METHOD__);
     # Update pending edit tracking table
     self::updatePendingList($this->getId(), $latest);
     return true;
 }