MediaWiki master
RevisionArchiveRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
30use stdClass;
31use Wikimedia\Assert\Assert;
32
43
47 protected $mArchiveId;
48
61 public function __construct(
62 PageIdentity $page,
63 UserIdentity $user,
64 CommentStoreComment $comment,
65 stdClass $row,
66 RevisionSlots $slots,
67 $wikiId = self::LOCAL
68 ) {
69 parent::__construct( $page, $slots, $wikiId );
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 = (bool)$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 $this->mSize ??= $this->mSlots->computeSize();
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 $this->mSha1 ??= $this->mSlots->computeSha1();
134
135 return $this->mSha1;
136 }
137
144 public function getUser( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
145 // overwritten just to add a guarantee to the contract
146 return parent::getUser( $audience, $performer );
147 }
148
155 public function getComment( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
156 // overwritten just to add a guarantee to the contract
157 return parent::getComment( $audience, $performer );
158 }
159
163 public function getTimestamp() {
164 // overwritten just to add a guarantee to the contract
165 return parent::getTimestamp();
166 }
167
168 public function userCan( $field, Authority $performer ) {
169 // This revision belongs to a deleted page, so check the relevant permissions as well. (T345777)
170
171 // Viewing the content requires either 'deletedtext' or 'undelete' (for legacy reasons)
172 if (
173 $field === self::DELETED_TEXT &&
174 !$performer->authorizeRead( 'deletedtext', $this->getPage() ) &&
175 !$performer->authorizeRead( 'undelete', $this->getPage() )
176 ) {
177 return false;
178 }
179
180 // Viewing the edit summary requires 'deletedhistory'
181 if (
182 $field === self::DELETED_COMMENT &&
183 !$performer->authorizeRead( 'deletedhistory', $this->getPage() )
184 ) {
185 return false;
186 }
187
188 // Other fields of revisions of deleted pages are public, per T232389 (unless revision-deleted)
189
190 return parent::userCan( $field, $performer );
191 }
192
193 public function audienceCan( $field, $audience, Authority $performer = null ) {
194 // This revision belongs to a deleted page, so check the relevant permissions as well. (T345777)
195 // See userCan().
196 if (
197 $audience == self::FOR_PUBLIC &&
198 ( $field === self::DELETED_TEXT || $field === self::DELETED_COMMENT )
199 ) {
200 // TODO: Should this use PermissionManager::isEveryoneAllowed() or something?
201 // But RevisionRecord::audienceCan() doesn't do that either…
202 return false;
203 }
204
205 // This calls userCan(), which checks the user's permissions
206 return parent::audienceCan( $field, $audience, $performer );
207 }
208
214 public function isReadyForInsertion() {
215 return true;
216 }
217
218}
Value object for a comment stored by CommentStore.
A RevisionRecord representing a revision of a deleted page persisted in the archive table.
__construct(PageIdentity $page, UserIdentity $user, CommentStoreComment $comment, stdClass $row, RevisionSlots $slots, $wikiId=self::LOCAL)
getComment( $audience=self::FOR_PUBLIC, Authority $performer=null)
audienceCan( $field, $audience, Authority $performer=null)
Check that the given audience has access to the given field.
userCan( $field, Authority $performer)
Determine if the give authority is allowed to view a particular field of this revision,...
getUser( $audience=self::FOR_PUBLIC, Authority $performer=null)
Page revision base class.
string false $wikiId
Wiki ID; false means the current wiki.
Value object representing the set of slots belonging to a revision.
Library for creating and parsing MW-style timestamps.
Interface for objects (potentially) representing an editable wiki page.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:37
authorizeRead(string $action, PageIdentity $target, PermissionStatus $status=null)
Authorize read access.
Interface for objects representing user identity.