MediaWiki REL1_37
RevisionStoreRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
26use InvalidArgumentException;
30use MWTimestamp;
31
40
42 protected $mCurrent = false;
43
56 public function __construct(
57 PageIdentity $page,
58 UserIdentity $user,
59 CommentStoreComment $comment,
60 \stdClass $row,
61 RevisionSlots $slots,
62 $wikiId = self::LOCAL
63 ) {
64 parent::__construct( $page, $slots, $wikiId );
65 $this->mId = intval( $row->rev_id );
66 $this->mPageId = intval( $row->rev_page );
67 $this->mComment = $comment;
68
69 // Don't use MWTimestamp::convert, instead let any detailed exception from MWTimestamp
70 // bubble up (T254210)
71 $timestamp = ( new MWTimestamp( $row->rev_timestamp ) )->getTimestamp( TS_MW );
72
73 $this->mUser = $user;
74 $this->mMinorEdit = boolval( $row->rev_minor_edit );
75 $this->mTimestamp = $timestamp;
76 $this->mDeleted = intval( $row->rev_deleted );
77
78 // NOTE: rev_parent_id = 0 indicates that there is no parent revision, while null
79 // indicates that the parent revision is unknown. As per MW 1.31, the database schema
80 // allows rev_parent_id to be NULL.
81 $this->mParentId = isset( $row->rev_parent_id ) ? intval( $row->rev_parent_id ) : null;
82 $this->mSize = isset( $row->rev_len ) ? intval( $row->rev_len ) : null;
83 $this->mSha1 = !empty( $row->rev_sha1 ) ? $row->rev_sha1 : null;
84
85 // NOTE: we must not call $this->mTitle->getLatestRevID() here, since the state of
86 // page_latest may be in limbo during revision creation. In that case, calling
87 // $this->mTitle->getLatestRevID() would cause a bad value to be cached in the Title
88 // object. During page creation, that bad value would be 0.
89 if ( isset( $row->page_latest ) ) {
90 $this->mCurrent = ( $row->rev_id == $row->page_latest );
91 }
92
93 // sanity check
94 $pageIdBasedOnPage = $this->getArticleId( $this->mPage );
95 if ( $this->mPageId && $pageIdBasedOnPage && $this->mPageId !== $pageIdBasedOnPage ) {
96 throw new InvalidArgumentException(
97 'The given page (' . $this->mPage . ')' .
98 ' does not belong to page ID ' . $this->mPageId .
99 ' but actually belongs to ' . $this->getArticleId( $this->mPage )
100 );
101 }
102 }
103
107 public function isCurrent() {
108 return $this->mCurrent;
109 }
110
118 public function isDeleted( $field ) {
119 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
120 // Current revisions of pages cannot have the content hidden. Skipping this
121 // check is very useful for Parser as it fetches templates using newKnownCurrent().
122 // Calling getVisibility() in that case triggers a verification database query.
123 return false; // no need to check
124 }
125
126 return parent::isDeleted( $field );
127 }
128
129 public function userCan( $field, Authority $performer ) {
130 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
131 // Current revisions of pages cannot have the content hidden. Skipping this
132 // check is very useful for Parser as it fetches templates using newKnownCurrent().
133 // Calling getVisibility() in that case triggers a verification database query.
134 return true; // no need to check
135 }
136
137 return parent::userCan( $field, $performer );
138 }
139
144 public function getId( $wikiId = self::LOCAL ) {
145 // overwritten just to add a guarantee to the contract
146 return parent::getId( $wikiId );
147 }
148
153 public function getSize() {
154 // If length is null, calculate and remember it (potentially SLOW!).
155 // This is for compatibility with old database rows that don't have the field set.
156 if ( $this->mSize === null ) {
157 $this->mSize = $this->mSlots->computeSize();
158 }
159
160 return $this->mSize;
161 }
162
167 public function getSha1() {
168 // If hash is null, calculate it and remember (potentially SLOW!)
169 // This is for compatibility with old database rows that don't have the field set.
170 if ( $this->mSha1 === null ) {
171 $this->mSha1 = $this->mSlots->computeSha1();
172 }
173
174 return $this->mSha1;
175 }
176
183 public function getUser( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
184 // overwritten just to add a guarantee to the contract
185 return parent::getUser( $audience, $performer );
186 }
187
194 public function getComment( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
195 // overwritten just to add a guarantee to the contract
196 return parent::getComment( $audience, $performer );
197 }
198
202 public function getTimestamp() {
203 // overwritten just to add a guarantee to the contract
204 return parent::getTimestamp();
205 }
206
212 public function isReadyForInsertion() {
213 return true;
214 }
215
216}
217
222class_alias( RevisionStoreRecord::class, 'MediaWiki\Storage\RevisionStoreRecord' );
Value object for a comment stored by CommentStore.
Library for creating and parsing MW-style timestamps.
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.
A RevisionRecord representing an existing revision persisted in the revision table.
isDeleted( $field)
MCR migration note: this replaced Revision::isDeleted.
userCan( $field, Authority $performer)
Determine if the give authority is allowed to view a particular field of this revision,...
isCurrent()
Checks whether the revision record is a stored current revision.1.35 bool
__construct(PageIdentity $page, UserIdentity $user, CommentStoreComment $comment, \stdClass $row, RevisionSlots $slots, $wikiId=self::LOCAL)
getComment( $audience=self::FOR_PUBLIC, Authority $performer=null)
getUser( $audience=self::FOR_PUBLIC, Authority $performer=null)
Interface for objects (potentially) representing an editable wiki page.
This interface represents the authority associated the current execution context, such as a web reque...
Definition Authority.php:37
Interface for objects representing user identity.