MediaWiki master
RecentChangeRCFeedNotifier.php
Go to the documentation of this file.
1<?php
8
14
19
20 public const CONSTRUCTOR_OPTIONS = [
26 ];
27
28 private HookContainer $hookContainer;
29 private ServiceOptions $options;
30
31 public function __construct(
32 HookContainer $hookContainer,
33 ServiceOptions $options
34 ) {
35 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
36
37 $this->hookContainer = $hookContainer;
38 $this->options = $options;
39 }
40
47 public function notifyRCFeeds( RecentChange $recentChange, ?array $feeds = null ) {
48 // T403757: Don't send 'suppressed from creation' recent changes entries to the RCFeeds as they do not
49 // have systems to appropriately redact suppressed / deleted material
50 if ( $recentChange->getAttribute( 'rc_deleted' ) != 0 ) {
51 return;
52 }
53
54 $feeds ??= $this->options->get( MainConfigNames::RCFeeds );
55
56 $performer = $recentChange->getPerformerIdentity();
57
58 foreach ( $feeds as $params ) {
59 $params += [
60 'omit_bots' => false,
61 'omit_anon' => false,
62 'omit_user' => false,
63 'omit_minor' => false,
64 'omit_patrolled' => false,
65 ];
66
67 if (
68 ( $params['omit_bots'] && $recentChange->getAttribute( 'rc_bot' ) ) ||
69 ( $params['omit_anon'] && !$performer->isRegistered() ) ||
70 ( $params['omit_user'] && $performer->isRegistered() ) ||
71 ( $params['omit_minor'] && $recentChange->getAttribute( 'rc_minor' ) ) ||
72 ( $params['omit_patrolled'] && $recentChange->getAttribute( 'rc_patrolled' ) ) ||
73 !in_array( $recentChange->getAttribute( 'rc_source' ), RecentChange::INTERNAL_SOURCES )
74 ) {
75 continue;
76 }
77
78 $actionComment = $recentChange->getExtra( 'actionCommentIRC' );
79
80 $feed = RCFeed::factory( $params );
81 $feed->notify( $recentChange, $actionComment );
82 }
83 }
84
93 public function getNotifyUrl( RecentChange $recentChange ): ?string {
94 $useRCPatrol = $this->options->get( MainConfigNames::UseRCPatrol );
95 $useNPPatrol = $this->options->get( MainConfigNames::UseNPPatrol );
96 $canonicalServer = $this->options->get( MainConfigNames::CanonicalServer );
97 $script = $this->options->get( MainConfigNames::Script );
98
99 $source = $recentChange->getAttribute( 'rc_source' );
101 $url = null;
102 } else {
103 $url = $canonicalServer . $script;
105 $query = '?oldid=' . $recentChange->getAttribute( 'rc_this_oldid' );
106 } else {
107 $query = '?diff=' . $recentChange->getAttribute( 'rc_this_oldid' )
108 . '&oldid=' . $recentChange->getAttribute( 'rc_last_oldid' );
109 }
110 if ( $useRCPatrol ||
111 ( $recentChange->getAttribute( 'rc_source' ) == RecentChange::SRC_NEW && $useNPPatrol )
112 ) {
113 $query .= '&rcid=' . $recentChange->getAttribute( 'rc_id' );
114 }
115
116 ( new HookRunner( $this->hookContainer ) )->onIRCLineURL( $url, $query, $recentChange );
117 $url .= $query;
118 }
119
120 return $url;
121 }
122
123}
A class for passing options to services.
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
A class containing constants representing the names of configuration variables.
const UseRCPatrol
Name constant for the UseRCPatrol setting, for use with Config::get()
const CanonicalServer
Name constant for the CanonicalServer setting, for use with Config::get()
const RCFeeds
Name constant for the RCFeeds setting, for use with Config::get()
const UseNPPatrol
Name constant for the UseNPPatrol setting, for use with Config::get()
const Script
Name constant for the Script setting, for use with Config::get()
static factory(array $params)
Definition RCFeed.php:33
notifyRCFeeds(RecentChange $recentChange, ?array $feeds=null)
Notify all the feeds about the change.
__construct(HookContainer $hookContainer, ServiceOptions $options)
getNotifyUrl(RecentChange $recentChange)
Get the extra URL that is given as part of the notification to RCFeed consumers.
Utility class for creating and reading rows in the recentchanges table.
getPerformerIdentity()
Get the UserIdentity of the client that performed this change.
getAttribute( $name)
Get an attribute value.
$source