mediawiki-extensions-Echo/ServiceWiring.php
Michael Holloway ce7a46f7ed Add push notifier
Provides a basic push notifier implementation. Since the push service is
not yet in place, all it does for now is log debug output when a
notification is to be sent.

To register the push notifier, add the following configuration to
LocalSettings.php:

 $wgEchoNotifiers['push'] = [ 'EchoPush\\PushNotifier', 'notifyWithPush' ];
 $wgDefaultNotifyTypeAvailability['push'] = true;
 $wgNotifyTypeAvailabilityByCategory['system']['push'] = false;
 $wgNotifyTypeAvailabilityByCategory['system-noemail']['push'] = false;

We'll register the notifier in configuration for now, rather than
hard-coding the default in extension.json, in order to have control over
when and where it rolls out (beta vs. prod, as well as which wikis).

Since the push notifier implementation depends on jobs being processed
by the job queue, I also recommend adding the following configuration
setting to ensure that all pending jobs are processed at the end of each
web request:

 // ensure all pending jobs are processed when a web request completes
 $wgJobRunRate = PHP_INT_MAX;

Bug: T252899
Change-Id: Ie7f222443045d30620ff297b006104ef18a074a8
2020-06-02 13:40:04 -04:00

50 lines
1.7 KiB
PHP

<?php
use EchoPush\NotificationServiceClient;
use EchoPush\SubscriptionManager;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableStore;
return [
'EchoPushNotificationServiceClient' => function ( MediaWikiServices $services ):
NotificationServiceClient {
$echoConfig = $services->getConfigFactory()->makeConfig( 'Echo' );
$httpRequestFactory = $services->getHttpRequestFactory();
$url = $echoConfig->get( 'EchoPushServiceUrl' );
$client = new NotificationServiceClient( $httpRequestFactory, $url );
$client->setLogger( LoggerFactory::getInstance( 'Echo' ) );
return $client;
},
'EchoPushSubscriptionManager' => function ( MediaWikiServices $services ): SubscriptionManager {
$echoConfig = $services->getConfigFactory()->makeConfig( 'Echo' );
// Use shared DB/cluster for push subscriptions
$cluster = $echoConfig->get( 'EchoSharedTrackingCluster' );
$database = $echoConfig->get( 'EchoSharedTrackingDB' );
$loadBalancerFactory = $services->getDBLoadBalancerFactory();
$loadBalancer = $cluster
? $loadBalancerFactory->getExternalLB( $cluster )
: $loadBalancerFactory->getMainLB( $database );
$dbw = $loadBalancer->getLazyConnectionRef( DB_MASTER, [], $database );
$dbr = $loadBalancer->getLazyConnectionRef( DB_REPLICA, [], $database );
$centralIdLookup = CentralIdLookup::factory();
$pushProviderStore = new NameTableStore(
$loadBalancer,
$services->getMainWANObjectCache(),
LoggerFactory::getInstance( 'Echo' ),
'echo_push_provider',
'epp_id',
'epp_name',
null,
$database
);
return new SubscriptionManager( $dbw, $dbr, $centralIdLookup, $pushProviderStore );
}
];