MediaWiki  1.34.0
RevisionArchiveRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
27 use Title;
28 use User;
29 use Wikimedia\Assert\Assert;
30 
41 
45  protected $mArchiveId;
46 
59  function __construct(
60  Title $title,
61  UserIdentity $user,
62  CommentStoreComment $comment,
63  $row,
64  RevisionSlots $slots,
65  $dbDomain = false
66  ) {
67  parent::__construct( $title, $slots, $dbDomain );
68  Assert::parameterType( 'object', $row, '$row' );
69 
70  $timestamp = wfTimestamp( TS_MW, $row->ar_timestamp );
71  Assert::parameter( is_string( $timestamp ), '$row->rev_timestamp', 'must be a valid timestamp' );
72 
73  $this->mArchiveId = intval( $row->ar_id );
74 
75  // NOTE: ar_page_id may be different from $this->mTitle->getArticleID() in some cases,
76  // notably when a partially restored page has been moved, and a new page has been created
77  // with the same title. Archive rows for that title will then have the wrong page id.
78  $this->mPageId = isset( $row->ar_page_id ) ? intval( $row->ar_page_id ) : $title->getArticleID();
79 
80  // NOTE: ar_parent_id = 0 indicates that there is no parent revision, while null
81  // indicates that the parent revision is unknown. As per MW 1.31, the database schema
82  // allows ar_parent_id to be NULL.
83  $this->mParentId = isset( $row->ar_parent_id ) ? intval( $row->ar_parent_id ) : null;
84  $this->mId = isset( $row->ar_rev_id ) ? intval( $row->ar_rev_id ) : null;
85  $this->mComment = $comment;
86  $this->mUser = $user;
87  $this->mTimestamp = $timestamp;
88  $this->mMinorEdit = boolval( $row->ar_minor_edit );
89  $this->mDeleted = intval( $row->ar_deleted );
90  $this->mSize = isset( $row->ar_len ) ? intval( $row->ar_len ) : null;
91  $this->mSha1 = !empty( $row->ar_sha1 ) ? $row->ar_sha1 : null;
92  }
93 
99  public function getArchiveId() {
100  return $this->mArchiveId;
101  }
102 
107  public function getId() {
108  // overwritten just to refine the contract specification.
109  return parent::getId();
110  }
111 
116  public function getSize() {
117  // If length is null, calculate and remember it (potentially SLOW!).
118  // This is for compatibility with old database rows that don't have the field set.
119  if ( $this->mSize === null ) {
120  $this->mSize = $this->mSlots->computeSize();
121  }
122 
123  return $this->mSize;
124  }
125 
130  public function getSha1() {
131  // If hash is null, calculate it and remember (potentially SLOW!)
132  // This is for compatibility with old database rows that don't have the field set.
133  if ( $this->mSha1 === null ) {
134  $this->mSha1 = $this->mSlots->computeSha1();
135  }
136 
137  return $this->mSha1;
138  }
139 
146  public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
147  // overwritten just to add a guarantee to the contract
148  return parent::getUser( $audience, $user );
149  }
150 
157  public function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
158  // overwritten just to add a guarantee to the contract
159  return parent::getComment( $audience, $user );
160  }
161 
165  public function getTimestamp() {
166  // overwritten just to add a guarantee to the contract
167  return parent::getTimestamp();
168  }
169 
175  public function isReadyForInsertion() {
176  return true;
177  }
178 
179 }
180 
185 class_alias( RevisionArchiveRecord::class, 'MediaWiki\Storage\RevisionArchiveRecord' );
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
Revision\RevisionArchiveRecord\getId
getId()
Definition: RevisionArchiveRecord.php:107
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1869
getUser
getUser()
Revision\RevisionArchiveRecord\getTimestamp
getTimestamp()
Definition: RevisionArchiveRecord.php:165
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
MediaWiki\Revision
Created by PhpStorm.
Definition: FallbackSlotRoleHandler.php:23
Revision\RevisionArchiveRecord\getArchiveId
getArchiveId()
Get archive row ID.
Definition: RevisionArchiveRecord.php:99
Revision\RevisionArchiveRecord\__construct
__construct(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $dbDomain=false)
Definition: RevisionArchiveRecord.php:59
$title
$title
Definition: testCompression.php:34
Revision\RevisionArchiveRecord\$mArchiveId
int $mArchiveId
Definition: RevisionArchiveRecord.php:45
Revision\RevisionArchiveRecord
A RevisionRecord representing a revision of a deleted page persisted in the archive table.
Definition: RevisionArchiveRecord.php:40
Revision\RevisionArchiveRecord\getSize
getSize()
Definition: RevisionArchiveRecord.php:116
Revision\RevisionRecord\$mSize
int null $mSize
Definition: RevisionRecord.php:77
Revision\RevisionArchiveRecord\isReadyForInsertion
isReadyForInsertion()
Definition: RevisionArchiveRecord.php:175
Title
Represents a title within MediaWiki.
Definition: Title.php:42
Revision\RevisionArchiveRecord\getSha1
getSha1()
Definition: RevisionArchiveRecord.php:130
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:35
getTimestamp
getTimestamp()
Definition: RevisionSearchResultTrait.php:154
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
Revision\RevisionArchiveRecord\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Definition: RevisionArchiveRecord.php:157
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:146