MediaWiki master
ChangeTrackingEventIngress.php
Go to the documentation of this file.
1<?php
2
4
12use RecentChange;
13
21
26 public const EVENTS = [
27 PageUpdatedEvent::TYPE
28 ];
29
37 public const OBJECT_SPEC = [
38 'class' => self::class,
39 'services' => [ // see __construct
40 'ChangeTagsStore',
41 'UserEditTracker'
42 ],
43 'events' => [ // see registerListeners()
44 PageUpdatedEvent::TYPE
45 ],
46 ];
47
48 private ChangeTagsStore $changeTagsStore;
49 private UserEditTracker $userEditTracker;
50
55 public function __construct(
56 ChangeTagsStore $changeTagsStore,
57 UserEditTracker $userEditTracker
58 ) {
59 // NOTE: keep in sync with self::OBJECT_SPEC
60 $this->changeTagsStore = $changeTagsStore;
61 $this->userEditTracker = $userEditTracker;
62 }
63
64 public static function newForTesting(
65 ChangeTagsStore $changeTagsStore,
66 UserEditTracker $userEditTracker
67 ) {
68 $ingress = new self( $changeTagsStore, $userEditTracker );
69 $ingress->initSubscriber( self::OBJECT_SPEC );
70 return $ingress;
71 }
72
80 if ( $event->isRevisionChange()
81 && !$event->hasFlag( PageUpdatedEvent::FLAG_SILENT )
82 ) {
83 $this->updateRecentChangesAfterPageUpdated(
84 $event->getNewRevision(),
85 $event->getOldRevision(),
86 $event->hasFlag( PageUpdatedEvent::FLAG_BOT ),
87 $event->getPatrolStatus(),
88 $event->getTags(),
89 $event->getEditResult()
90 );
91 } elseif ( $event->getTags() ) {
92 $this->updateChangeTagsAfterPageUpdated(
93 $event->getTags(),
94 $event->getNewRevision()->getId(),
95 );
96 }
97
98 if ( $event->isContentChange()
99 && !$event->hasFlag( PageUpdatedEvent::FLAG_AUTOMATED )
100 ) {
101 $this->updateUserEditTrackerAfterPageUpdated(
102 $event->getAuthor()
103 );
104 }
105 }
106
107 private function updateChangeTagsAfterPageUpdated( array $tags, int $revId ) {
108 $this->changeTagsStore->addTags( $tags, null, $revId );
109 }
110
111 private function updateRecentChangesAfterPageUpdated(
112 RevisionRecord $newRevisionRecord,
113 ?RevisionRecord $oldRevisionRecord,
114 bool $forceBot,
115 int $patrolStatus,
116 array $tags,
117 ?EditResult $editResult
118 ) {
119 // Update recentchanges
120 if ( !$oldRevisionRecord ) {
121 RecentChange::notifyNew(
122 $newRevisionRecord->getTimestamp(),
123 $newRevisionRecord->getPage(),
124 $newRevisionRecord->isMinor(),
125 $newRevisionRecord->getUser( RevisionRecord::RAW ),
126 $newRevisionRecord->getComment( RevisionRecord::RAW )->text,
127 $forceBot, // $event->hasFlag( EDIT_FORCE_BOT ),
128 '',
129 $newRevisionRecord->getSize(),
130 $newRevisionRecord->getId(),
131 $patrolStatus,
132 $tags
133 );
134 } else {
135 // Add RC row to the DB
136 RecentChange::notifyEdit(
137 $newRevisionRecord->getTimestamp(),
138 $newRevisionRecord->getPage(),
139 $newRevisionRecord->isMinor(),
140 $newRevisionRecord->getUser( RevisionRecord::RAW ),
141 $newRevisionRecord->getComment( RevisionRecord::RAW )->text,
142 $oldRevisionRecord->getId(),
143 $newRevisionRecord->getTimestamp(),
144 $forceBot,
145 '',
146 $oldRevisionRecord->getSize(),
147 $newRevisionRecord->getSize(),
148 $newRevisionRecord->getId(),
149 $patrolStatus,
150 $tags,
151 $editResult
152 );
153 }
154 }
155
156 private function updateUserEditTrackerAfterPageUpdated( UserIdentity $author ) {
157 $this->userEditTracker->incrementUserEditCount( $author );
158 }
159
160}
Read-write access to the change_tags table.
Base class for classes that implement DomainEventSubscriber.
The ingress subscriber for the change tracking component.
const OBJECT_SPEC
Object spec used for lazy instantiation.
static newForTesting(ChangeTagsStore $changeTagsStore, UserEditTracker $userEditTracker)
const EVENTS
The events handled by this ingress subscriber.
handlePageUpdatedEventAfterCommit(PageUpdatedEvent $event)
Listener method for PageUpdatedEvent, to be registered with an DomainEventSource.
__construct(ChangeTagsStore $changeTagsStore, UserEditTracker $userEditTracker)
Page revision base class.
Object for storing information about the effects of an edit.
Domain event representing a page edit.
hasFlag(string $name)
Checks flags describing the page update.
getOldRevision()
Returned the revision that used to be current before the edit.
getNewRevision()
The revision that became the current one because of the edit.
getAuthor()
Returns the user that performed the edit.
getPatrolStatus()
Returns the edit's initial patrol status.
getEditResult()
An EditResult representing the effects of an edit.
isContentChange()
Whether the update changed the content of the page.
isRevisionChange()
Whether this is an actual revision change, as opposed to a "null-edit" or purge.
getTags()
Returns any tags applied to the edit.
Track info about user edit counts and timings.
Utility class for creating and reading rows in the recentchanges table.
Interface for objects representing user identity.