mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-12 09:26:05 +00:00
f995de90c8
There are a variety of generic strategies you could define to choose which users should be notified about an event, such as 'users watching the title' or 'talk page owner' (User_talk only). This adds a new way to generically implement these in Echo and expose them to other extensions rather than having each extension implement these generic strategies themselves. This patch only converts one notification, edit-user-talk. The remaining notifications will be converted in future patches. The first user of this will be Flow for notifying all users watching a particular talk page in I4e46a9c003fbdde274b20ac7aef8455eab4a5222 The users watching title implementation provided here is minimalist, a larger refactor to accomidate pages with thousands of watchers is being handled in I3d3fa9328f348bb48682d3658622952ce82d3925 Change-Id: I19bb6a794d22565f3bb5421de92426d390197796
50 lines
1 KiB
PHP
50 lines
1 KiB
PHP
<?php
|
|
|
|
class EchoUserLocator {
|
|
|
|
/**
|
|
* The echo job queue must be enabled to prevent timeouts submitting to
|
|
* heavily watched pages when this is used.
|
|
*/
|
|
public static function locateUsersWatchingTitle( EchoEvent $event, $batchSize = 500 ) {
|
|
$title = $event->getTitle();
|
|
if ( !$title ) {
|
|
return array();
|
|
}
|
|
|
|
$dbr = wfGetDB( DB_SLAVE, 'watchlist' );
|
|
$res = $dbr->select(
|
|
array( 'watchlist' ),
|
|
array( 'wl_user' ),
|
|
array(
|
|
'wl_namespace' => $title->getNamespace(),
|
|
'wl_title' => $title->getDBkey(),
|
|
),
|
|
__METHOD__
|
|
);
|
|
|
|
$users = array();
|
|
if ( $res ) {
|
|
foreach ( $res as $row ) {
|
|
$users[$row->wl_user] = User::newFromId( $row->wl_user );
|
|
}
|
|
}
|
|
|
|
return $users;
|
|
}
|
|
|
|
public static function locateTalkPageOwner( EchoEvent $event ) {
|
|
$title = $event->getTitle();
|
|
if ( !$title || $title->getNamespace() !== NS_USER_TALK ) {
|
|
return array();
|
|
}
|
|
|
|
$user = User::newFromName( $title->getDBkey() );
|
|
if ( $user && !$user->isAnon() ) {
|
|
return array( $user->getId() => $user );
|
|
} else {
|
|
return array();
|
|
}
|
|
}
|
|
}
|