MediaWiki  master
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
29 use Title;
30 use User;
43  private $mCallback;
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  }
76  public function getVisibility() {
77  if ( $this->mCallback ) {
78  $this->loadFreshRow();
79  }
80  return parent::getVisibility();
81  }
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  }
103  private function loadFreshRow() {
104  $freshRow = call_user_func( $this->mCallback, $this->mId );
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;
110  if ( $freshRow ) {
111  $this->mDeleted = intval( $freshRow->rev_deleted );
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  }
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.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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:627
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)
Load a fresh row from the database to ensure we return updated information.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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
Exception representing a failure to look up a revision.
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.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454