MediaWiki REL1_34
RevisionStoreRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
26use InvalidArgumentException;
28use Title;
29use User;
30use Wikimedia\Assert\Assert;
31
40
42 protected $mCurrent = false;
43
56 function __construct(
58 UserIdentity $user,
59 CommentStoreComment $comment,
60 $row,
61 RevisionSlots $slots,
62 $dbDomain = false
63 ) {
64 parent::__construct( $title, $slots, $dbDomain );
65 Assert::parameterType( 'object', $row, '$row' );
66
67 $this->mId = intval( $row->rev_id );
68 $this->mPageId = intval( $row->rev_page );
69 $this->mComment = $comment;
70
71 $timestamp = wfTimestamp( TS_MW, $row->rev_timestamp );
72 Assert::parameter( is_string( $timestamp ), '$row->rev_timestamp', 'must be a valid timestamp' );
73
74 $this->mUser = $user;
75 $this->mMinorEdit = boolval( $row->rev_minor_edit );
76 $this->mTimestamp = $timestamp;
77 $this->mDeleted = intval( $row->rev_deleted );
78
79 // NOTE: rev_parent_id = 0 indicates that there is no parent revision, while null
80 // indicates that the parent revision is unknown. As per MW 1.31, the database schema
81 // allows rev_parent_id to be NULL.
82 $this->mParentId = isset( $row->rev_parent_id ) ? intval( $row->rev_parent_id ) : null;
83 $this->mSize = isset( $row->rev_len ) ? intval( $row->rev_len ) : null;
84 $this->mSha1 = !empty( $row->rev_sha1 ) ? $row->rev_sha1 : null;
85
86 // NOTE: we must not call $this->mTitle->getLatestRevID() here, since the state of
87 // page_latest may be in limbo during revision creation. In that case, calling
88 // $this->mTitle->getLatestRevID() would cause a bad value to be cached in the Title
89 // object. During page creation, that bad value would be 0.
90 if ( isset( $row->page_latest ) ) {
91 $this->mCurrent = ( $row->rev_id == $row->page_latest );
92 }
93
94 // sanity check
95 if (
96 $this->mPageId && $this->mTitle->exists()
97 && $this->mPageId !== $this->mTitle->getArticleID()
98 ) {
99 throw new InvalidArgumentException(
100 'The given Title does not belong to page ID ' . $this->mPageId .
101 ' but actually belongs to ' . $this->mTitle->getArticleID()
102 );
103 }
104 }
105
111 public function isCurrent() {
112 return $this->mCurrent;
113 }
114
122 public function isDeleted( $field ) {
123 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
124 // Current revisions of pages cannot have the content hidden. Skipping this
125 // check is very useful for Parser as it fetches templates using newKnownCurrent().
126 // Calling getVisibility() in that case triggers a verification database query.
127 return false; // no need to check
128 }
129
130 return parent::isDeleted( $field );
131 }
132
133 protected function userCan( $field, User $user ) {
134 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
135 // Current revisions of pages cannot have the content hidden. Skipping this
136 // check is very useful for Parser as it fetches templates using newKnownCurrent().
137 // Calling getVisibility() in that case triggers a verification database query.
138 return true; // no need to check
139 }
140
141 return parent::userCan( $field, $user );
142 }
143
147 public function getId() {
148 // overwritten just to add a guarantee to the contract
149 return parent::getId();
150 }
151
156 public function getSize() {
157 // If length is null, calculate and remember it (potentially SLOW!).
158 // This is for compatibility with old database rows that don't have the field set.
159 if ( $this->mSize === null ) {
160 $this->mSize = $this->mSlots->computeSize();
161 }
162
163 return $this->mSize;
164 }
165
170 public function getSha1() {
171 // If hash is null, calculate it and remember (potentially SLOW!)
172 // This is for compatibility with old database rows that don't have the field set.
173 if ( $this->mSha1 === null ) {
174 $this->mSha1 = $this->mSlots->computeSha1();
175 }
176
177 return $this->mSha1;
178 }
179
186 public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
187 // overwritten just to add a guarantee to the contract
188 return parent::getUser( $audience, $user );
189 }
190
197 public function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
198 // overwritten just to add a guarantee to the contract
199 return parent::getComment( $audience, $user );
200 }
201
205 public function getTimestamp() {
206 // overwritten just to add a guarantee to the contract
207 return parent::getTimestamp();
208 }
209
215 public function isReadyForInsertion() {
216 return true;
217 }
218
219}
220
225class_alias( RevisionStoreRecord::class, 'MediaWiki\Storage\RevisionStoreRecord' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
CommentStoreComment represents a comment stored by CommentStore.
Page revision base class.
Value object representing the set of slots belonging to a revision.
A RevisionRecord representing an existing revision persisted in the revision table.
isDeleted( $field)
MCR migration note: this replaces Revision::isDeleted.
getComment( $audience=self::FOR_PUBLIC, User $user=null)
__construct(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $dbDomain=false)
userCan( $field, User $user)
Determine if the current user is allowed to view a particular field of this revision,...
getUser( $audience=self::FOR_PUBLIC, User $user=null)
isCurrent()
MCR migration note: this replaces Revision::isCurrent.
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
Interface for objects representing user identity.