MediaWiki  1.31.0
RevisionStoreRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Storage;
24 
26 use InvalidArgumentException;
28 use Title;
29 use User;
30 use Wikimedia\Assert\Assert;
31 
39 
41  protected $mCurrent = false;
42 
56  function __construct(
57  Title $title,
59  CommentStoreComment $comment,
60  $row,
61  RevisionSlots $slots,
62  $wikiId = false
63  ) {
64  parent::__construct( $title, $slots, $wikiId );
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 
210 }
MediaWiki\Storage\RevisionStoreRecord\isDeleted
isDeleted( $field)
MCR migration note: this replaces Revision::isDeleted.
Definition: RevisionStoreRecord.php:122
$user
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 account $user
Definition: hooks.txt:244
MediaWiki\Storage\RevisionStoreRecord\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Definition: RevisionStoreRecord.php:197
MediaWiki\Storage\RevisionStoreRecord\getSize
getSize()
Definition: RevisionStoreRecord.php:156
MediaWiki\Storage\RevisionRecord\$mSha1
string null $mSha1
Definition: RevisionRecord.php:76
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1968
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Storage\RevisionStoreRecord\isCurrent
isCurrent()
MCR migration note: this replaces Revision::isCurrent.
Definition: RevisionStoreRecord.php:111
User
User
Definition: All_system_messages.txt:425
MediaWiki\Storage\RevisionStoreRecord\getSha1
getSha1()
Definition: RevisionStoreRecord.php:170
MediaWiki\Storage\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:34
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
php
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:35
MediaWiki\Storage\RevisionStoreRecord\userCan
userCan( $field, User $user)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: RevisionStoreRecord.php:133
MediaWiki\Storage\RevisionStoreRecord\getId
getId()
Definition: RevisionStoreRecord.php:147
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
MediaWiki\Storage\RevisionStoreRecord\__construct
__construct(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiId=false)
Definition: RevisionStoreRecord.php:56
MediaWiki\Storage\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:38
MediaWiki\Storage\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:44
MediaWiki\Storage\RevisionRecord\$mSize
int null $mSize
Definition: RevisionRecord.php:74
MediaWiki\Storage\RevisionStoreRecord\$mCurrent
bool $mCurrent
Definition: RevisionStoreRecord.php:41
MediaWiki\Storage\RevisionStoreRecord\getTimestamp
getTimestamp()
Definition: RevisionStoreRecord.php:205
MediaWiki\Storage
Definition: BlobAccessException.php:23
MediaWiki\Storage\RevisionStoreRecord\getUser
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Definition: RevisionStoreRecord.php:186
Title
Represents a title within MediaWiki.
Definition: Title.php:39
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:28