MediaWiki REL1_35
RevisionStoreRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
26use InvalidArgumentException;
28use MWTimestamp;
29use Title;
30use User;
31use Wikimedia\Assert\Assert;
32
41
43 protected $mCurrent = false;
44
57 public function __construct(
59 UserIdentity $user,
60 CommentStoreComment $comment,
61 $row,
62 RevisionSlots $slots,
63 $dbDomain = false
64 ) {
65 parent::__construct( $title, $slots, $dbDomain );
66 Assert::parameterType( \stdClass::class, $row, '$row' );
67
68 $this->mId = intval( $row->rev_id );
69 $this->mPageId = intval( $row->rev_page );
70 $this->mComment = $comment;
71
72 $timestamp = MWTimestamp::convert( TS_MW, $row->rev_timestamp );
73 Assert::parameter(
74 is_string( $timestamp ),
75 '$row->rev_timestamp',
76 "must be a valid timestamp (rev_id={$this->mId}, rev_timestamp={$row->rev_timestamp})"
77 );
78
79 $this->mUser = $user;
80 $this->mMinorEdit = boolval( $row->rev_minor_edit );
81 $this->mTimestamp = $timestamp;
82 $this->mDeleted = intval( $row->rev_deleted );
83
84 // NOTE: rev_parent_id = 0 indicates that there is no parent revision, while null
85 // indicates that the parent revision is unknown. As per MW 1.31, the database schema
86 // allows rev_parent_id to be NULL.
87 $this->mParentId = isset( $row->rev_parent_id ) ? intval( $row->rev_parent_id ) : null;
88 $this->mSize = isset( $row->rev_len ) ? intval( $row->rev_len ) : null;
89 $this->mSha1 = !empty( $row->rev_sha1 ) ? $row->rev_sha1 : null;
90
91 // NOTE: we must not call $this->mTitle->getLatestRevID() here, since the state of
92 // page_latest may be in limbo during revision creation. In that case, calling
93 // $this->mTitle->getLatestRevID() would cause a bad value to be cached in the Title
94 // object. During page creation, that bad value would be 0.
95 if ( isset( $row->page_latest ) ) {
96 $this->mCurrent = ( $row->rev_id == $row->page_latest );
97 }
98
99 // sanity check
100 if (
101 $this->mPageId && $this->mTitle->exists()
102 && $this->mPageId !== $this->mTitle->getArticleID()
103 ) {
104 throw new InvalidArgumentException(
105 'The given Title (' . $this->mTitle->getPrefixedText() . ')' .
106 ' does not belong to page ID ' . $this->mPageId .
107 ' but actually belongs to ' . $this->mTitle->getArticleID()
108 );
109 }
110 }
111
115 public function isCurrent() {
116 return $this->mCurrent;
117 }
118
126 public function isDeleted( $field ) {
127 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
128 // Current revisions of pages cannot have the content hidden. Skipping this
129 // check is very useful for Parser as it fetches templates using newKnownCurrent().
130 // Calling getVisibility() in that case triggers a verification database query.
131 return false; // no need to check
132 }
133
134 return parent::isDeleted( $field );
135 }
136
137 protected function userCan( $field, User $user ) {
138 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
139 // Current revisions of pages cannot have the content hidden. Skipping this
140 // check is very useful for Parser as it fetches templates using newKnownCurrent().
141 // Calling getVisibility() in that case triggers a verification database query.
142 return true; // no need to check
143 }
144
145 return parent::userCan( $field, $user );
146 }
147
151 public function getId() {
152 // overwritten just to add a guarantee to the contract
153 return parent::getId();
154 }
155
160 public function getSize() {
161 // If length is null, calculate and remember it (potentially SLOW!).
162 // This is for compatibility with old database rows that don't have the field set.
163 if ( $this->mSize === null ) {
164 $this->mSize = $this->mSlots->computeSize();
165 }
166
167 return $this->mSize;
168 }
169
174 public function getSha1() {
175 // If hash is null, calculate it and remember (potentially SLOW!)
176 // This is for compatibility with old database rows that don't have the field set.
177 if ( $this->mSha1 === null ) {
178 $this->mSha1 = $this->mSlots->computeSha1();
179 }
180
181 return $this->mSha1;
182 }
183
190 public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
191 // overwritten just to add a guarantee to the contract
192 return parent::getUser( $audience, $user );
193 }
194
201 public function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
202 // overwritten just to add a guarantee to the contract
203 return parent::getComment( $audience, $user );
204 }
205
209 public function getTimestamp() {
210 // overwritten just to add a guarantee to the contract
211 return parent::getTimestamp();
212 }
213
219 public function isReadyForInsertion() {
220 return true;
221 }
222
223}
224
229class_alias( RevisionStoreRecord::class, 'MediaWiki\Storage\RevisionStoreRecord' );
CommentStoreComment represents a comment stored by CommentStore.
Library for creating and parsing MW-style timestamps.
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()
Checks whether the revision record is a stored current revision.1.35 bool
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:60
Interface for objects representing user identity.