MediaWiki  master
RevisionStoreCacheRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
29 
38 
42  private $mCallback;
43 
58  public function __construct(
59  callable $callback,
60  PageIdentity $page,
61  UserIdentity $user,
62  CommentStoreComment $comment,
63  $row,
64  RevisionSlots $slots,
65  $wikiID = self::LOCAL
66  ) {
67  parent::__construct( $page, $user, $comment, $row, $slots, $wikiID );
68  $this->mCallback = $callback;
69  }
70 
76  public function getVisibility() {
77  if ( $this->mCallback ) {
78  $this->loadFreshRow();
79  }
80  return parent::getVisibility();
81  }
82 
91  public function getUser( $audience = self::FOR_PUBLIC, Authority $performer = null ) {
92  if ( $this->mCallback ) {
93  $this->loadFreshRow();
94  }
95  return parent::getUser( $audience, $performer );
96  }
97 
103  private function loadFreshRow() {
104  list( $freshRevDeleted, $freshUser ) = call_user_func( $this->mCallback, $this->mId );
105 
106  // Set to null to ensure we do not make unnecessary queries for subsequent getter calls,
107  // and to allow the closure to be freed.
108  $this->mCallback = null;
109 
110  if ( $freshRevDeleted !== null && $freshUser !== null ) {
111  $this->mDeleted = intval( $freshRevDeleted );
112  $this->mUser = $freshUser;
113  } else {
114  throw new RevisionAccessException(
115  'Unable to load fresh row for rev_id: ' . $this->mId
116  );
117  }
118  }
119 
120 }
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:65
Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:34
Revision\RevisionStoreCacheRecord
A cached RevisionStoreRecord.
Definition: RevisionStoreCacheRecord.php:37
Revision\RevisionStoreCacheRecord\getUser
getUser( $audience=self::FOR_PUBLIC, Authority $performer=null)
Overridden to ensure that we return a fresh value and not a cached one.
Definition: RevisionStoreCacheRecord.php:91
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\Revision
Definition: ContributionsLookup.php:3
Revision\RevisionStoreCacheRecord\getVisibility
getVisibility()
Overridden to ensure that we return a fresh value and not a cached one.
Definition: RevisionStoreCacheRecord.php:76
Revision\RevisionStoreCacheRecord\__construct
__construct(callable $callback, PageIdentity $page, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiID=self::LOCAL)
Definition: RevisionStoreCacheRecord.php:58
MediaWiki\Permissions\Authority
Definition: Authority.php:30
Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:40
Revision\RevisionStoreCacheRecord\$mCallback
callable $mCallback
( int $revId ): [ int $rev_deleted, UserIdentity $user ]
Definition: RevisionStoreCacheRecord.php:42
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:41
Revision\RevisionStoreCacheRecord\loadFreshRow
loadFreshRow()
Load a fresh row from the database to ensure we return updated information.
Definition: RevisionStoreCacheRecord.php:103
CommentStoreComment
Value object for a comment stored by CommentStore.
Definition: CommentStoreComment.php:30