44 PageLatestRevisionChangedEvent::TYPE
55 'class' => self::class,
63 'TalkPageNotificationManager',
66 'ContentHandlerFactory',
67 'RecentChangeFactory',
70 PageLatestRevisionChangedEvent::TYPE
84 private bool $useRcPatrol;
85 private bool $rcWatchCategoryMembership;
101 $this->changeTagsStore = $changeTagsStore;
102 $this->userEditTracker = $userEditTracker;
103 $this->permissionManager = $permissionManager;
104 $this->wikiPageFactory = $wikiPageFactory;
105 $this->hookRunner =
new HookRunner( $hookContainer );
106 $this->userNameUtils = $userNameUtils;
107 $this->talkPageNotificationManager = $talkPageNotificationManager;
108 $this->jobQueueGroup = $jobQueueGroup;
109 $this->contentHandlerFactory = $contentHandlerFactory;
110 $this->recentChangeFactory = $recentChangeFactory;
113 $this->rcWatchCategoryMembership = $mainConfig->
get(
138 $talkPageNotificationManager,
141 $contentHandlerFactory,
144 $ingress->initSubscriber( self::OBJECT_SPEC );
166 if ( $event->changedLatestRevisionId()
167 && !$event->isSilent()
169 $this->updateRecentChangesAfterPageUpdated(
177 } elseif ( $event->
getTags() ) {
178 $this->updateChangeTagsAfterPageUpdated(
185 $this->generateCategoryMembershipChanges( $event );
188 $this->updateUserEditTrackerAfterPageUpdated(
192 $this->updateNewTalkAfterPageUpdated( $event );
197 $this->updateRevertTagAfterPageUpdated( $event );
208 private function generateCategoryMembershipChanges( PageLatestRevisionChangedEvent $event ): void {
209 if ( $this->rcWatchCategoryMembership
210 && !$event->hasCause( PageLatestRevisionChangedEvent::CAUSE_UNDELETE )
211 && $this->anyChangedSlotSupportsCategories( $event )
216 $this->jobQueueGroup->lazyPush(
217 CategoryMembershipChangeJob::newSpec(
219 $event->getLatestRevisionAfter()->getTimestamp(),
220 $event->hasCause( PageLatestRevisionChangedEvent::CAUSE_IMPORT )
233 private function anyChangedSlotSupportsCategories( PageLatestRevisionChangedEvent $event ): bool {
234 $slotsUpdate = $event->getSlotsUpdate();
235 foreach ( $slotsUpdate->getModifiedRoles() as $role ) {
236 $model = $slotsUpdate->getModifiedSlot( $role )->getModel();
238 if ( $this->contentHandlerFactory->getContentHandler( $model )->supportsCategories() ) {
246 private function updateChangeTagsAfterPageUpdated( array $tags,
int $revId ) {
247 $this->changeTagsStore->addTags( $tags,
null, $revId );
250 private function updateRecentChangesAfterPageUpdated(
251 RevisionRecord $newRevisionRecord,
252 ?RevisionRecord $oldRevisionRecord,
256 ?EditResult $editResult
258 if ( !$oldRevisionRecord ) {
259 $recentChange = $this->recentChangeFactory->createNewPageRecentChange(
260 $newRevisionRecord->getTimestamp(),
261 $newRevisionRecord->getPage(),
262 $newRevisionRecord->isMinor(),
263 $newRevisionRecord->getUser( RevisionRecord::RAW ),
264 $newRevisionRecord->getComment( RevisionRecord::RAW )->text,
267 $newRevisionRecord->getSize(),
268 $newRevisionRecord->getId(),
273 $recentChange = $this->recentChangeFactory->createEditRecentChange(
274 $newRevisionRecord->getTimestamp(),
275 $newRevisionRecord->getPage(),
276 $newRevisionRecord->isMinor(),
277 $newRevisionRecord->getUser( RevisionRecord::RAW ),
278 $newRevisionRecord->getComment( RevisionRecord::RAW )->text,
279 $oldRevisionRecord->getId(),
282 $oldRevisionRecord->getSize(),
283 $newRevisionRecord->getSize(),
284 $newRevisionRecord->getId(),
291 $this->recentChangeFactory->insertRecentChange( $recentChange );
294 private function updateUserEditTrackerAfterPageUpdated( UserIdentity $author ) {
295 $this->userEditTracker->incrementUserEditCount( $author );
303 private function updateNewTalkAfterPageUpdated( PageLatestRevisionChangedEvent $event ) {
307 $page = $event->getPage();
308 $revRecord = $event->getLatestRevisionAfter();
309 $recipientName = $page->getDBkey();
310 $recipientName = $this->userNameUtils->isIP( $recipientName )
312 : $this->userNameUtils->getCanonical( $page->getDBkey() );
315 && !( $revRecord->isMinor()
316 && $this->permissionManager->userHasRight(
317 $event->getAuthor(),
'nominornewtalk' ) )
318 && $recipientName != $event->getAuthor()->getName()
320 $recipient = User::newFromName( $recipientName,
false );
322 wfDebug( __METHOD__ .
": invalid username" );
324 $wikiPage = $this->wikiPageFactory->newFromTitle( $page );
328 if ( $this->hookRunner->onArticleEditUpdateNewTalk( $wikiPage, $recipient ) ) {
329 if ( $this->userNameUtils->isIP( $recipientName ) ) {
331 $this->talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord );
332 } elseif ( $recipient->isRegistered() ) {
333 $this->talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord );
335 wfDebug( __METHOD__ .
": don't need to notify a nonexistent user" );
342 private function updateRevertTagAfterPageUpdated( PageLatestRevisionChangedEvent $event ) {
343 $patrolStatus = $event->getPatrolStatus();
344 $wikiPage = $this->wikiPageFactory->newFromTitle( $event->getPage() );
349 $approved = !$this->useRcPatrol ||
350 $patrolStatus === RecentChange::PRC_PATROLLED ||
351 $patrolStatus === RecentChange::PRC_AUTOPATROLLED;
353 $editResult = $event->getEditResult();
355 if ( !$editResult ) {
357 throw new LogicException(
'Missing EditResult in revert' );
360 $revisionRecord = $event->getLatestRevisionAfter();
363 $this->hookRunner->onBeforeRevertedTagUpdate(
366 $revisionRecord->getComment( RevisionRecord::RAW ),
367 self::getEditFlags( $event ),
376 $this->jobQueueGroup->lazyPush(
377 RevertedTagUpdateJob::newSpec(
378 $revisionRecord->getId(),