MediaWiki  master
RevisionStoreCacheRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
29 use Title;
30 use User;
31 
39 
43  private $mCallback;
44 
58  public function __construct(
59  $callback,
60  Title $title,
61  UserIdentity $user,
62  CommentStoreComment $comment,
63  $row,
64  RevisionSlots $slots,
65  $dbDomain = false
66  ) {
67  parent::__construct( $title, $user, $comment, $row, $slots, $dbDomain );
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, User $user = null ) {
92  if ( $this->mCallback ) {
93  $this->loadFreshRow();
94  }
95  return parent::getUser( $audience, $user );
96  }
97 
103  private function loadFreshRow() {
104  $freshRow = 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 ( $freshRow ) {
111  $this->mDeleted = intval( $freshRow->rev_deleted );
112 
113  try {
114  $this->mUser = User::newFromAnyId(
115  $freshRow->rev_user ?? null,
116  $freshRow->rev_user_text ?? null,
117  $freshRow->rev_actor ?? null
118  );
119  } catch ( InvalidArgumentException $ex ) {
120  wfWarn(
121  __METHOD__
122  . ': '
123  . $this->mTitle->getPrefixedDBkey()
124  . ': '
125  . $ex->getMessage()
126  );
127  $this->mUser = new UserIdentityValue( 0, 'Unknown user', 0 );
128  }
129  } else {
130  throw new RevisionAccessException(
131  'Unable to load fresh row for rev_id: ' . $this->mId
132  );
133  }
134  }
135 
136 }
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
A RevisionRecord representing an existing revision persisted in the revision table.
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Overridden to ensure that we return a fresh value and not a cached one.
static newFromAnyId( $userId, $userName, $actorId, $dbDomain=false)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:617
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
Created by PhpStorm.
__construct( $callback, Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $dbDomain=false)
loadFreshRow()
Load a fresh row from the database to ensure we return updated information.
getUser()
Exception representing a failure to look up a revision.
getVisibility()
Overridden to ensure that we return a fresh value and not a cached one.
Value object representing the set of slots belonging to a revision.