/**
* Return the list of revision fields that should be selected to create
* a new revision.
+ * @return array
*/
public static function selectFields() {
return array(
/**
* Return the list of text fields that should be selected to read the
* revision text
+ * @return array
*/
public static function selectTextFields() {
return array(
/**
* Return the list of page fields that should be selected from page table
+ * @return array
*/
public static function selectPageFields() {
return array(
/**
* Return the list of user fields that should be selected from user table
+ * @return array
*/
public static function selectUserFields() {
return array( 'user_name' );
$this->mSha1 = isset( $row['sha1'] ) ? strval( $row['sha1'] ) : null;
$this->mContentModelName = isset( $row['content_model'] ) ? strval( $row['content_model'] ) : null;
- $this->mContentFormat = isset( $row['content_format'] ) ? strval( $row['content_format'] ) : null;
-
- if( !isset( $row->rev_content_format ) || is_null( $row->rev_content_format ) ) {
- $this->mContentFormat = null; # determine on demand if needed
- } else {
- $this->mContentFormat = $row->rev_content_format;
- }
+ $this->mContentFormat = isset( $row['content_format'] ) ? strval( $row['content_format'] ) : null;
// Enforce spacing trimming on supplied text
$this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null;
# if we have a content object, serialize it, overriding mText
if ( !empty( $row['content'] ) ) {
$handler = $this->getContentHandler();
- $this->mText = $handler->serialize( $row['content'], $this->getContentFormat() );
+ $this->mText = $handler->serializeContent( $row['content'], $this->getContentFormat() );
}
} else {
throw new MWException( 'Revision constructor passed invalid row format.' );
}
$this->mUnpatrolled = null;
- #FIXME: add patch for ar_content_format, ar_content_model, rev_content_format, rev_content_model to installer
- #FIXME: add support for ar_content_format, ar_content_model, rev_content_format, rev_content_model to API
+ // @TODO: add support for ar_content_format, ar_content_model, rev_content_format, rev_content_model to API
+ // @TODO: get rid of $mText
}
/**
/**
* Get parent revision ID (the original previous page revision)
*
- * @return Integer
+ * @return Integer|null
*/
public function getParentId() {
return $this->mParentId;
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow(
array( 'page', 'revision' ),
- array( 'page_namespace', 'page_title' ),
+ self::selectPageFields(),
array( 'page_id=rev_page',
'rev_id' => $this->mId ),
- 'Revision::getTitle' );
- if( $row ) {
- $this->mTitle = Title::makeTitle( $row->page_namespace, $row->page_title );
+ __METHOD__ );
+ if ( $row ) {
+ $this->mTitle = Title::newFromRow( $row );
}
return $this->mTitle;
}
$this->mText = $this->loadText();
}
- $this->mContent = $handler->unserialize( $this->mText, $title, $format );
+ $this->mContent = is_null( $this->mText ) ? null : $handler->unserializeContent( $this->mText, $format );
}
return $this->mContent;
public function getContentHandler() {
if ( !$this->mContentHandler ) {
- $title = $this->getTitle();
-
- if ( $title ) $model = $title->getContentModelName();
- else $model = CONTENT_MODEL_WIKITEXT;
-
+ $model = $this->getContentModelName();
$this->mContentHandler = ContentHandler::getForModelName( $model );
- #XXX: do we need to verify that mContentHandler supports mContentFormat?
- # otherwise, a fixed content format may cause problems on insert.
+ assert( $this->mContentHandler->isSupportedFormat( $this->getContentFormat() ) );
}
return $this->mContentHandler;
$rev_id = isset( $this->mId )
? $this->mId
: $dbw->nextSequenceValue( 'revision_rev_id_seq' );
- $dbw->insert( 'revision',
- array(
- 'rev_id' => $rev_id,
- 'rev_page' => $this->mPage,
- 'rev_text_id' => $this->mTextId,
- 'rev_comment' => $this->mComment,
- 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0,
- 'rev_user' => $this->mUser,
- 'rev_user_text' => $this->mUserText,
- 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ),
- 'rev_deleted' => $this->mDeleted,
- 'rev_len' => $this->mSize,
- 'rev_parent_id' => is_null( $this->mParentId )
- ? $this->getPreviousRevisionId( $dbw )
- : $this->mParentId,
- 'rev_sha1' => is_null( $this->mSha1 )
- ? Revision::base36Sha1( $this->mText )
- : $this->mSha1,
- 'rev_content_model' => $this->getContentModelName(),
- 'rev_content_format' => $this->getContentFormat(),
- ), __METHOD__
- );
+
+ $row = array(
+ 'rev_id' => $rev_id,
+ 'rev_page' => $this->mPage,
+ 'rev_text_id' => $this->mTextId,
+ 'rev_comment' => $this->mComment,
+ 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0,
+ 'rev_user' => $this->mUser,
+ 'rev_user_text' => $this->mUserText,
+ 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ),
+ 'rev_deleted' => $this->mDeleted,
+ 'rev_len' => $this->mSize,
+ 'rev_parent_id' => is_null( $this->mParentId )
+ ? $this->getPreviousRevisionId( $dbw )
+ : $this->mParentId,
+ 'rev_sha1' => is_null( $this->mSha1 )
+ ? Revision::base36Sha1( $this->mText )
+ : $this->mSha1,
+ 'rev_content_model' => $this->getContentModelName(),
+ 'rev_content_format' => $this->getContentFormat(),
+ );
+
+ $dbw->insert( 'revision', $row, __METHOD__ );
$this->mId = !is_null( $rev_id ) ? $rev_id : $dbw->insertId();
$id = 0;
}
$conds = array( 'rev_id' => $id );
- $conds['rev_page'] = $title->getArticleId();
+ $conds['rev_page'] = $title->getArticleID();
$timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
# Not in slave, try master
* @return Integer
*/
static function countByTitle( $db, $title ) {
- $id = $title->getArticleId();
+ $id = $title->getArticleID();
if( $id ) {
return Revision::countByPageId( $db, $id );
}