MediaWiki REL1_35
RevisionStoreCacheRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
26use InvalidArgumentException;
29use Title;
30use User;
31
39
43 private $mCallback;
44
58 public function __construct(
59 $callback,
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.
CommentStoreComment represents a comment stored by CommentStore.
Exception representing a failure to look up a revision.
Value object representing the set of slots belonging to a revision.
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Overridden to ensure that we return a fresh value and not a cached one.
loadFreshRow()
Load a fresh row from the database to ensure we return updated information.
__construct( $callback, Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $dbDomain=false)
getVisibility()
Overridden to ensure that we return a fresh value and not a cached one.
A RevisionRecord representing an existing revision persisted in the revision table.
Value object representing a user's identity.
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
static newFromAnyId( $userId, $userName, $actorId, $dbDomain=false)
Static factory method for creation from an ID, name, and/or actor ID.
Definition User.php:616
Interface for objects representing user identity.