+ /**
+ * Update the page record to point to a newly saved revision.
+ *
+ * @param Database $dbw
+ * @param Revision $revision -- for ID number, and text used to set
+ length and redirect status fields
+ * @param int $lastRevision -- if given, will not overwrite the page field
+ * when different from the currently set value.
+ * Giving 0 indicates the new page flag should
+ * be set on.
+ * @return bool true on success, false on failure
+ * @access private
+ */
+ function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
+ $fname = 'Article::updateToRevision';
+ wfProfileIn( $fname );
+
+ $conditions = array( 'page_id' => $this->getId() );
+ if( !is_null( $lastRevision ) ) {
+ # An extra check against threads stepping on each other
+ $conditions['page_latest'] = $lastRevision;
+ }
+ $text = $revision->getText();
+ $dbw->update( 'page',
+ array( /* SET */
+ 'page_latest' => $revision->getId(),
+ 'page_touched' => $dbw->timestamp(),
+ 'page_is_new' => ($lastRevision === 0) ? 1 : 0,
+ 'page_is_redirect' => Article::isRedirect( $text ),
+ 'page_len' => strlen( $text ),
+ ),
+ $conditions,
+ $fname );
+
+ wfProfileOut( $fname );
+ return ( $dbw->affectedRows() != 0 );
+ }
+
+ /**
+ * If the given revision is newer than the currently set page_latest,
+ * update the page record. Otherwise, do nothing.
+ *
+ * @param Database $dbw
+ * @param Revision $revision
+ */
+ function updateIfNewerOn( &$dbw, $revision ) {
+ $fname = 'Article::updateIfNewerOn';
+ wfProfileIn( $fname );
+
+ $row = $dbw->selectRow(
+ array( 'revision', 'page' ),
+ array( 'rev_id', 'rev_timestamp' ),
+ array(
+ 'page_id' => $this->getId(),
+ 'page_latest=rev_id' ),
+ $fname );
+ if( $row ) {
+ if( $row->rev_timestamp >= $revision->getTimestamp() ) {
+ wfProfileOut( $fname );
+ return false;
+ }
+ $prev = $row->rev_id;
+ } else {
+ # No or missing previous revision; mark the page as new
+ $prev = 0;
+ }
+
+ $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
+ wfProfileOut( $fname );
+ return $ret;