MediaWiki  1.33.0
RevisionStoreRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
26 use InvalidArgumentException;
28 use Title;
29 use User;
30 use 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 
226 class_alias( RevisionStoreRecord::class, 'MediaWiki\Storage\RevisionStoreRecord' );
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
Revision\RevisionStoreRecord\getSize
getSize()
Definition: RevisionStoreRecord.php:157
Revision\RevisionStoreRecord\__construct
__construct(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiId=false)
Definition: RevisionStoreRecord.php:57
Revision\RevisionStoreRecord\getSha1
getSha1()
Definition: RevisionStoreRecord.php:171
Revision\RevisionStoreRecord\getUser
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Definition: RevisionStoreRecord.php:187
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
Revision\RevisionStoreRecord\isDeleted
isDeleted( $field)
MCR migration note: this replaces Revision::isDeleted.
Definition: RevisionStoreRecord.php:123
User
User
Definition: All_system_messages.txt:425
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\Revision
Created by PhpStorm.
Definition: FallbackSlotRoleHandler.php:23
Revision\RevisionStoreRecord\getId
getId()
Definition: RevisionStoreRecord.php:148
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
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
Revision\RevisionStoreRecord\userCan
userCan( $field, User $user)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: RevisionStoreRecord.php:134
Revision\RevisionStoreRecord\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Definition: RevisionStoreRecord.php:198
Revision\RevisionStoreRecord\isReadyForInsertion
isReadyForInsertion()
Definition: RevisionStoreRecord.php:216
Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:39
Revision\RevisionRecord\$mSize
int null $mSize
Definition: RevisionRecord.php:76
Title
Represents a title within MediaWiki.
Definition: Title.php:40
Revision\RevisionStoreRecord\isCurrent
isCurrent()
MCR migration note: this replaces Revision::isCurrent.
Definition: RevisionStoreRecord.php:112
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:35
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Revision\RevisionStoreRecord\$mCurrent
bool $mCurrent
Definition: RevisionStoreRecord.php:42
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
Revision\RevisionRecord\$mSha1
string null $mSha1
Definition: RevisionRecord.php:78
Revision\RevisionStoreRecord\getTimestamp
getTimestamp()
Definition: RevisionStoreRecord.php:206
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29