MediaWiki 1.42.0
RevisionStoreRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
25use InvalidArgumentException;
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 $pageIdBasedOnPage = $this->getArticleId( $this->mPage );
94 if ( $this->mPageId && $pageIdBasedOnPage && $this->mPageId !== $pageIdBasedOnPage ) {
95 throw new InvalidArgumentException(
96 'The given page (' . $this->mPage . ')' .
97 ' does not belong to page ID ' . $this->mPageId .
98 ' but actually belongs to ' . $this->getArticleId( $this->mPage )
99 );
100 }
101 }
102
106 public function isCurrent() {
107 return $this->mCurrent;
108 }
109
117 public function isDeleted( $field ) {
118 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
119 // Current revisions of pages cannot have the content hidden. Skipping this
120 // check is very useful for Parser as it fetches templates using newKnownCurrent().
121 // Calling getVisibility() in that case triggers a verification database query.
122 return false; // no need to check
123 }
124
125 return parent::isDeleted( $field );
126 }
127
128 public function userCan( $field, Authority $performer ) {
129 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
130 // Current revisions of pages cannot have the content hidden. Skipping this
131 // check is very useful for Parser as it fetches templates using newKnownCurrent().
132 // Calling getVisibility() in that case triggers a verification database query.
133 return true; // no need to check
134 }
135
136 return parent::userCan( $field, $performer );
137 }
138
143 public function getId( $wikiId = self::LOCAL ) {
144 // overwritten just to add a guarantee to the contract
145 return parent::getId( $wikiId );
146 }
147
152 public function getSize() {
153 // If length is null, calculate and remember it (potentially SLOW!).
154 // This is for compatibility with old database rows that don't have the field set.
155 $this->mSize ??= $this->mSlots->computeSize();
156
157 return $this->mSize;
158 }
159
164 public function getSha1() {
165 // If hash is null, calculate it and remember (potentially SLOW!)
166 // This is for compatibility with old database rows that don't have the field set.
167 $this->mSha1 ??= $this->mSlots->computeSha1();
168
169 return $this->mSha1;
170 }
171
178 public function getUser( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
179 // overwritten just to add a guarantee to the contract
180 return parent::getUser( $audience, $performer );
181 }
182
189 public function getComment( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
190 // overwritten just to add a guarantee to the contract
191 return parent::getComment( $audience, $performer );
192 }
193
197 public function getTimestamp() {
198 // overwritten just to add a guarantee to the contract
199 return parent::getTimestamp();
200 }
201
207 public function isReadyForInsertion() {
208 return true;
209 }
210
211}
Value object for a comment stored by CommentStore.
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)
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
Interface for objects representing user identity.