87 $mwServices = MediaWikiServices::getInstance();
88 $config = $mwServices->getMainConfig();
90 $minorEdit = $recentChange->getAttribute(
'rc_minor' );
91 $editor = $mwServices->getUserFactory()
92 ->newFromUserIdentity( $recentChange->getPerformerIdentity() );
94 $title = Title::castFromPageReference( $recentChange->getPage() );
95 if ( $title ===
null || $title->getNamespace() < 0 ) {
101 if ( $config->get( MainConfigNames::EnotifWatchlist ) || $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
102 $watchers = $mwServices->getWatchedItemStore()->updateNotificationTimestamp(
105 $recentChange->getAttribute(
'rc_timestamp' )
110 if ( $editor->isBot() ) {
114 $sendNotification =
true;
119 if ( $watchers === [] &&
120 !count( $config->get( MainConfigNames::UsersNotifiedOnAllChanges ) )
122 $sendNotification =
false;
125 ( $config->get( MainConfigNames::EnotifMinorEdits ) &&
126 !$editor->isAllowed(
'nominornewtalk' ) )
128 if ( $config->get( MainConfigNames::EnotifUserTalk )
130 && $this->canSendUserTalkEmail( $editor, $title, $minorEdit )
132 $sendNotification =
true;
137 if ( $sendNotification ) {
141 'editor' => $editor->
getName(),
142 'editorID' => $editor->
getId(),
143 'watchers' => $watchers,
144 'pageStatus' => $recentChange->mExtra[
'pageStatus'] ??
'changed',
145 'rc_id' => $recentChange->getAttribute(
'rc_id' ),
150 return $sendNotification;
172 $pageStatus =
'changed'
174 # we use $wgPasswordSender as sender's address
175 $mwServices = MediaWikiServices::getInstance();
176 $config = $mwServices->getMainConfig();
177 $notifService = $mwServices->getNotificationService();
178 $userFactory = $mwServices->getUserFactory();
179 $hookRunner =
new HookRunner( $mwServices->getHookContainer() );
182 # The following code is only run, if several conditions are met:
183 # 1. EmailNotification for pages (other than user_talk pages) must be enabled
184 # 2. minor edits (changes) are only regarded if the global flag indicates so
185 $this->pageStatus = $pageStatus;
186 $formattedPageStatus = [
'deleted',
'created',
'moved',
'restored',
'changed' ];
188 $hookRunner->onUpdateUserMailerFormattedPageStatus( $formattedPageStatus );
189 if ( !in_array( $this->pageStatus, $formattedPageStatus ) ) {
190 throw new UnexpectedValueException(
'Not a valid page status!' );
192 $agent = $mwServices->getUserFactory()->newFromAuthority( $editor );
196 ( $config->get( MainConfigNames::EnotifMinorEdits ) &&
197 !$editor->
isAllowed(
'nominornewtalk' ) )
199 if ( $config->get( MainConfigNames::EnotifUserTalk )
201 && $this->canSendUserTalkEmail( $editor->
getUser(), $title, $minorEdit )
203 $targetUser = $userFactory->newFromName( $title->getText() );
210 RecentChangeNotification::TALK_NOTIFICATION
212 $notifService->notify( $talkNotification,
new RecipientSet( [ $targetUser ] ) );
213 $userTalkId = $targetUser->getId();
217 if ( $config->get( MainConfigNames::EnotifWatchlist ) ) {
218 $userOptionsLookup = $mwServices->getUserOptionsLookup();
221 $userArray = UserArray::newFromIDs( $watchers );
223 foreach ( $userArray as $watchingUser ) {
224 if ( $userOptionsLookup->
getOption( $watchingUser,
'enotifwatchlistpages' )
225 && ( !$minorEdit || $userOptionsLookup->
getOption( $watchingUser,
'enotifminoredits' ) )
226 && $watchingUser->getId() != $userTalkId
227 && !in_array( $watchingUser->getName(),
228 $config->get( MainConfigNames::UsersNotifiedOnAllChanges ) )
231 && !( $config->get( MainConfigNames::BlockDisablesLogin ) &&
232 $watchingUser->getBlock() )
233 && $hookRunner->onSendWatchlistEmailNotification( $watchingUser, $title, $this )
235 $recipients->addRecipient( $watchingUser );
238 if ( count( $recipients ) !== 0 ) {
244 RecentChangeNotification::WATCHLIST_NOTIFICATION
246 $notifService->notify( $talkNotification, $recipients );
251 foreach ( $config->get( MainConfigNames::UsersNotifiedOnAllChanges ) as $name ) {
253 if ( $editor->
getUser()->getName() == $name ) {
257 $user = $userFactory->newFromName( $name );
258 if ( $user instanceof
User ) {
261 $notifService->notify(
267 RecentChangeNotification::ADMIN_NOTIFICATION