MediaWiki  master
RevisionArchiveRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
29 use MWTimestamp;
30 use Wikimedia\Assert\Assert;
31 
42 
46  protected $mArchiveId;
47 
60  public function __construct(
61  PageIdentity $page,
62  UserIdentity $user,
63  CommentStoreComment $comment,
64  $row,
65  RevisionSlots $slots,
66  $wikiId = self::LOCAL
67  ) {
68  parent::__construct( $page, $slots, $wikiId );
69  Assert::parameterType( \stdClass::class, $row, '$row' );
70 
71  $timestamp = MWTimestamp::convert( TS_MW, $row->ar_timestamp );
72  Assert::parameter( is_string( $timestamp ), '$row->rev_timestamp', 'must be a valid timestamp' );
73 
74  $this->mArchiveId = intval( $row->ar_id );
75 
76  // NOTE: ar_page_id may be different from $this->mPage->getId() in some cases,
77  // notably when a partially restored page has been moved, and a new page has been created
78  // with the same title. Archive rows for that title will then have the wrong page id.
79  $this->mPageId = isset( $row->ar_page_id ) ? intval( $row->ar_page_id ) : $this->getArticleId( $this->mPage );
80 
81  // NOTE: ar_parent_id = 0 indicates that there is no parent revision, while null
82  // indicates that the parent revision is unknown. As per MW 1.31, the database schema
83  // allows ar_parent_id to be NULL.
84  $this->mParentId = isset( $row->ar_parent_id ) ? intval( $row->ar_parent_id ) : null;
85  $this->mId = isset( $row->ar_rev_id ) ? intval( $row->ar_rev_id ) : null;
86  $this->mComment = $comment;
87  $this->mUser = $user;
88  $this->mTimestamp = $timestamp;
89  $this->mMinorEdit = boolval( $row->ar_minor_edit );
90  $this->mDeleted = intval( $row->ar_deleted );
91  $this->mSize = isset( $row->ar_len ) ? intval( $row->ar_len ) : null;
92  $this->mSha1 = !empty( $row->ar_sha1 ) ? $row->ar_sha1 : null;
93  }
94 
100  public function getArchiveId() {
101  return $this->mArchiveId;
102  }
103 
109  public function getId( $wikiId = self::LOCAL ) {
110  // overwritten just to refine the contract specification.
111  return parent::getId( $wikiId );
112  }
113 
118  public function getSize() {
119  // If length is null, calculate and remember it (potentially SLOW!).
120  // This is for compatibility with old database rows that don't have the field set.
121  if ( $this->mSize === null ) {
122  $this->mSize = $this->mSlots->computeSize();
123  }
124 
125  return $this->mSize;
126  }
127 
132  public function getSha1() {
133  // If hash is null, calculate it and remember (potentially SLOW!)
134  // This is for compatibility with old database rows that don't have the field set.
135  if ( $this->mSha1 === null ) {
136  $this->mSha1 = $this->mSlots->computeSha1();
137  }
138 
139  return $this->mSha1;
140  }
141 
148  public function getUser( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
149  // overwritten just to add a guarantee to the contract
150  return parent::getUser( $audience, $performer );
151  }
152 
159  public function getComment( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
160  // overwritten just to add a guarantee to the contract
161  return parent::getComment( $audience, $performer );
162  }
163 
167  public function getTimestamp() {
168  // overwritten just to add a guarantee to the contract
169  return parent::getTimestamp();
170  }
171 
177  public function isReadyForInsertion() {
178  return true;
179  }
180 
181 }
182 
187 class_alias( RevisionArchiveRecord::class, 'MediaWiki\Storage\RevisionArchiveRecord' );
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:65
MWTimestamp
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:37
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
Revision\RevisionArchiveRecord\getUser
getUser( $audience=self::FOR_PUBLIC, Authority $performer=null)
Definition: RevisionArchiveRecord.php:148
Revision\RevisionArchiveRecord\getTimestamp
getTimestamp()
Definition: RevisionArchiveRecord.php:167
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
Revision\RevisionArchiveRecord\getComment
getComment( $audience=self::FOR_PUBLIC, Authority $performer=null)
Definition: RevisionArchiveRecord.php:159
MediaWiki\Revision
Definition: ContributionsLookup.php:3
Revision\RevisionArchiveRecord\getArchiveId
getArchiveId()
Get archive row ID.
Definition: RevisionArchiveRecord.php:100
Revision\RevisionRecord\$wikiId
string false $wikiId
Wiki ID; false means the current wiki.
Definition: RevisionRecord.php:67
Revision\RevisionArchiveRecord\$mArchiveId
int $mArchiveId
Definition: RevisionArchiveRecord.php:46
MediaWiki\Permissions\Authority
Definition: Authority.php:30
Revision\RevisionArchiveRecord
A RevisionRecord representing a revision of a deleted page persisted in the archive table.
Definition: RevisionArchiveRecord.php:41
Revision\RevisionArchiveRecord\getSize
getSize()
Definition: RevisionArchiveRecord.php:118
Revision\RevisionArchiveRecord\getId
getId( $wikiId=self::LOCAL)
Definition: RevisionArchiveRecord.php:109
Revision\RevisionArchiveRecord\__construct
__construct(PageIdentity $page, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiId=self::LOCAL)
Definition: RevisionArchiveRecord.php:60
Revision\RevisionRecord\$mSize
int null $mSize
Definition: RevisionRecord.php:81
Revision\RevisionArchiveRecord\isReadyForInsertion
isReadyForInsertion()
Definition: RevisionArchiveRecord.php:177
Revision\RevisionArchiveRecord\getSha1
getSha1()
Definition: RevisionArchiveRecord.php:132
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:41
getTimestamp
getTimestamp()
Definition: RevisionSearchResultTrait.php:161
Revision\RevisionRecord\$mSha1
string null $mSha1
Definition: RevisionRecord.php:83
CommentStoreComment
Value object for a comment stored by CommentStore.
Definition: CommentStoreComment.php:30