7use InvalidArgumentException;
12use Wikimedia\Timestamp\ConvertibleTimestamp;
23 private const FIRST_EDIT = 1;
24 private const LATEST_EDIT = 2;
27 private $actorMigration;
30 private $loadBalancer;
33 private $jobQueueGroup;
41 private $userEditCountCache = [];
53 $this->actorMigration = $actorMigration;
54 $this->loadBalancer = $loadBalancer;
55 $this->jobQueueGroup = $jobQueueGroup;
65 if ( !$user->isRegistered() ) {
69 $userId = $user->
getId();
70 $cacheKey =
'u' . (string)$userId;
72 if ( isset( $this->userEditCountCache[ $cacheKey ] ) ) {
73 return $this->userEditCountCache[ $cacheKey ];
77 $count =
$dbr->selectField(
80 [
'user_id' => $userId ],
84 if ( $count ===
null ) {
89 $this->userEditCountCache[ $cacheKey ] = $count;
100 $actorWhere = $this->actorMigration->getWhere(
$dbr,
'rev_user', $user );
102 $count = (int)
$dbr->selectField(
103 [
'revision' ] + $actorWhere[
'tables'],
105 [ $actorWhere[
'conds'] ],
113 'userId' => $user->
getId(),
114 'editCount' => $count,
132 DeferredUpdates::addUpdate(
134 DeferredUpdates::POSTSEND
146 return $this->getUserEditTimestamp( $user, self::FIRST_EDIT );
157 return $this->getUserEditTimestamp( $user, self::LATEST_EDIT );
173 $actorWhere = $this->actorMigration->getWhere(
$dbr,
'rev_user', $user );
175 $sortOrder = (
$type === self::FIRST_EDIT ) ?
'ASC' :
'DESC';
176 $time =
$dbr->selectField(
177 [
'revision' ] + $actorWhere[
'tables'],
179 [ $actorWhere[
'conds'] ],
181 [
'ORDER BY' =>
"rev_timestamp $sortOrder" ],
189 return ConvertibleTimestamp::convert( TS_MW, $time );
201 $userId = $user->
getId();
202 $cacheKey =
'u' . (string)$userId;
204 unset( $this->userEditCountCache[ $cacheKey ] );
215 throw new InvalidArgumentException( __METHOD__ .
' with an anonymous user' );
218 $userId = $user->
getId();
219 $cacheKey =
'u' . (string)$userId;
221 $this->userEditCountCache[ $cacheKey ] = $editCount;
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
Class for managing the deferral of updates within the scope of a PHP script invocation.
Class to handle enqueueing of background jobs.
Job that initializes an user's edit count if it's not yet set or the current value is outdated.
Handles increment the edit count for a given set of users.