MediaWiki  1.33.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 
59  function __construct(
60  $callback,
61  Title $title,
62  UserIdentity $user,
63  CommentStoreComment $comment,
64  $row,
65  RevisionSlots $slots,
66  $wikiId = false
67  ) {
68  parent::__construct( $title, $user, $comment, $row, $slots, $wikiId );
69  $this->mCallback = $callback;
70  }
71 
77  public function getVisibility() {
78  if ( $this->mCallback ) {
79  $this->loadFreshRow();
80  }
81  return parent::getVisibility();
82  }
83 
92  public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
93  if ( $this->mCallback ) {
94  $this->loadFreshRow();
95  }
96  return parent::getUser( $audience, $user );
97  }
98 
104  private function loadFreshRow() {
105  $freshRow = call_user_func( $this->mCallback, $this->mId );
106 
107  // Set to null to ensure we do not make unnecessary queries for subsequent getter calls,
108  // and to allow the closure to be freed.
109  $this->mCallback = null;
110 
111  if ( $freshRow ) {
112  $this->mDeleted = intval( $freshRow->rev_deleted );
113 
114  try {
115  $this->mUser = User::newFromAnyId(
116  $freshRow->rev_user ?? null,
117  $freshRow->rev_user_text ?? null,
118  $freshRow->rev_actor ?? null
119  );
120  } catch ( InvalidArgumentException $ex ) {
121  wfWarn(
122  __METHOD__
123  . ': '
124  . $this->mTitle->getPrefixedDBkey()
125  . ': '
126  . $ex->getMessage()
127  );
128  $this->mUser = new UserIdentityValue( 0, 'Unknown user', 0 );
129  }
130  } else {
131  throw new RevisionAccessException(
132  'Unable to load fresh row for rev_id: ' . $this->mId
133  );
134  }
135  }
136 
137 }
MediaWiki\User\UserIdentityValue
Value object representing a user's identity.
Definition: UserIdentityValue.php:32
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
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:92
Revision\RevisionStoreCacheRecord
A cached RevisionStoreRecord.
Definition: RevisionStoreCacheRecord.php:38
User\newFromAnyId
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:676
User
User
Definition: All_system_messages.txt:425
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
php
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
MediaWiki\Revision
Created by PhpStorm.
Definition: FallbackSlotRoleHandler.php:23
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
Revision\RevisionStoreCacheRecord\getVisibility
getVisibility()
Overridden to ensure that we return a fresh value and not a cached one.
Definition: RevisionStoreCacheRecord.php:77
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:39
Revision\RevisionStoreCacheRecord\__construct
__construct( $callback, Title $title, UserIdentity $user, CommentStoreComment $comment, $row, RevisionSlots $slots, $wikiId=false)
Definition: RevisionStoreCacheRecord.php:59
Title
Represents a title within MediaWiki.
Definition: Title.php:40
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:1092
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
Revision\RevisionStoreCacheRecord\loadFreshRow
loadFreshRow()
Load a fresh row from the database to ensure we return updated information.
Definition: RevisionStoreCacheRecord.php:104
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29