MediaWiki  master
RevisionArchiveRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
27 use MWTimestamp;
28 use Title;
29 use User;
30 use Wikimedia\Assert\Assert;
31 
42 
46  protected $mArchiveId;
47 
60  public function __construct(
61  Title $title,
62  UserIdentity $user,
63  CommentStoreComment $comment,
64  $row,
65  RevisionSlots $slots,
66  $dbDomain = false
67  ) {
68  parent::__construct( $title, $slots, $dbDomain );
69  Assert::parameterType( 'object', $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->mTitle->getArticleID() 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 ) : $title->getArticleID();
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 
108  public function getId() {
109  // overwritten just to refine the contract specification.
110  return parent::getId();
111  }
112 
117  public function getSize() {
118  // If length is null, calculate and remember it (potentially SLOW!).
119  // This is for compatibility with old database rows that don't have the field set.
120  if ( $this->mSize === null ) {
121  $this->mSize = $this->mSlots->computeSize();
122  }
123 
124  return $this->mSize;
125  }
126 
131  public function getSha1() {
132  // If hash is null, calculate it and remember (potentially SLOW!)
133  // This is for compatibility with old database rows that don't have the field set.
134  if ( $this->mSha1 === null ) {
135  $this->mSha1 = $this->mSlots->computeSha1();
136  }
137 
138  return $this->mSha1;
139  }
140 
147  public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
148  // overwritten just to add a guarantee to the contract
149  return parent::getUser( $audience, $user );
150  }
151 
158  public function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
159  // overwritten just to add a guarantee to the contract
160  return parent::getComment( $audience, $user );
161  }
162 
166  public function getTimestamp() {
167  // overwritten just to add a guarantee to the contract
168  return parent::getTimestamp();
169  }
170 
176  public function isReadyForInsertion() {
177  return true;
178  }
179 
180 }
181 
186 class_alias( RevisionArchiveRecord::class, 'MediaWiki\Storage\RevisionArchiveRecord' );
MWTimestamp
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:32
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
Revision\RevisionArchiveRecord\getId
getId()
Definition: RevisionArchiveRecord.php:108
getUser
getUser()
Revision\RevisionArchiveRecord\getTimestamp
getTimestamp()
Definition: RevisionArchiveRecord.php:166
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
MediaWiki\Revision
Definition: FallbackSlotRoleHandler.php:23
Revision\RevisionArchiveRecord\getArchiveId
getArchiveId()
Get archive row ID.
Definition: RevisionArchiveRecord.php:100
Revision\RevisionArchiveRecord\__construct
__construct(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $dbDomain=false)
Definition: RevisionArchiveRecord.php:60
$title
$title
Definition: testCompression.php:38
Revision\RevisionArchiveRecord\$mArchiveId
int $mArchiveId
Definition: RevisionArchiveRecord.php:46
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:117
Revision\RevisionRecord\$mSize
int null $mSize
Definition: RevisionRecord.php:77
Revision\RevisionArchiveRecord\isReadyForInsertion
isReadyForInsertion()
Definition: RevisionArchiveRecord.php:176
Title
Represents a title within MediaWiki.
Definition: Title.php:42
Revision\RevisionArchiveRecord\getSha1
getSha1()
Definition: RevisionArchiveRecord.php:131
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:39
getTimestamp
getTimestamp()
Definition: RevisionSearchResultTrait.php:161
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:55
Revision\RevisionArchiveRecord\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Definition: RevisionArchiveRecord.php:158
Revision\RevisionRecord\$mSha1
string null $mSha1
Definition: RevisionRecord.php:79
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29
Revision\RevisionArchiveRecord\getUser
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Definition: RevisionArchiveRecord.php:147