MediaWiki  master
RevisionStoreRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
28 use Title;
29 use User;
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' );
__construct(Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiId=false)
A RevisionRecord representing an existing revision persisted in the revision table.
isDeleted( $field)
MCR migration note: this replaces Revision::isDeleted.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getUser( $audience=self::FOR_PUBLIC, User $user=null)
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:50
Created by PhpStorm.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
isCurrent()
MCR migration note: this replaces Revision::isCurrent.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
getComment( $audience=self::FOR_PUBLIC, User $user=null)
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
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
Page revision base class.
Value object representing the set of slots belonging to a revision.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473