MediaWiki REL1_32
RevisionStoreRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
26use InvalidArgumentException;
29use User;
30use Wikimedia\Assert\Assert;
31
40
42 protected $mCurrent = false;
43
57 function __construct(
58 Title $title,
59 UserIdentity $user,
60 CommentStoreComment $comment,
61 $row,
62 RevisionSlots $slots,
63 $wikiId = false
64 ) {
65 parent::__construct( $title, $slots, $wikiId );
66 Assert::parameterType( 'object', $row, '$row' );
67
68 $this->mId = intval( $row->rev_id );
69 $this->mPageId = intval( $row->rev_page );
70 $this->mComment = $comment;
71
72 $timestamp = wfTimestamp( TS_MW, $row->rev_timestamp );
73 Assert::parameter( is_string( $timestamp ), '$row->rev_timestamp', 'must be a valid timestamp' );
74
75 $this->mUser = $user;
76 $this->mMinorEdit = boolval( $row->rev_minor_edit );
77 $this->mTimestamp = $timestamp;
78 $this->mDeleted = intval( $row->rev_deleted );
79
80 // NOTE: rev_parent_id = 0 indicates that there is no parent revision, while null
81 // indicates that the parent revision is unknown. As per MW 1.31, the database schema
82 // allows rev_parent_id to be NULL.
83 $this->mParentId = isset( $row->rev_parent_id ) ? intval( $row->rev_parent_id ) : null;
84 $this->mSize = isset( $row->rev_len ) ? intval( $row->rev_len ) : null;
85 $this->mSha1 = !empty( $row->rev_sha1 ) ? $row->rev_sha1 : null;
86
87 // NOTE: we must not call $this->mTitle->getLatestRevID() here, since the state of
88 // page_latest may be in limbo during revision creation. In that case, calling
89 // $this->mTitle->getLatestRevID() would cause a bad value to be cached in the Title
90 // object. During page creation, that bad value would be 0.
91 if ( isset( $row->page_latest ) ) {
92 $this->mCurrent = ( $row->rev_id == $row->page_latest );
93 }
94
95 // sanity check
96 if (
97 $this->mPageId && $this->mTitle->exists()
98 && $this->mPageId !== $this->mTitle->getArticleID()
99 ) {
100 throw new InvalidArgumentException(
101 'The given Title does not belong to page ID ' . $this->mPageId .
102 ' but actually belongs to ' . $this->mTitle->getArticleID()
103 );
104 }
105 }
106
112 public function isCurrent() {
113 return $this->mCurrent;
114 }
115
123 public function isDeleted( $field ) {
124 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
125 // Current revisions of pages cannot have the content hidden. Skipping this
126 // check is very useful for Parser as it fetches templates using newKnownCurrent().
127 // Calling getVisibility() in that case triggers a verification database query.
128 return false; // no need to check
129 }
130
131 return parent::isDeleted( $field );
132 }
133
134 protected function userCan( $field, User $user ) {
135 if ( $this->isCurrent() && $field === self::DELETED_TEXT ) {
136 // Current revisions of pages cannot have the content hidden. Skipping this
137 // check is very useful for Parser as it fetches templates using newKnownCurrent().
138 // Calling getVisibility() in that case triggers a verification database query.
139 return true; // no need to check
140 }
141
142 return parent::userCan( $field, $user );
143 }
144
148 public function getId() {
149 // overwritten just to add a guarantee to the contract
150 return parent::getId();
151 }
152
157 public function getSize() {
158 // If length is null, calculate and remember it (potentially SLOW!).
159 // This is for compatibility with old database rows that don't have the field set.
160 if ( $this->mSize === null ) {
161 $this->mSize = $this->mSlots->computeSize();
162 }
163
164 return $this->mSize;
165 }
166
171 public function getSha1() {
172 // If hash is null, calculate it and remember (potentially SLOW!)
173 // This is for compatibility with old database rows that don't have the field set.
174 if ( $this->mSha1 === null ) {
175 $this->mSha1 = $this->mSlots->computeSha1();
176 }
177
178 return $this->mSha1;
179 }
180
187 public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
188 // overwritten just to add a guarantee to the contract
189 return parent::getUser( $audience, $user );
190 }
191
198 public function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
199 // overwritten just to add a guarantee to the contract
200 return parent::getComment( $audience, $user );
201 }
202
206 public function getTimestamp() {
207 // overwritten just to add a guarantee to the contract
208 return parent::getTimestamp();
209 }
210
216 public function isReadyForInsertion() {
217 return true;
218 }
219
220}
221
226class_alias( RevisionStoreRecord::class, 'MediaWiki\Storage\RevisionStoreRecord' );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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)
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.
__construct(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiId=false)
Represents a title within MediaWiki.
Definition Title.php:39
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:47
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:994
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Interface for objects representing user identity.