MediaWiki  1.34.0
RevisionStoreCacheRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
28 use InvalidArgumentException;
29 use Title;
30 use User;
31 
39 
43  private $mCallback;
44 
58  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 }
MediaWiki\User\UserIdentityValue
Value object representing a user's identity.
Definition: UserIdentityValue.php:32
Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:33
Revision\RevisionStoreCacheRecord\getUser
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Overridden to ensure that we return a fresh value and not a cached one.
Definition: RevisionStoreCacheRecord.php:91
Revision\RevisionStoreCacheRecord
A cached RevisionStoreRecord.
Definition: RevisionStoreCacheRecord.php:38
getUser
getUser()
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
MediaWiki\Revision
Created by PhpStorm.
Definition: FallbackSlotRoleHandler.php:23
Revision\RevisionStoreCacheRecord\__construct
__construct( $callback, Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $dbDomain=false)
Definition: RevisionStoreCacheRecord.php:58
Revision\RevisionStoreCacheRecord\getVisibility
getVisibility()
Overridden to ensure that we return a fresh value and not a cached one.
Definition: RevisionStoreCacheRecord.php:76
$title
$title
Definition: testCompression.php:34
User\newFromAnyId
static newFromAnyId( $userId, $userName, $actorId, $dbDomain=false)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:596
Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:39
Title
Represents a title within MediaWiki.
Definition: Title.php:42
Revision\RevisionStoreCacheRecord\$mCallback
callable $mCallback
Definition: RevisionStoreCacheRecord.php:43
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:35
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1065
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
Revision\RevisionStoreCacheRecord\loadFreshRow
loadFreshRow()
Load a fresh row from the database to ensure we return updated information.
Definition: RevisionStoreCacheRecord.php:103
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29