2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
2016-05-25 19:03:29 +00:00
|
|
|
use MediaWiki\Auth\AuthManager;
|
2016-02-29 06:13:25 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2017-03-17 11:16:28 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-07-09 22:45:54 +00:00
|
|
|
use MediaWiki\Preferences\MultiUsernameFilter;
|
2019-04-17 15:46:06 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2016-02-29 06:13:25 +00:00
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
class EchoHooks {
|
2018-03-26 22:32:30 +00:00
|
|
|
/**
|
2019-04-17 15:46:06 +00:00
|
|
|
* @var RevisionRecord
|
2018-03-26 22:32:30 +00:00
|
|
|
*/
|
|
|
|
private static $lastRevertedRevision = null;
|
|
|
|
|
2018-07-26 00:19:17 +00:00
|
|
|
/**
|
|
|
|
* @param array &$defaults
|
|
|
|
*/
|
|
|
|
public static function onUserGetDefaultOptions( array &$defaults ) {
|
|
|
|
global $wgAllowHTMLEmail, $wgEchoNotificationCategories;
|
2016-12-01 00:17:30 +00:00
|
|
|
|
|
|
|
if ( $wgAllowHTMLEmail ) {
|
2018-07-26 00:19:17 +00:00
|
|
|
$defaults['echo-email-format'] = 'html'; /*EchoHooks::EMAIL_FORMAT_HTML*/
|
2016-12-01 00:17:30 +00:00
|
|
|
} else {
|
2018-07-26 00:19:17 +00:00
|
|
|
$defaults['echo-email-format'] = 'plain-text'; /*EchoHooks::EMAIL_FORMAT_PLAIN_TEXT*/
|
2016-12-01 00:17:30 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 00:15:09 +00:00
|
|
|
$presets = [
|
|
|
|
// Set all of the events to notify by web but not email by default
|
|
|
|
// (won't affect events that don't email)
|
|
|
|
'default' => [
|
|
|
|
'email' => false,
|
|
|
|
'web' => true,
|
|
|
|
],
|
|
|
|
// most settings default to web on, email off, but override these
|
|
|
|
'system' => [
|
|
|
|
'email' => true,
|
|
|
|
],
|
|
|
|
'user-rights' => [
|
|
|
|
'email' => true,
|
|
|
|
],
|
|
|
|
'article-linked' => [
|
|
|
|
'web' => false,
|
|
|
|
],
|
|
|
|
'mention-failure' => [
|
|
|
|
'web' => false,
|
|
|
|
],
|
|
|
|
'mention-success' => [
|
|
|
|
'web' => false,
|
|
|
|
],
|
2019-12-09 02:42:55 +00:00
|
|
|
'watchlist' => [
|
|
|
|
'web' => false,
|
|
|
|
],
|
|
|
|
'minor-watchlist' => [
|
|
|
|
'web' => false,
|
|
|
|
],
|
2018-09-21 00:15:09 +00:00
|
|
|
];
|
|
|
|
|
2016-12-01 00:17:30 +00:00
|
|
|
foreach ( $wgEchoNotificationCategories as $category => $categoryData ) {
|
2018-09-21 00:15:09 +00:00
|
|
|
if ( !isset( $defaults["echo-subscriptions-email-{$category}"] ) ) {
|
|
|
|
$defaults["echo-subscriptions-email-{$category}"] = $presets[$category]['email']
|
|
|
|
?? $presets['default']['email'];
|
|
|
|
}
|
|
|
|
if ( !isset( $defaults["echo-subscriptions-web-{$category}"] ) ) {
|
|
|
|
$defaults["echo-subscriptions-web-{$category}"] = $presets[$category]['web']
|
|
|
|
?? $presets['default']['web'];
|
|
|
|
}
|
2016-12-01 00:17:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
/**
|
|
|
|
* Initialize Echo extension with necessary data, this function is invoked
|
|
|
|
* from $wgExtensionFunctions
|
|
|
|
*/
|
|
|
|
public static function initEchoExtension() {
|
2014-07-18 03:58:21 +00:00
|
|
|
global $wgEchoNotifications, $wgEchoNotificationCategories, $wgEchoNotificationIcons,
|
2019-10-04 00:01:00 +00:00
|
|
|
$wgEchoMentionStatusNotifications, $wgAllowArticleReminderNotification, $wgAPIModules,
|
2019-12-09 02:42:55 +00:00
|
|
|
$wgEchoWatchlistNotifications, $wgEchoSeenTimeCacheType, $wgMainStash;
|
2013-02-16 02:20:34 +00:00
|
|
|
|
|
|
|
// allow extensions to define their own event
|
2018-08-25 10:51:14 +00:00
|
|
|
Hooks::run( 'BeforeCreateEchoEvent',
|
|
|
|
[ &$wgEchoNotifications, &$wgEchoNotificationCategories, &$wgEchoNotificationIcons ] );
|
2013-02-16 02:20:34 +00:00
|
|
|
|
2016-06-21 14:42:56 +00:00
|
|
|
// Only allow mention status notifications when enabled
|
|
|
|
if ( !$wgEchoMentionStatusNotifications ) {
|
|
|
|
unset( $wgEchoNotificationCategories['mention-failure'] );
|
2016-07-21 13:00:54 +00:00
|
|
|
unset( $wgEchoNotificationCategories['mention-success'] );
|
2016-06-21 14:42:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 12:08:51 +00:00
|
|
|
// Only allow article reminder notifications when enabled
|
|
|
|
if ( !$wgAllowArticleReminderNotification ) {
|
|
|
|
unset( $wgEchoNotificationCategories['article-reminder'] );
|
2017-06-08 16:38:06 +00:00
|
|
|
unset( $wgAPIModules['echoarticlereminder'] );
|
2017-06-01 12:08:51 +00:00
|
|
|
}
|
2019-10-04 00:01:00 +00:00
|
|
|
|
2019-12-09 02:42:55 +00:00
|
|
|
// Only allow watchlist notifications when enabled
|
|
|
|
if ( !$wgEchoWatchlistNotifications ) {
|
|
|
|
unset( $wgEchoNotificationCategories['watchlist'] );
|
|
|
|
unset( $wgEchoNotificationCategories['minor-watchlist'] );
|
|
|
|
}
|
|
|
|
|
2019-10-04 00:01:00 +00:00
|
|
|
// Default $wgEchoSeenTimeCacheType to $wgMainStash
|
|
|
|
if ( $wgEchoSeenTimeCacheType === null ) {
|
|
|
|
$wgEchoSeenTimeCacheType = $wgMainStash;
|
|
|
|
}
|
2014-08-08 20:35:58 +00:00
|
|
|
}
|
2014-02-25 06:09:27 +00:00
|
|
|
|
2014-08-05 22:18:38 +00:00
|
|
|
/**
|
|
|
|
* ResourceLoaderTestModules hook handler
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
|
|
|
|
*
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param array &$testModules
|
2014-08-05 22:18:38 +00:00
|
|
|
* @param ResourceLoader $resourceLoader
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderTestModules( array &$testModules,
|
|
|
|
ResourceLoader $resourceLoader
|
|
|
|
) {
|
|
|
|
global $wgResourceModules;
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$testModuleBoilerplate = [
|
2018-04-09 07:19:34 +00:00
|
|
|
'localBasePath' => dirname( __DIR__ ),
|
2014-08-05 22:18:38 +00:00
|
|
|
'remoteExtPath' => 'Echo',
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2014-08-05 22:18:38 +00:00
|
|
|
|
|
|
|
// find test files for every RL module
|
|
|
|
$prefix = 'ext.echo';
|
|
|
|
foreach ( $wgResourceModules as $key => $module ) {
|
|
|
|
if ( substr( $key, 0, strlen( $prefix ) ) === $prefix && isset( $module['scripts'] ) ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$testFiles = [];
|
2014-08-05 22:18:38 +00:00
|
|
|
foreach ( $module['scripts'] as $script ) {
|
|
|
|
$testFile = 'tests/qunit/' . dirname( $script ) . '/test_' . basename( $script );
|
|
|
|
// if a test file exists for a given JS file, add it
|
|
|
|
if ( file_exists( $testModuleBoilerplate['localBasePath'] . '/' . $testFile ) ) {
|
|
|
|
$testFiles[] = $testFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if test files exist for given module, create a corresponding test module
|
2018-06-17 16:59:03 +00:00
|
|
|
if ( $testFiles !== [] ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$testModules['qunit']["$key.tests"] = $testModuleBoilerplate + [
|
|
|
|
'dependencies' => [ $key ],
|
2014-08-05 22:18:38 +00:00
|
|
|
'scripts' => $testFiles,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2014-08-05 22:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 00:26:59 +00:00
|
|
|
/**
|
|
|
|
* Handler for ResourceLoaderRegisterModules hook
|
2019-11-19 03:52:30 +00:00
|
|
|
* @param ResourceLoader $resourceLoader
|
2013-03-01 00:26:59 +00:00
|
|
|
*/
|
2019-11-19 03:52:30 +00:00
|
|
|
public static function onResourceLoaderRegisterModules( ResourceLoader $resourceLoader ) {
|
2017-03-02 05:01:56 +00:00
|
|
|
global $wgExtensionDirectory, $wgEchoNotificationIcons, $wgEchoSecondaryIcons;
|
2016-12-14 23:08:34 +00:00
|
|
|
$resourceLoader->register( 'ext.echo.emailicons', [
|
|
|
|
'class' => 'ResourceLoaderEchoImageModule',
|
2017-03-02 05:01:56 +00:00
|
|
|
'icons' => $wgEchoNotificationIcons,
|
|
|
|
'selector' => '.mw-echo-icon-{name}',
|
|
|
|
'localBasePath' => $wgExtensionDirectory,
|
|
|
|
'remoteExtPath' => 'Echo/modules'
|
|
|
|
] );
|
|
|
|
$resourceLoader->register( 'ext.echo.secondaryicons', [
|
|
|
|
'class' => 'ResourceLoaderEchoImageModule',
|
|
|
|
'icons' => $wgEchoSecondaryIcons,
|
2016-12-14 23:08:34 +00:00
|
|
|
'selector' => '.mw-echo-icon-{name}',
|
|
|
|
'localBasePath' => $wgExtensionDirectory,
|
|
|
|
'remoteExtPath' => 'Echo/modules'
|
|
|
|
] );
|
2013-03-01 00:26:59 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param DatabaseUpdater $updater
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2015-06-02 00:28:25 +00:00
|
|
|
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
|
|
|
|
global $wgEchoCluster;
|
2020-02-11 11:29:27 +00:00
|
|
|
if ( $wgEchoCluster ) {
|
2015-06-02 00:28:25 +00:00
|
|
|
// DatabaseUpdater does not support other databases, so skip
|
|
|
|
return;
|
|
|
|
}
|
2018-04-09 07:19:34 +00:00
|
|
|
$dir = dirname( __DIR__ );
|
2012-04-27 15:14:24 +00:00
|
|
|
$baseSQLFile = "$dir/echo.sql";
|
2013-03-26 00:57:42 +00:00
|
|
|
$updater->addExtensionTable( 'echo_event', $baseSQLFile );
|
2012-11-27 01:53:35 +00:00
|
|
|
$updater->addExtensionTable( 'echo_email_batch', "$dir/db_patches/echo_email_batch.sql" );
|
2014-08-06 00:16:10 +00:00
|
|
|
$updater->addExtensionTable( 'echo_target_page', "$dir/db_patches/echo_target_page.sql" );
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2013-05-20 17:23:51 +00:00
|
|
|
if ( $updater->getDB()->getType() === 'sqlite' ) {
|
2018-08-25 10:51:14 +00:00
|
|
|
$updater->modifyExtensionField( 'echo_event', 'event_agent',
|
|
|
|
"$dir/db_patches/patch-event_agent-split.sqlite.sql" );
|
|
|
|
$updater->modifyExtensionField( 'echo_event', 'event_variant',
|
|
|
|
"$dir/db_patches/patch-event_variant_nullability.sqlite.sql" );
|
|
|
|
$updater->addExtensionField( 'echo_target_page', 'etp_id',
|
|
|
|
"$dir/db_patches/patch-multiple_target_pages.sqlite.sql" );
|
|
|
|
$updater->dropExtensionField( 'echo_target_page', 'etp_user',
|
|
|
|
"$dir/db_patches/patch-drop-echo_target_page-etp_user.sqlite.sql" );
|
2013-05-20 17:23:51 +00:00
|
|
|
// There is no need to run the patch-event_extra-size or patch-event_agent_ip-size because
|
|
|
|
// sqlite ignores numeric arguments in parentheses that follow the type name (ex: VARCHAR(255))
|
|
|
|
// see http://www.sqlite.org/datatype3.html Section 2.2 for more info
|
|
|
|
} else {
|
2018-08-25 10:51:14 +00:00
|
|
|
$updater->modifyExtensionField( 'echo_event', 'event_agent',
|
|
|
|
"$dir/db_patches/patch-event_agent-split.sql" );
|
|
|
|
$updater->modifyExtensionField( 'echo_event', 'event_variant',
|
|
|
|
"$dir/db_patches/patch-event_variant_nullability.sql" );
|
|
|
|
$updater->modifyExtensionField( 'echo_event', 'event_extra',
|
|
|
|
"$dir/db_patches/patch-event_extra-size.sql" );
|
|
|
|
$updater->modifyExtensionField( 'echo_event', 'event_agent_ip',
|
|
|
|
"$dir/db_patches/patch-event_agent_ip-size.sql" );
|
|
|
|
$updater->addExtensionField( 'echo_target_page', 'etp_id',
|
|
|
|
"$dir/db_patches/patch-multiple_target_pages.sql" );
|
|
|
|
$updater->dropExtensionField( 'echo_target_page', 'etp_user',
|
|
|
|
"$dir/db_patches/patch-drop-echo_target_page-etp_user.sql" );
|
2013-05-20 17:23:51 +00:00
|
|
|
}
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2016-08-24 02:34:32 +00:00
|
|
|
$updater->addExtensionField( 'echo_notification', 'notification_bundle_hash',
|
2013-01-15 23:21:39 +00:00
|
|
|
"$dir/db_patches/patch-notification-bundling-field.sql" );
|
2018-08-25 10:51:14 +00:00
|
|
|
// This index was renamed twice, first from type_page to event_type and
|
|
|
|
// later from event_type to echo_event_type
|
2013-05-20 17:23:51 +00:00
|
|
|
if ( $updater->getDB()->indexExists( 'echo_event', 'type_page', __METHOD__ ) ) {
|
2018-08-25 10:51:14 +00:00
|
|
|
$updater->addExtensionIndex( 'echo_event', 'event_type',
|
|
|
|
"$dir/db_patches/patch-alter-type_page-index.sql" );
|
2013-05-20 17:23:51 +00:00
|
|
|
}
|
2018-08-25 10:51:14 +00:00
|
|
|
$updater->dropExtensionTable( 'echo_subscription',
|
|
|
|
"$dir/db_patches/patch-drop-echo_subscription.sql" );
|
2016-08-24 02:34:32 +00:00
|
|
|
if ( $updater->getDB()->getType() !== 'sqlite' ) {
|
|
|
|
$updater->dropExtensionField( 'echo_event', 'event_timestamp',
|
|
|
|
"$dir/db_patches/patch-drop-echo_event-event_timestamp.sql" );
|
|
|
|
}
|
2013-03-06 00:04:48 +00:00
|
|
|
$updater->addExtensionField( 'echo_email_batch', 'eeb_event_hash',
|
|
|
|
"$dir/db_patches/patch-email_batch-new-field.sql" );
|
2018-08-25 10:51:14 +00:00
|
|
|
$updater->addExtensionField( 'echo_event', 'event_page_id',
|
|
|
|
"$dir/db_patches/patch-add-echo_event-event_page_id.sql" );
|
|
|
|
$updater->addExtensionIndex( 'echo_event', 'echo_event_type',
|
|
|
|
"$dir/db_patches/patch-alter-event_type-index.sql" );
|
|
|
|
$updater->addExtensionIndex( 'echo_notification', 'echo_user_timestamp',
|
|
|
|
"$dir/db_patches/patch-alter-user_timestamp-index.sql" );
|
|
|
|
$updater->addExtensionIndex( 'echo_notification', 'echo_notification_event',
|
|
|
|
"$dir/db_patches/patch-add-notification_event-index.sql" );
|
2019-03-15 18:28:29 +00:00
|
|
|
$updater->addPostDatabaseUpdateMaintenance( RemoveOrphanedEvents::class );
|
2018-08-25 10:51:14 +00:00
|
|
|
$updater->addExtensionField( 'echo_event', 'event_deleted',
|
|
|
|
"$dir/db_patches/patch-add-echo_event-event_deleted.sql" );
|
|
|
|
$updater->addExtensionIndex( 'echo_notification', 'echo_notification_user_read_timestamp',
|
|
|
|
"$dir/db_patches/patch-add-user_read_timestamp-index.sql" );
|
|
|
|
$updater->addExtensionIndex( 'echo_target_page', 'echo_target_page_page_event',
|
|
|
|
"$dir/db_patches/patch-add-page_event-index.sql" );
|
|
|
|
$updater->addExtensionIndex( 'echo_event', 'echo_event_page_id',
|
|
|
|
"$dir/db_patches/patch-add-event_page_id-index.sql" );
|
|
|
|
$updater->dropExtensionIndex( 'echo_notification', 'user_event',
|
|
|
|
"$dir/db_patches/patch-notification-pk.sql" );
|
2016-06-06 21:56:53 +00:00
|
|
|
// Can't use addPostDatabaseUpdateMaintenance() here because that would
|
|
|
|
// run the migration script after dropping the fields
|
2019-03-15 18:28:29 +00:00
|
|
|
$updater->addExtensionUpdate( [ 'runMaintenance', UpdateEchoSchemaForSuppression::class,
|
2016-06-06 21:56:53 +00:00
|
|
|
'extensions/Echo/maintenance/updateEchoSchemaForSuppression.php' ] );
|
|
|
|
$updater->dropExtensionField( 'echo_event', 'event_page_namespace',
|
|
|
|
"$dir/db_patches/patch-drop-echo_event-event_page_namespace.sql" );
|
|
|
|
$updater->dropExtensionField( 'echo_event', 'event_page_title',
|
|
|
|
"$dir/db_patches/patch-drop-echo_event-event_page_title.sql" );
|
2016-08-24 02:34:32 +00:00
|
|
|
if ( $updater->getDB()->getType() !== 'sqlite' ) {
|
|
|
|
$updater->dropExtensionField( 'echo_notification', 'notification_bundle_base',
|
|
|
|
"$dir/db_patches/patch-drop-notification_bundle_base.sql" );
|
2016-08-25 23:53:24 +00:00
|
|
|
$updater->dropExtensionField( 'echo_notification', 'notification_bundle_display_hash',
|
|
|
|
"$dir/db_patches/patch-drop-notification_bundle_display_hash.sql" );
|
2016-08-24 02:34:32 +00:00
|
|
|
}
|
2016-08-25 23:53:24 +00:00
|
|
|
$updater->dropExtensionIndex( 'echo_notification', 'echo_notification_user_hash_timestamp',
|
|
|
|
"$dir/db_patches/patch-drop-user-hash-timestamp-index.sql" );
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for EchoGetBundleRule hook, which defines the bundle rule for each notification
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param EchoEvent $event
|
|
|
|
* @param string &$bundleString Determines how the notification should be bundled, for example,
|
2013-01-15 23:21:39 +00:00
|
|
|
* talk page notification is bundled based on namespace and title, the bundle string would be
|
|
|
|
* 'edit-user-talk-' + namespace + title, email digest/email bundling would use this hash as
|
|
|
|
* a key to identify bundle-able event. For web bundling, we bundle further based on user's
|
|
|
|
* visit to the overlay, we would generate a display hash based on the hash of $bundleString
|
|
|
|
*/
|
|
|
|
public static function onEchoGetBundleRules( $event, &$bundleString ) {
|
|
|
|
switch ( $event->getType() ) {
|
|
|
|
case 'edit-user-talk':
|
|
|
|
$bundleString = 'edit-user-talk';
|
|
|
|
if ( $event->getTitle() ) {
|
|
|
|
$bundleString .= '-' . $event->getTitle()->getNamespace()
|
2015-10-01 13:48:52 +00:00
|
|
|
. '-' . $event->getTitle()->getDBkey();
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
break;
|
2013-01-15 23:21:39 +00:00
|
|
|
case 'page-linked':
|
|
|
|
$bundleString = 'page-linked';
|
|
|
|
if ( $event->getTitle() ) {
|
|
|
|
$bundleString .= '-' . $event->getTitle()->getNamespace()
|
2015-10-01 13:48:52 +00:00
|
|
|
. '-' . $event->getTitle()->getDBkey();
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
break;
|
2016-07-21 13:00:54 +00:00
|
|
|
case 'mention-success':
|
2016-07-29 10:15:34 +00:00
|
|
|
case 'mention-failure':
|
|
|
|
$bundleString = 'mention-status-' . $event->getExtraParam( 'revid' );
|
2016-07-21 13:00:54 +00:00
|
|
|
break;
|
2019-12-09 02:42:55 +00:00
|
|
|
case 'watchlist-change':
|
|
|
|
case 'minor-watchlist-change':
|
|
|
|
$bundleString = 'watchlist-change';
|
|
|
|
if ( $event->getTitle() ) {
|
|
|
|
$bundleString .= '-' . $event->getTitle()->getNamespace()
|
|
|
|
. '-' . $event->getTitle()->getDBkey();
|
|
|
|
}
|
|
|
|
break;
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for GetPreferences hook.
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user User to get preferences for
|
|
|
|
* @param array &$preferences Preferences array
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
|
|
|
* @throws MWException
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public static function getPreferences( $user, &$preferences ) {
|
2016-05-25 19:03:29 +00:00
|
|
|
global $wgEchoEnableEmailBatch,
|
2013-05-01 20:48:12 +00:00
|
|
|
$wgEchoNotifiers, $wgEchoNotificationCategories, $wgEchoNotifications,
|
2019-08-02 20:14:05 +00:00
|
|
|
$wgAllowHTMLEmail, $wgEchoPollForUpdates,
|
2019-12-09 02:42:55 +00:00
|
|
|
$wgEchoCrossWikiNotifications, $wgEchoPerUserBlacklist,
|
|
|
|
$wgEchoWatchlistNotifications;
|
2012-11-16 21:03:57 +00:00
|
|
|
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
$attributeManager = EchoAttributeManager::newFromGlobalVars();
|
|
|
|
|
2012-11-16 21:03:57 +00:00
|
|
|
// Show email frequency options
|
2016-12-05 18:51:07 +00:00
|
|
|
$freqOptions = [
|
2018-12-31 15:54:19 +00:00
|
|
|
'echo-pref-email-frequency-never' => EchoEmailFrequency::NEVER,
|
|
|
|
'echo-pref-email-frequency-immediately' => EchoEmailFrequency::IMMEDIATELY,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2012-12-14 20:48:41 +00:00
|
|
|
// Only show digest options if email batch is enabled
|
|
|
|
if ( $wgEchoEnableEmailBatch ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$freqOptions += [
|
2018-12-31 15:54:19 +00:00
|
|
|
'echo-pref-email-frequency-daily' => EchoEmailFrequency::DAILY_DIGEST,
|
|
|
|
'echo-pref-email-frequency-weekly' => EchoEmailFrequency::WEEKLY_DIGEST,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2012-12-14 20:48:41 +00:00
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
$preferences['echo-email-frequency'] = [
|
2012-11-16 21:03:57 +00:00
|
|
|
'type' => 'select',
|
2013-04-18 00:44:20 +00:00
|
|
|
'label-message' => 'echo-pref-send-me',
|
|
|
|
'section' => 'echo/emailsettings',
|
2018-12-31 15:54:19 +00:00
|
|
|
'options-messages' => $freqOptions
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2012-11-16 21:03:57 +00:00
|
|
|
|
2019-12-10 00:13:29 +00:00
|
|
|
$preferences['echo-dont-email-read-notifications'] = [
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'echo-pref-dont-email-read-notifications',
|
|
|
|
'section' => 'echo/emailsettings',
|
|
|
|
'hide-if' => [ 'OR', [ '===', 'echo-email-frequency', '-1' ], [ '===', 'echo-email-frequency', '0' ] ]
|
|
|
|
];
|
|
|
|
|
2012-11-16 21:03:57 +00:00
|
|
|
// Display information about the user's currently set email address
|
|
|
|
$prefsTitle = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' );
|
2016-12-04 13:08:41 +00:00
|
|
|
$link = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
|
2012-11-16 21:03:57 +00:00
|
|
|
SpecialPage::getTitleFor( 'ChangeEmail' ),
|
2016-12-04 13:08:41 +00:00
|
|
|
wfMessage( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->text(),
|
2016-12-05 18:51:07 +00:00
|
|
|
[],
|
|
|
|
[ 'returnto' => $prefsTitle->getFullText() ]
|
2012-11-16 21:03:57 +00:00
|
|
|
);
|
2016-05-12 17:18:58 +00:00
|
|
|
$emailAddress = $user->getEmail() && $user->isAllowed( 'viewmyprivateinfo' )
|
|
|
|
? htmlspecialchars( $user->getEmail() ) : '';
|
2016-05-25 19:03:29 +00:00
|
|
|
if ( $user->isAllowed( 'editmyprivateinfo' ) && self::isEmailChangeAllowed() ) {
|
2012-11-16 21:03:57 +00:00
|
|
|
if ( $emailAddress === '' ) {
|
|
|
|
$emailAddress .= $link;
|
|
|
|
} else {
|
|
|
|
$emailAddress .= wfMessage( 'word-separator' )->escaped()
|
|
|
|
. wfMessage( 'parentheses' )->rawParams( $link )->escaped();
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
$preferences['echo-emailaddress'] = [
|
2012-11-16 21:03:57 +00:00
|
|
|
'type' => 'info',
|
|
|
|
'raw' => true,
|
2013-04-18 00:44:20 +00:00
|
|
|
'default' => $emailAddress,
|
|
|
|
'label-message' => 'echo-pref-send-to',
|
|
|
|
'section' => 'echo/emailsettings'
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2012-11-16 21:03:57 +00:00
|
|
|
|
2013-06-24 00:22:08 +00:00
|
|
|
// Only show this option if html email is allowed, otherwise it is always plain text format
|
|
|
|
if ( $wgAllowHTMLEmail ) {
|
|
|
|
// Email format
|
2016-12-05 18:51:07 +00:00
|
|
|
$preferences['echo-email-format'] = [
|
2013-06-24 00:22:08 +00:00
|
|
|
'type' => 'select',
|
|
|
|
'label-message' => 'echo-pref-email-format',
|
|
|
|
'section' => 'echo/emailsettings',
|
2018-12-31 15:54:19 +00:00
|
|
|
'options-messages' => [
|
|
|
|
'echo-pref-email-format-html' => EchoEmailFormat::HTML,
|
|
|
|
'echo-pref-email-format-plain-text' => EchoEmailFormat::PLAIN_TEXT,
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
|
|
|
];
|
2013-06-24 00:22:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 02:20:34 +00:00
|
|
|
// Sort notification categories by priority
|
2016-12-05 18:51:07 +00:00
|
|
|
$categoriesAndPriorities = [];
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
foreach ( $attributeManager->getInternalCategoryNames() as $category ) {
|
|
|
|
// See if the category should be hidden from preferences.
|
|
|
|
if ( !$attributeManager->isCategoryDisplayedInPreferences( $category ) ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
|
2016-12-28 11:29:44 +00:00
|
|
|
// See if user is eligible to receive this notification (per user group restrictions)
|
2014-07-22 21:33:22 +00:00
|
|
|
if ( $attributeManager->getCategoryEligibility( $user, $category ) ) {
|
|
|
|
$categoriesAndPriorities[$category] = $attributeManager->getCategoryPriority( $category );
|
2013-01-14 23:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-16 02:20:34 +00:00
|
|
|
asort( $categoriesAndPriorities );
|
|
|
|
$validSortedCategories = array_keys( $categoriesAndPriorities );
|
2013-01-14 23:52:46 +00:00
|
|
|
|
2019-12-09 02:42:55 +00:00
|
|
|
// Show subscription options. IMPORTANT: 'echo-subscriptions-email-edit-user-talk',
|
|
|
|
// 'echo-subscriptions-email-watchlist', and 'echo-subscriptions-email-minor-watchlist' are
|
|
|
|
// virtual options, their values are saved to existing notification options 'enotifusertalkpages',
|
|
|
|
// 'enotifwatchlistpages', and 'enotifminoredits', see onUserLoadOptions() and onUserSaveOptions()
|
|
|
|
// for more information on how it is handled. Doing it in this way, we can avoid keeping running
|
2013-05-09 21:23:15 +00:00
|
|
|
// massive data migration script to keep these two options synced when echo is enabled on
|
|
|
|
// new wikis or Echo is disabled and re-enabled for some reason. We can update the name
|
|
|
|
// if Echo is ever merged to core
|
2013-02-16 02:20:34 +00:00
|
|
|
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
// Build the columns (notify types)
|
2016-12-05 18:51:07 +00:00
|
|
|
$columns = [];
|
2013-02-16 02:20:34 +00:00
|
|
|
foreach ( $wgEchoNotifiers as $notifierType => $notifierData ) {
|
2013-04-16 22:40:45 +00:00
|
|
|
$formatMessage = wfMessage( 'echo-pref-' . $notifierType )->escaped();
|
2013-02-16 02:20:34 +00:00
|
|
|
$columns[$formatMessage] = $notifierType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the rows (notification categories)
|
2016-12-05 18:51:07 +00:00
|
|
|
$rows = [];
|
|
|
|
$tooltips = [];
|
2013-02-16 02:20:34 +00:00
|
|
|
foreach ( $validSortedCategories as $category ) {
|
2013-04-16 22:40:45 +00:00
|
|
|
$categoryMessage = wfMessage( 'echo-category-title-' . $category )->numParams( 1 )->escaped();
|
2013-02-16 02:20:34 +00:00
|
|
|
$rows[$categoryMessage] = $category;
|
2013-05-02 00:12:59 +00:00
|
|
|
if ( isset( $wgEchoNotificationCategories[$category]['tooltip'] ) ) {
|
2016-04-02 13:41:56 +00:00
|
|
|
$tooltips[$categoryMessage] = wfMessage( $wgEchoNotificationCategories[$category]['tooltip'] )->text();
|
2013-05-02 00:12:59 +00:00
|
|
|
}
|
2013-02-16 02:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out the individual exceptions in the matrix and make them disabled
|
2016-12-05 18:51:07 +00:00
|
|
|
$forceOptionsOff = $forceOptionsOn = [];
|
2013-02-16 02:20:34 +00:00
|
|
|
foreach ( $wgEchoNotifiers as $notifierType => $notifierData ) {
|
|
|
|
foreach ( $validSortedCategories as $category ) {
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
// See if this notify type is non-dismissable
|
|
|
|
if ( !$attributeManager->isNotifyTypeDismissableForCategory( $category, $notifierType ) ) {
|
2013-04-29 17:58:05 +00:00
|
|
|
$forceOptionsOn[] = "$notifierType-$category";
|
2013-01-14 23:52:46 +00:00
|
|
|
}
|
2013-02-16 02:20:34 +00:00
|
|
|
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
if ( !$attributeManager->isNotifyTypeAvailableForCategory( $category, $notifierType ) ) {
|
2013-04-29 17:58:05 +00:00
|
|
|
$forceOptionsOff[] = "$notifierType-$category";
|
2013-01-14 23:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-29 17:58:05 +00:00
|
|
|
$invalid = array_intersect( $forceOptionsOff, $forceOptionsOn );
|
|
|
|
if ( $invalid ) {
|
|
|
|
throw new MWException( sprintf(
|
|
|
|
'The following notifications are both forced and removed: %s',
|
|
|
|
implode( ', ', $invalid )
|
|
|
|
) );
|
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
$preferences['echo-subscriptions'] = [
|
2013-02-16 02:20:34 +00:00
|
|
|
'class' => 'HTMLCheckMatrix',
|
|
|
|
'section' => 'echo/echosubscriptions',
|
|
|
|
'rows' => $rows,
|
|
|
|
'columns' => $columns,
|
2013-05-22 19:50:24 +00:00
|
|
|
'prefix' => 'echo-subscriptions-',
|
2013-04-29 17:58:05 +00:00
|
|
|
'force-options-off' => $forceOptionsOff,
|
|
|
|
'force-options-on' => $forceOptionsOn,
|
2013-05-02 00:12:59 +00:00
|
|
|
'tooltips' => $tooltips,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2013-03-20 01:10:23 +00:00
|
|
|
|
2019-04-18 05:18:13 +00:00
|
|
|
if ( $wgEchoCrossWikiNotifications ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$preferences['echo-cross-wiki-notifications'] = [
|
2016-03-11 01:48:06 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'echo-pref-cross-wiki-notifications',
|
|
|
|
'section' => 'echo/echocrosswiki'
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-03-11 01:48:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 20:14:05 +00:00
|
|
|
if ( $wgEchoPollForUpdates ) {
|
|
|
|
$preferences['echo-show-poll-updates'] = [
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'echo-pref-show-poll-updates',
|
|
|
|
'help-message' => 'echo-pref-show-poll-updates-help',
|
|
|
|
'section' => 'echo/echopollupdates'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-12-09 02:42:55 +00:00
|
|
|
// If we're using Echo to handle user talk page post or watchlist notifications,
|
|
|
|
// hide the old (non-Echo) preferences for them. If Echo is moved to core
|
|
|
|
// we'll want to remove the old user options entirely. For now, though,
|
2013-04-28 21:55:05 +00:00
|
|
|
// we need to keep it defined in case Echo is ever uninstalled.
|
|
|
|
// Otherwise, that preference could be lost entirely. This hiding logic
|
2019-12-09 02:42:55 +00:00
|
|
|
// is not abstracted since there are only three preferences in core
|
|
|
|
// that are potentially made obsolete by Echo.
|
2013-04-28 21:55:05 +00:00
|
|
|
if ( isset( $wgEchoNotifications['edit-user-talk'] ) ) {
|
|
|
|
$preferences['enotifusertalkpages']['type'] = 'hidden';
|
|
|
|
unset( $preferences['enotifusertalkpages']['section'] );
|
|
|
|
}
|
2019-12-09 02:42:55 +00:00
|
|
|
if ( $wgEchoWatchlistNotifications && isset( $wgEchoNotifications['watchlist-change'] ) ) {
|
|
|
|
$preferences['enotifwatchlistpages']['type'] = 'hidden';
|
|
|
|
unset( $preferences['enotifusertalkpages']['section'] );
|
|
|
|
$preferences['enotifminoredits']['type'] = 'hidden';
|
|
|
|
unset( $preferences['enotifminoredits']['section'] );
|
|
|
|
}
|
2013-04-28 21:55:05 +00:00
|
|
|
|
2016-11-10 04:37:10 +00:00
|
|
|
if ( $wgEchoPerUserBlacklist ) {
|
|
|
|
$preferences['echo-notifications-blacklist'] = [
|
2017-05-20 13:51:30 +00:00
|
|
|
'type' => 'usersmultiselect',
|
2016-11-10 04:37:10 +00:00
|
|
|
'label-message' => 'echo-pref-notifications-blacklist',
|
|
|
|
'section' => 'echo/blocknotificationslist',
|
2018-07-09 22:45:54 +00:00
|
|
|
'filter' => MultiUsernameFilter::class,
|
2016-11-10 04:37:10 +00:00
|
|
|
];
|
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 19:03:29 +00:00
|
|
|
/**
|
|
|
|
* Test whether email address change is supposed to be allowed
|
2017-08-09 15:20:55 +00:00
|
|
|
* @return bool
|
2016-05-25 19:03:29 +00:00
|
|
|
*/
|
|
|
|
private static function isEmailChangeAllowed() {
|
2017-10-12 00:28:09 +00:00
|
|
|
return AuthManager::singleton()->allowsPropertyChange( 'emailaddress' );
|
2016-05-25 19:03:29 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
2016-10-06 16:22:28 +00:00
|
|
|
* Handler for PageContentSaveComplete hook
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/PageContentSaveComplete
|
2017-12-08 13:49:55 +00:00
|
|
|
*
|
2019-04-17 15:46:06 +00:00
|
|
|
* @param WikiPage $wikiPage modified WikiPage
|
2019-11-19 03:52:30 +00:00
|
|
|
* @param User $user User who edited
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param Content $content New article text
|
|
|
|
* @param string $summary Edit summary
|
|
|
|
* @param bool $minoredit Minor edit or not
|
|
|
|
* @param bool $watchthis Watch this article?
|
|
|
|
* @param string $sectionanchor Section that was edited
|
|
|
|
* @param int &$flags Edit flags
|
|
|
|
* @param Revision $revision Revision that was created
|
2019-11-19 03:52:30 +00:00
|
|
|
* @param Status $status
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param int $baseRevId
|
|
|
|
* @param int $undidRevId
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2018-08-25 10:51:14 +00:00
|
|
|
public static function onPageContentSaveComplete(
|
2019-04-17 15:46:06 +00:00
|
|
|
WikiPage $wikiPage,
|
2019-11-19 03:52:30 +00:00
|
|
|
$user,
|
2018-08-25 10:51:14 +00:00
|
|
|
$content,
|
|
|
|
$summary,
|
|
|
|
$minoredit,
|
|
|
|
$watchthis,
|
|
|
|
$sectionanchor,
|
|
|
|
&$flags,
|
|
|
|
$revision,
|
2019-11-19 03:52:30 +00:00
|
|
|
Status $status,
|
2018-08-25 10:51:14 +00:00
|
|
|
$baseRevId,
|
|
|
|
$undidRevId = 0
|
|
|
|
) {
|
2016-12-18 02:21:53 +00:00
|
|
|
global $wgEchoNotifications;
|
2013-11-04 17:58:47 +00:00
|
|
|
|
2015-05-18 19:58:15 +00:00
|
|
|
if ( !$revision ) {
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2015-05-18 19:58:15 +00:00
|
|
|
}
|
2016-02-24 08:27:17 +00:00
|
|
|
|
|
|
|
// unless status is "good" (not only ok, also no warnings or errors), we
|
|
|
|
// probably shouldn't process it at all (e.g. null edits)
|
|
|
|
if ( !$status->isGood() ) {
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2016-02-24 08:27:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 13:49:55 +00:00
|
|
|
$title = $wikiPage->getTitle();
|
2012-07-27 22:16:19 +00:00
|
|
|
|
2015-05-18 19:58:15 +00:00
|
|
|
// Try to do this after the HTTP response
|
2018-01-19 21:26:49 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $revision, $undidRevId ) {
|
2018-03-26 22:32:30 +00:00
|
|
|
// This check has to happen during deferred processing, otherwise $lastRevertedRevision
|
|
|
|
// will not be initialized.
|
|
|
|
$isRevert = $undidRevId > 0 ||
|
|
|
|
( self::$lastRevertedRevision &&
|
|
|
|
self::$lastRevertedRevision->getId() === $revision->getId() );
|
2019-04-17 15:46:06 +00:00
|
|
|
EchoDiscussionParser::generateEventsForRevision( $revision->getRevisionRecord(), $isRevert );
|
2015-05-18 19:58:15 +00:00
|
|
|
} );
|
|
|
|
|
2016-01-18 23:55:47 +00:00
|
|
|
// If the user is not an IP and this is not a null edit,
|
|
|
|
// test for them reaching a congratulatory threshold
|
2016-02-26 23:51:25 +00:00
|
|
|
$thresholds = [ 1, 10, 100, 1000, 10000, 100000, 1000000 ];
|
2016-01-18 23:55:47 +00:00
|
|
|
if ( $user->isLoggedIn() && $status->value['revision'] ) {
|
2019-03-04 15:49:19 +00:00
|
|
|
$thresholdCount = self::getEditCount( $user );
|
2016-03-09 01:05:05 +00:00
|
|
|
if ( in_array( $thresholdCount, $thresholds ) ) {
|
2016-08-03 15:41:50 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $user, $title, $thresholdCount ) {
|
|
|
|
$notificationMapper = new EchoNotificationMapper();
|
2016-12-05 18:51:07 +00:00
|
|
|
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
|
2016-08-03 15:41:50 +00:00
|
|
|
/** @var EchoNotification $notification */
|
|
|
|
foreach ( $notifications as $notification ) {
|
|
|
|
if ( $notification->getEvent()->getExtraParam( 'editCount' ) === $thresholdCount ) {
|
|
|
|
LoggerFactory::getInstance( 'Echo' )->debug(
|
|
|
|
'{user} (id: {id}) has already been thanked for their {count} edit',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2016-08-03 15:41:50 +00:00
|
|
|
'user' => $user->getName(),
|
|
|
|
'id' => $user->getId(),
|
|
|
|
'count' => $thresholdCount,
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2016-08-03 15:41:50 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-04 05:48:01 +00:00
|
|
|
}
|
2016-08-03 15:41:50 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
EchoEvent::create( [
|
2016-01-18 23:55:47 +00:00
|
|
|
'type' => 'thank-you-edit',
|
|
|
|
'title' => $title,
|
|
|
|
'agent' => $user,
|
|
|
|
// Edit threshold notifications are sent to the agent
|
2016-12-05 18:51:07 +00:00
|
|
|
'extra' => [
|
2016-03-11 16:58:21 +00:00
|
|
|
'editCount' => $thresholdCount,
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
|
|
|
]
|
2016-01-18 23:55:47 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 19:58:15 +00:00
|
|
|
// Handle the case of someone undoing an edit, either through the
|
|
|
|
// 'undo' link in the article history or via the API.
|
2016-12-18 02:21:53 +00:00
|
|
|
if ( isset( $wgEchoNotifications['reverted'] ) && $undidRevId ) {
|
2019-04-17 15:46:06 +00:00
|
|
|
$store = MediaWikiServices::getInstance()->getRevisionStore();
|
|
|
|
$undidRevision = $store->getRevisionById( $undidRevId );
|
|
|
|
if (
|
|
|
|
$undidRevision &&
|
|
|
|
Title::newFromLinkTarget( $undidRevision->getPageAsLinkTarget() )->equals( $title )
|
|
|
|
) {
|
2016-12-18 02:21:53 +00:00
|
|
|
$victimId = $undidRevision->getUser();
|
|
|
|
if ( $victimId ) { // No notifications for anonymous users
|
|
|
|
EchoEvent::create( [
|
|
|
|
'type' => 'reverted',
|
|
|
|
'title' => $title,
|
|
|
|
'extra' => [
|
|
|
|
'revid' => $revision->getId(),
|
|
|
|
'reverted-user-id' => $victimId,
|
|
|
|
'reverted-revision-id' => $undidRevId,
|
2018-03-26 18:54:03 +00:00
|
|
|
'method' => 'undo',
|
2016-12-18 02:21:53 +00:00
|
|
|
'summary' => $summary,
|
|
|
|
],
|
|
|
|
'agent' => $user,
|
|
|
|
] );
|
2012-07-18 19:39:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-01 20:15:37 +00:00
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2019-03-04 15:49:19 +00:00
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private static function getEditCount( User $user ) {
|
|
|
|
// When this code runs from a maintenance script or unit tests
|
|
|
|
// the deferred update incrementing edit count runs right away
|
|
|
|
// so the edit count is right. Otherwise it lags by one.
|
|
|
|
if ( wfIsCLI() ) {
|
|
|
|
return $user->getEditCount();
|
|
|
|
}
|
|
|
|
return $user->getEditCount() + 1;
|
|
|
|
}
|
|
|
|
|
2013-05-01 19:27:32 +00:00
|
|
|
/**
|
|
|
|
* Handler for EchoAbortEmailNotification hook
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user
|
|
|
|
* @param EchoEvent $event
|
2013-05-01 19:27:32 +00:00
|
|
|
* @return bool true - send email, false - do not send email
|
|
|
|
*/
|
|
|
|
public static function onEchoAbortEmailNotification( $user, $event ) {
|
2019-12-09 02:42:55 +00:00
|
|
|
global $wgEchoWatchlistEmailOncePerPage;
|
|
|
|
$type = $event->getType();
|
|
|
|
if ( $type === 'edit-user-talk' ) {
|
2013-05-01 19:27:32 +00:00
|
|
|
$extra = $event->getExtra();
|
|
|
|
if ( !empty( $extra['minoredit'] ) ) {
|
|
|
|
global $wgEnotifMinorEdits;
|
|
|
|
if ( !$wgEnotifMinorEdits || !$user->getOption( 'enotifminoredits' ) ) {
|
|
|
|
// Do not send talk page notification email
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 02:42:55 +00:00
|
|
|
// Mimic core code of only sending watchlist notification emails once per page
|
|
|
|
} elseif ( $type === "watchlist-change" || $type === "minor-watchlist-change" ) {
|
|
|
|
if ( !$wgEchoWatchlistEmailOncePerPage ) {
|
|
|
|
// Don't care about rate limiting
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$store = MediaWikiServices::getInstance()->getWatchedItemStore();
|
|
|
|
$ts = $store->getWatchedItem( $user, $event->getTitle() )->getNotificationTimestamp();
|
|
|
|
// if (ts != null) is not sufficient because, if $wgEchoUseJobQueue is set,
|
|
|
|
// wl_notificationtimestamp will have already been set for the new edit
|
|
|
|
// by the time this code runs.
|
|
|
|
if ( $ts !== null && $ts !== $event->getExtraParam( "timestamp" ) ) {
|
|
|
|
// User has already seen an email for this page before
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-01 19:27:32 +00:00
|
|
|
}
|
2019-12-09 02:42:55 +00:00
|
|
|
// Proceed to send notification email
|
2013-05-01 19:27:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
/**
|
|
|
|
* Get overrides for new users. This allows changes that only apply going forward,
|
|
|
|
* without affecting existing users.
|
|
|
|
*
|
2018-08-13 07:25:22 +00:00
|
|
|
* @return bool[] Associative array mapping key to bool for whether it should be enabled
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
*/
|
|
|
|
public static function getNewUserPreferenceOverrides() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
'echo-subscriptions-web-reverted' => false,
|
|
|
|
'echo-subscriptions-email-reverted' => false,
|
|
|
|
'echo-subscriptions-web-article-linked' => true,
|
|
|
|
'echo-subscriptions-email-mention' => true,
|
|
|
|
'echo-subscriptions-email-article-linked' => true,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
BREAKING CHANGE: Change $wgEchoDefaultNotificationTypes to be logical
Merge and deploy at the *same time* as:
* BounceHandler - I3c669945080d8e1f67880bd8a31af7f88a70904d
* mediawiki-config - I13817c139967ed9e230cfb0c87c5de66da793c96
Despite claiming to be about categories, $wgEchoDefaultNotificationTypes
was actually configuring both categories and types (which go inside
categories).
For example, 'thank-you-edit' is a type, but 'emailuser' is both
a category and a type (when used as a category, this has special
effects at Special:Preferences).
Since types and categories can and sometimes do have the same names,
this leaves no way to properly and clearly configure them. It also
makes it difficult to document what is going on (as required by
T132127).
Split into three variables:
$wgDefaultNotifyTypeAvailability - Applies unless overriden
$wgNotifyTypeAvailabilityByCategory - By category; this can be and is
displayed at Special:Preferences
$wgNotifyTypeAvailabilityByNotificationType - By type; this cannot
be displayed at Special:Preferences. To avoid confusing the user,
we introduce a restriction (which was previously followed in practice,
AFAICT) that types can only be overridden if the category is not
displayed in preferences.
Otherwise, it can look to the user like a category is on/off, but the
types within might have the opposite state.
Due to this configuration change, this is a breaking change, and needs
coordinated deployments.
This also lays the groundwork for T132127
Also change terminology to consistently use "notify type" for web/email.
It was mixing between that and output format (which unfortunately
sounds like the API format, e.g. 'model').
Bug: T132820
Bug: T132127
Change-Id: I09f39f5fc5f13f3253af9f7819bca81f1601da93
2016-04-19 02:54:15 +00:00
|
|
|
}
|
|
|
|
|
2012-08-31 23:35:16 +00:00
|
|
|
/**
|
2016-05-25 19:03:29 +00:00
|
|
|
* Handler for LocalUserCreated hook.
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/LocalUserCreated
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user User object that was created.
|
|
|
|
* @param bool $autocreated True when account was auto-created
|
2012-08-31 23:35:16 +00:00
|
|
|
*/
|
2016-05-25 19:03:29 +00:00
|
|
|
public static function onLocalUserCreated( $user, $autocreated ) {
|
|
|
|
if ( !$autocreated ) {
|
|
|
|
$overrides = self::getNewUserPreferenceOverrides();
|
|
|
|
foreach ( $overrides as $prefKey => $value ) {
|
|
|
|
$user->setOption( $prefKey, $value );
|
|
|
|
}
|
|
|
|
$user->saveSettings();
|
2016-12-05 18:51:07 +00:00
|
|
|
EchoEvent::create( [
|
2016-05-25 19:03:29 +00:00
|
|
|
'type' => 'welcome',
|
|
|
|
'agent' => $user,
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2016-05-25 19:03:29 +00:00
|
|
|
}
|
2012-08-31 23:35:16 +00:00
|
|
|
|
2016-09-09 21:46:11 +00:00
|
|
|
$seenTime = EchoSeenTime::newFromUser( $user );
|
|
|
|
|
|
|
|
// Set seen time to UNIX epoch, so initially all notifications are unseen.
|
|
|
|
$seenTime->setTime( wfTimestamp( TS_MW, 1 ), 'all' );
|
2012-08-31 23:35:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 00:49:19 +00:00
|
|
|
/**
|
2015-09-22 18:16:59 +00:00
|
|
|
* Handler for UserGroupsChanged hook.
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserGroupsChanged
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
2015-09-22 18:16:59 +00:00
|
|
|
* @param User $user user that was changed
|
|
|
|
* @param string[] $add strings corresponding to groups added
|
|
|
|
* @param string[] $remove strings corresponding to groups removed
|
|
|
|
* @param User|bool $performer
|
2016-02-08 20:45:44 +00:00
|
|
|
* @param string|bool $reason Reason given by the user changing the rights
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param array $oldUGMs
|
|
|
|
* @param array $newUGMs
|
2013-03-13 00:49:19 +00:00
|
|
|
*/
|
2017-04-08 07:43:05 +00:00
|
|
|
public static function onUserGroupsChanged( $user, $add, $remove, $performer,
|
2017-11-12 01:54:19 +00:00
|
|
|
$reason = false, array $oldUGMs = [], array $newUGMs = [] ) {
|
2015-09-22 18:16:59 +00:00
|
|
|
if ( !$performer ) {
|
|
|
|
// TODO: Implement support for autopromotion
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2015-09-22 18:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$user instanceof User ) {
|
|
|
|
// TODO: Support UserRightsProxy
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2015-09-22 18:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $user->equals( $performer ) ) {
|
|
|
|
// Don't notify for self changes
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2015-09-22 18:16:59 +00:00
|
|
|
}
|
2013-03-13 00:49:19 +00:00
|
|
|
|
2017-04-08 07:43:05 +00:00
|
|
|
// If any old groups are in $add, those groups are having their expiry
|
|
|
|
// changed, not actually being added
|
|
|
|
$expiryChanged = [];
|
|
|
|
$reallyAdded = [];
|
|
|
|
foreach ( $add as $group ) {
|
|
|
|
if ( isset( $oldUGMs[$group] ) ) {
|
|
|
|
$expiryChanged[] = $group;
|
|
|
|
} else {
|
|
|
|
$reallyAdded[] = $group;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $expiryChanged ) {
|
|
|
|
// use a separate notification for these, so the notification text doesn't
|
|
|
|
// get too long
|
|
|
|
EchoEvent::create(
|
|
|
|
[
|
|
|
|
'type' => 'user-rights',
|
|
|
|
'extra' => [
|
2019-06-11 21:43:05 +00:00
|
|
|
'user' => $user->getId(),
|
2017-04-08 07:43:05 +00:00
|
|
|
'expiry-changed' => $expiryChanged,
|
|
|
|
'reason' => $reason,
|
|
|
|
],
|
|
|
|
'agent' => $performer,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $reallyAdded || $remove ) {
|
2013-03-13 00:49:19 +00:00
|
|
|
EchoEvent::create(
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2013-03-13 00:49:19 +00:00
|
|
|
'type' => 'user-rights',
|
2016-12-05 18:51:07 +00:00
|
|
|
'extra' => [
|
2019-06-11 21:43:05 +00:00
|
|
|
'user' => $user->getId(),
|
2017-04-08 07:43:05 +00:00
|
|
|
'add' => $reallyAdded,
|
2016-02-08 20:45:44 +00:00
|
|
|
'remove' => $remove,
|
|
|
|
'reason' => $reason,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2015-09-22 18:16:59 +00:00
|
|
|
'agent' => $performer,
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2013-03-13 00:49:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-26 22:05:29 +00:00
|
|
|
/**
|
|
|
|
* Handler for LinksUpdateAfterInsert hook.
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdateAfterInsert
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param LinksUpdate $linksUpdate
|
|
|
|
* @param string $table
|
2019-11-07 19:35:03 +00:00
|
|
|
* @param array[] $insertions
|
2012-12-26 22:05:29 +00:00
|
|
|
*/
|
|
|
|
public static function onLinksUpdateAfterInsert( $linksUpdate, $table, $insertions ) {
|
2015-10-27 23:17:25 +00:00
|
|
|
global $wgRequest;
|
2013-03-18 21:48:33 +00:00
|
|
|
|
2015-10-27 23:17:25 +00:00
|
|
|
// FIXME: This doesn't work in 1.27+
|
2013-03-18 21:48:33 +00:00
|
|
|
// Rollback or undo should not trigger link notification
|
|
|
|
// @Todo Implement a better solution so it doesn't depend on the checking of
|
|
|
|
// a specific set of request variables
|
|
|
|
if ( $wgRequest->getVal( 'wpUndidRevision' ) || $wgRequest->getVal( 'action' ) == 'rollback' ) {
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2013-03-18 21:48:33 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 00:13:58 +00:00
|
|
|
// Handle only
|
2013-05-01 20:48:12 +00:00
|
|
|
// 1. inserts to pagelinks table &&
|
2013-01-16 00:13:58 +00:00
|
|
|
// 2. content namespace pages &&
|
|
|
|
// 3. non-transcluding pages &&
|
|
|
|
// 4. non-redirect pages
|
|
|
|
if ( $table !== 'pagelinks' || !MWNamespace::isContent( $linksUpdate->mTitle->getNamespace() )
|
2015-10-01 13:48:52 +00:00
|
|
|
|| !$linksUpdate->mRecursive || $linksUpdate->mTitle->isRedirect()
|
|
|
|
) {
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2013-01-04 01:36:12 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 22:45:30 +00:00
|
|
|
$revision = $linksUpdate->getRevision();
|
|
|
|
$revid = $revision ? $revision->getId() : null;
|
|
|
|
$user = $revision ? $revision->getRevisionRecord()->getUser() : null;
|
2016-05-23 19:22:41 +00:00
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
// link notification is boundless as you can include infinite number of links in a page
|
|
|
|
// db insert is expensive, limit it to a reasonable amount, we can increase this limit
|
|
|
|
// once the storage is on Redis
|
|
|
|
$max = 10;
|
2013-01-08 23:57:28 +00:00
|
|
|
// Only create notifications for links to content namespace pages
|
2013-01-15 23:21:39 +00:00
|
|
|
// @Todo - use one big insert instead of individual insert inside foreach loop
|
2014-05-27 18:28:37 +00:00
|
|
|
foreach ( $insertions as $page ) {
|
2013-01-15 23:21:39 +00:00
|
|
|
if ( MWNamespace::isContent( $page['pl_namespace'] ) ) {
|
|
|
|
$title = Title::makeTitle( $page['pl_namespace'], $page['pl_title'] );
|
2013-05-03 16:30:29 +00:00
|
|
|
if ( $title->isRedirect() ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:43:05 +00:00
|
|
|
$linkFromPageId = $linksUpdate->mTitle->getArticleID();
|
2016-12-05 18:51:07 +00:00
|
|
|
EchoEvent::create( [
|
2013-01-15 23:21:39 +00:00
|
|
|
'type' => 'page-linked',
|
|
|
|
'title' => $title,
|
2015-10-27 23:17:25 +00:00
|
|
|
'agent' => $user,
|
2016-12-05 18:51:07 +00:00
|
|
|
'extra' => [
|
2016-07-27 14:52:18 +00:00
|
|
|
'target-page' => $linkFromPageId,
|
|
|
|
'link-from-page-id' => $linkFromPageId,
|
2016-05-23 19:22:41 +00:00
|
|
|
'revid' => $revid,
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
|
|
|
] );
|
2013-01-15 23:21:39 +00:00
|
|
|
$max--;
|
|
|
|
}
|
|
|
|
if ( $max < 0 ) {
|
|
|
|
break;
|
2013-01-04 01:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-26 22:05:29 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for BeforePageDisplay hook.
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
|
2018-06-17 16:56:02 +00:00
|
|
|
* @param OutputPage $out
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param Skin $skin Skin being used.
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2016-05-20 10:10:51 +00:00
|
|
|
public static function beforePageDisplay( $out, $skin ) {
|
2019-10-01 20:15:25 +00:00
|
|
|
if ( $out->getUser()->isLoggedIn() ) {
|
2012-11-01 21:59:53 +00:00
|
|
|
// Load the module for the Notifications flyout
|
2016-12-05 18:51:07 +00:00
|
|
|
$out->addModules( [ 'ext.echo.init' ] );
|
2013-05-15 23:10:49 +00:00
|
|
|
// Load the styles for the Notifications badge
|
2016-12-05 18:51:07 +00:00
|
|
|
$out->addModuleStyles( [
|
2015-09-16 19:48:56 +00:00
|
|
|
'ext.echo.styles.badge',
|
2019-04-13 18:45:11 +00:00
|
|
|
'oojs-ui.styles.icons-alerts'
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-03 17:01:06 +00:00
|
|
|
private static function processMarkAsRead( User $user, WebRequest $request, Title $title ) {
|
|
|
|
global $wgEchoCrossWikiNotifications;
|
|
|
|
$subtractions = [
|
|
|
|
EchoAttributeManager::ALERT => 0,
|
|
|
|
EchoAttributeManager::MESSAGE => 0
|
|
|
|
];
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2016-03-09 19:01:42 +00:00
|
|
|
// Attempt to mark a notification as read when visiting a page
|
2016-12-05 18:51:07 +00:00
|
|
|
$eventIds = [];
|
2014-08-07 00:07:34 +00:00
|
|
|
if ( $title->getArticleID() ) {
|
2016-03-04 19:23:02 +00:00
|
|
|
$eventMapper = new EchoEventMapper();
|
|
|
|
$events = $eventMapper->fetchUnreadByUserAndPage( $user, $title->getArticleID() );
|
|
|
|
|
2018-06-17 17:00:05 +00:00
|
|
|
foreach ( $events as $event ) {
|
2018-09-03 17:01:06 +00:00
|
|
|
$subtractions[$event->getSection()]++;
|
2018-06-17 17:00:05 +00:00
|
|
|
$eventIds[] = $event->getId();
|
2014-08-07 00:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-13 20:41:12 +00:00
|
|
|
|
|
|
|
// Attempt to mark as read the event IDs in the ?markasread= parameter, if present
|
2018-09-03 17:01:06 +00:00
|
|
|
$markAsReadIds = explode( '|', $request->getText( 'markasread' ) );
|
|
|
|
$markAsReadWiki = $request->getText( 'markasreadwiki', wfWikiID() );
|
|
|
|
$markAsReadLocal = !$wgEchoCrossWikiNotifications || $markAsReadWiki === wfWikiID();
|
2016-06-13 20:41:12 +00:00
|
|
|
if ( $markAsReadIds ) {
|
2018-09-03 17:01:06 +00:00
|
|
|
if ( $markAsReadLocal ) {
|
|
|
|
// gather the IDs that we didn't already find with target_pages
|
|
|
|
$eventsToMarkAsRead = [];
|
|
|
|
foreach ( $markAsReadIds as $markAsReadId ) {
|
|
|
|
$markAsReadId = intval( $markAsReadId );
|
|
|
|
if ( $markAsReadId !== 0 && !in_array( $markAsReadId, $eventIds ) ) {
|
|
|
|
$eventsToMarkAsRead[] = $markAsReadId;
|
|
|
|
}
|
2016-06-13 20:41:12 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 17:01:06 +00:00
|
|
|
if ( $eventsToMarkAsRead ) {
|
|
|
|
// fetch the notifications to adjust the counters
|
|
|
|
$notifMapper = new EchoNotificationMapper();
|
|
|
|
$notifs = $notifMapper->fetchByUserEvents( $user, $eventsToMarkAsRead );
|
|
|
|
|
|
|
|
foreach ( $notifs as $notif ) {
|
|
|
|
if ( !$notif->getReadTimestamp() ) {
|
|
|
|
$subtractions[$notif->getEvent()->getSection()]++;
|
|
|
|
$eventIds[] = intval( $notif->getEvent()->getId() );
|
2016-06-13 20:41:12 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-03 01:56:13 +00:00
|
|
|
}
|
2018-09-03 17:01:06 +00:00
|
|
|
} else {
|
2019-12-21 05:45:14 +00:00
|
|
|
$markAsReadIds = array_map( 'intval', $markAsReadIds );
|
2018-09-03 17:01:06 +00:00
|
|
|
// Look up the notifications on the foreign wiki
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
|
|
|
$notifInfo = $notifUser->getForeignNotificationInfo( $markAsReadIds, $markAsReadWiki );
|
|
|
|
foreach ( $notifInfo as $id => $info ) {
|
|
|
|
$subtractions[$info['section']]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Schedule a deferred update to mark these notifications as read on the foreign wiki
|
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $user, $markAsReadIds, $markAsReadWiki ) {
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
|
|
|
$notifUser->markReadForeign( $markAsReadIds, $markAsReadWiki );
|
|
|
|
} );
|
2016-05-03 01:56:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-13 20:41:12 +00:00
|
|
|
|
2018-09-03 17:01:06 +00:00
|
|
|
// Schedule a deferred update to mark local target_page and ?markasread= notifications as read
|
2016-05-03 01:56:13 +00:00
|
|
|
if ( $eventIds ) {
|
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $user, $eventIds ) {
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
|
|
|
$notifUser->markRead( $eventIds );
|
|
|
|
} );
|
|
|
|
}
|
2014-08-07 00:07:34 +00:00
|
|
|
|
2018-09-03 17:01:06 +00:00
|
|
|
return $subtractions;
|
|
|
|
}
|
|
|
|
|
2019-10-01 20:15:25 +00:00
|
|
|
/**
|
|
|
|
* Handler for SkinMinervaReplaceNotificationsBadge hook.
|
|
|
|
* @param User $user who needs notifications
|
|
|
|
* @param Title $title of current page
|
|
|
|
* @param string &$badge to replace
|
|
|
|
*/
|
|
|
|
public static function onSkinMinervaReplaceNotificationsBadge( $user, $title, &$badge ) {
|
|
|
|
$notificationsTitle = SpecialPage::getTitleFor( 'Notifications' );
|
|
|
|
$count = 0;
|
|
|
|
$countLabel = '';
|
|
|
|
$isZero = true;
|
|
|
|
$hasUnseen = false;
|
|
|
|
|
|
|
|
if ( $title->equals( $notificationsTitle ) ) {
|
|
|
|
// On Special:Notifications show no icon
|
|
|
|
$badge = '';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: `mw-ui-icon-wikimedia-bellOutline-base20` class is provided by Minerva.
|
|
|
|
// In future we'll likely want to rethink how this works and possibly consolidate this with the desktop badge.
|
|
|
|
// For now, we avoid loading two bells in the same place by reusing the class already defined in Minerva.
|
|
|
|
$notificationIconClass = 'mw-ui-icon mw-ui-icon-wikimedia-bellOutline-base20 mw-ui-icon-element user-button';
|
|
|
|
$url = $notificationsTitle->getLocalURL(
|
|
|
|
[ 'returnto' => $title->getPrefixedText() ] );
|
|
|
|
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
|
|
|
$count = $notifUser->getNotificationCount();
|
|
|
|
|
|
|
|
$echoSeenTime = EchoSeenTime::newFromUser( $user );
|
|
|
|
$seenAlertTime = $echoSeenTime->getTime( 'alert', TS_ISO_8601 );
|
|
|
|
$seenMsgTime = $echoSeenTime->getTime( 'message', TS_ISO_8601 );
|
|
|
|
|
|
|
|
$alertNotificationTimestamp = $notifUser->getLastUnreadAlertTime();
|
|
|
|
$msgNotificationTimestamp = $notifUser->getLastUnreadMessageTime();
|
|
|
|
|
|
|
|
$isZero = $count === 0;
|
|
|
|
$hasUnseen = $count > 0 &&
|
|
|
|
(
|
|
|
|
$seenMsgTime !== false && $msgNotificationTimestamp !== false &&
|
|
|
|
$seenMsgTime < $msgNotificationTimestamp->getTimestamp( TS_ISO_8601 )
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
$seenAlertTime !== false && $alertNotificationTimestamp !== false &&
|
|
|
|
$seenAlertTime < $alertNotificationTimestamp->getTimestamp( TS_ISO_8601 )
|
|
|
|
);
|
|
|
|
|
|
|
|
$countLabel = EchoNotificationController::formatNotificationCount( $count );
|
|
|
|
$data = [
|
|
|
|
'notificationIconClass' => $notificationIconClass,
|
|
|
|
'title' => $hasUnseen ?
|
|
|
|
wfMessage( 'echo-overlay-link' ) :
|
|
|
|
wfMessage( 'echo-none' ),
|
|
|
|
'url' => $url,
|
|
|
|
'notificationCountRaw' => $count,
|
|
|
|
'notificationCountString' => $countLabel,
|
|
|
|
'isNotificationCountZero' => $isZero,
|
|
|
|
'hasNotifications' => $hasUnseen,
|
|
|
|
// this variable is used inside the client side which has different handling
|
|
|
|
// for when notifications have been dismissed. Instead of a bell it shows `(0)`.
|
|
|
|
'hasUnseenNotifications' => $hasUnseen,
|
|
|
|
];
|
|
|
|
$parser = new TemplateParser( __DIR__ . '/../modules/mobile' );
|
|
|
|
// substitute the badge
|
|
|
|
$badge = $parser->processTemplate( 'NotificationBadge', $data );
|
|
|
|
}
|
|
|
|
|
2018-09-03 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* Handler for PersonalUrls hook.
|
|
|
|
* Add a "Notifications" item to the user toolbar ('personal URLs').
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
|
2018-09-03 17:01:06 +00:00
|
|
|
* @param array &$personal_urls Array of URLs to append to.
|
|
|
|
* @param Title &$title Title of page being visited.
|
|
|
|
* @param SkinTemplate $sk
|
|
|
|
*/
|
|
|
|
public static function onPersonalUrls( &$personal_urls, &$title, $sk ) {
|
|
|
|
$user = $sk->getUser();
|
|
|
|
if ( $user->isAnon() ) {
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2018-09-03 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$subtractions = self::processMarkAsRead( $user, $sk->getOutput()->getRequest(), $title );
|
|
|
|
|
2013-11-13 03:17:04 +00:00
|
|
|
// Add a "My notifications" item to personal URLs
|
2015-07-08 00:10:49 +00:00
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
2018-09-03 17:01:06 +00:00
|
|
|
$msgCount = $notifUser->getMessageCount() - $subtractions[EchoAttributeManager::MESSAGE];
|
|
|
|
$alertCount = $notifUser->getAlertCount() - $subtractions[EchoAttributeManager::ALERT];
|
2016-04-11 08:20:08 +00:00
|
|
|
// But make sure we never show a negative number (T130853)
|
|
|
|
$msgCount = max( 0, $msgCount );
|
|
|
|
$alertCount = max( 0, $alertCount );
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
$msgNotificationTimestamp = $notifUser->getLastUnreadMessageTime();
|
|
|
|
$alertNotificationTimestamp = $notifUser->getLastUnreadAlertTime();
|
|
|
|
|
2016-09-15 21:16:06 +00:00
|
|
|
$seenTime = EchoSeenTime::newFromUser( $user );
|
|
|
|
if ( $title->isSpecial( 'Notifications' ) ) {
|
|
|
|
// If this is the Special:Notifications page, seenTime to now
|
|
|
|
$seenTime->setTime( wfTimestamp( TS_MW ), EchoAttributeManager::ALL );
|
|
|
|
}
|
2016-09-23 18:46:44 +00:00
|
|
|
$seenAlertTime = $seenTime->getTime( 'alert', TS_ISO_8601 );
|
|
|
|
$seenMsgTime = $seenTime->getTime( 'message', TS_ISO_8601 );
|
2016-09-13 20:00:35 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$sk->getOutput()->addJsConfigVars( 'wgEchoSeenTime', [
|
2015-09-03 01:11:10 +00:00
|
|
|
'alert' => $seenAlertTime,
|
2016-07-22 18:59:10 +00:00
|
|
|
'notice' => $seenMsgTime,
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2017-03-12 13:04:20 +00:00
|
|
|
$msgFormattedCount = EchoNotificationController::formatNotificationCount( $msgCount );
|
|
|
|
$alertFormattedCount = EchoNotificationController::formatNotificationCount( $alertCount );
|
|
|
|
|
|
|
|
$msgText = wfMessage( 'echo-notification-notice', $msgCount );
|
|
|
|
$alertText = wfMessage( 'echo-notification-alert', $alertCount );
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2015-07-08 00:10:49 +00:00
|
|
|
$url = SpecialPage::getTitleFor( 'Notifications' )->getLocalURL();
|
|
|
|
|
2015-09-10 17:15:30 +00:00
|
|
|
// HACK: inverted icons only work in the "MediaWiki" OOUI theme
|
|
|
|
// Avoid flashes in skins that don't use it (T111821)
|
2018-08-25 10:51:14 +00:00
|
|
|
$sk->getOutput()->setupOOUI(
|
|
|
|
strtolower( $sk->getSkinName() ), $sk->getOutput()->getLanguage()->getDir() );
|
2015-09-10 17:15:30 +00:00
|
|
|
|
2019-04-13 18:45:11 +00:00
|
|
|
$msgLinkClasses = [ "mw-echo-notifications-badge", "mw-echo-notification-badge-nojs","oo-ui-icon-tray" ];
|
|
|
|
$alertLinkClasses = [ "mw-echo-notifications-badge", "mw-echo-notification-badge-nojs", "oo-ui-icon-bell" ];
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2015-09-15 22:58:13 +00:00
|
|
|
$hasUnseen = false;
|
2015-07-08 00:10:49 +00:00
|
|
|
if (
|
2015-08-13 00:54:16 +00:00
|
|
|
$msgCount != 0 && // no unread notifications
|
|
|
|
$msgNotificationTimestamp !== false && // should already always be false if count === 0
|
2018-08-25 10:51:14 +00:00
|
|
|
// there are no unseen notifications
|
|
|
|
( $seenMsgTime === null ||
|
|
|
|
$seenMsgTime < $msgNotificationTimestamp->getTimestamp( TS_ISO_8601 ) )
|
2015-07-08 00:10:49 +00:00
|
|
|
) {
|
2015-08-13 00:54:16 +00:00
|
|
|
$msgLinkClasses[] = 'mw-echo-unseen-notifications';
|
2015-09-15 22:58:13 +00:00
|
|
|
$hasUnseen = true;
|
2016-07-20 00:24:17 +00:00
|
|
|
} elseif ( $msgCount === 0 ) {
|
|
|
|
$msgLinkClasses[] = 'mw-echo-notifications-badge-all-read';
|
2013-11-13 03:17:04 +00:00
|
|
|
}
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-12-20 18:40:54 +00:00
|
|
|
if ( $msgCount > MWEchoNotifUser::MAX_BADGE_COUNT ) {
|
|
|
|
$msgLinkClasses[] = 'mw-echo-notifications-badge-long-label';
|
|
|
|
}
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
if (
|
|
|
|
$alertCount != 0 && // no unread notifications
|
|
|
|
$alertNotificationTimestamp !== false && // should already always be false if count === 0
|
2018-08-25 10:51:14 +00:00
|
|
|
// all notifications have already been seen
|
|
|
|
( $seenAlertTime === null ||
|
|
|
|
$seenAlertTime < $alertNotificationTimestamp->getTimestamp( TS_ISO_8601 ) )
|
2015-08-13 00:54:16 +00:00
|
|
|
) {
|
|
|
|
$alertLinkClasses[] = 'mw-echo-unseen-notifications';
|
2015-09-15 22:58:13 +00:00
|
|
|
$hasUnseen = true;
|
2016-07-20 00:24:17 +00:00
|
|
|
} elseif ( $alertCount === 0 ) {
|
|
|
|
$alertLinkClasses[] = 'mw-echo-notifications-badge-all-read';
|
2015-08-13 00:54:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 21:08:27 +00:00
|
|
|
if ( $alertCount > MWEchoNotifUser::MAX_BADGE_COUNT ) {
|
2016-12-20 18:40:54 +00:00
|
|
|
$alertLinkClasses[] = 'mw-echo-notifications-badge-long-label';
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$alertLink = [
|
2015-07-08 00:10:49 +00:00
|
|
|
'href' => $url,
|
2015-08-13 00:54:16 +00:00
|
|
|
'text' => $alertText,
|
2019-06-11 21:43:05 +00:00
|
|
|
'active' => ( $url == $title->getLocalURL() ),
|
2015-08-13 00:54:16 +00:00
|
|
|
'class' => $alertLinkClasses,
|
2016-12-05 18:51:07 +00:00
|
|
|
'data' => [
|
2016-07-20 00:24:17 +00:00
|
|
|
'counter-num' => $alertCount,
|
2017-03-12 13:04:20 +00:00
|
|
|
'counter-text' => $alertFormattedCount,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
];
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$insertUrls = [
|
2015-09-07 23:54:47 +00:00
|
|
|
'notifications-alert' => $alertLink,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-07-08 00:10:49 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$msgLink = [
|
2016-02-23 09:20:24 +00:00
|
|
|
'href' => $url,
|
|
|
|
'text' => $msgText,
|
2019-06-11 21:43:05 +00:00
|
|
|
'active' => ( $url == $title->getLocalURL() ),
|
2016-02-23 09:20:24 +00:00
|
|
|
'class' => $msgLinkClasses,
|
2016-12-05 18:51:07 +00:00
|
|
|
'data' => [
|
2016-07-20 00:24:17 +00:00
|
|
|
'counter-num' => $msgCount,
|
2017-03-12 13:04:20 +00:00
|
|
|
'counter-text' => $msgFormattedCount,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
|
|
|
];
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-07-21 18:19:17 +00:00
|
|
|
$insertUrls['notifications-notice'] = $msgLink;
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2015-07-08 00:10:49 +00:00
|
|
|
$personal_urls = wfArrayInsertAfter( $personal_urls, $insertUrls, 'userpage' );
|
2013-11-13 03:17:04 +00:00
|
|
|
|
2015-09-15 22:58:13 +00:00
|
|
|
if ( $hasUnseen ) {
|
2019-06-12 22:38:01 +00:00
|
|
|
// Record that the user is going to see an indicator that they have unseen notifications
|
|
|
|
// This is part of tracking how likely users are to click a badge with unseen notifications.
|
|
|
|
// The other part is the 'echo.unseen.click' counter, see ext.echo.init.js.
|
2017-03-17 11:16:28 +00:00
|
|
|
MediaWikiServices::getInstance()->getStatsdDataFactory()->increment( 'echo.unseen' );
|
2015-09-15 22:58:13 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 03:17:04 +00:00
|
|
|
// If the user has new messages, display a talk page alert
|
2015-09-14 17:34:44 +00:00
|
|
|
// We need to check:
|
|
|
|
// * User actually has new messages
|
|
|
|
// * User is not viewing their user talk page, as user_newtalk
|
2017-06-20 02:41:30 +00:00
|
|
|
// will not have been cleared yet. (bug T107655).
|
2015-07-07 00:46:37 +00:00
|
|
|
if ( $user->getNewtalk() && !$user->getTalkPage()->equals( $title ) ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
if ( Hooks::run( 'BeforeDisplayOrangeAlert', [ $user, $title ] ) ) {
|
2016-10-13 18:55:34 +00:00
|
|
|
$personal_urls['mytalk']['text'] = $sk->msg( 'echo-new-messages' )->text();
|
2016-12-05 18:51:07 +00:00
|
|
|
$personal_urls['mytalk']['class'] = [ 'mw-echo-alert' ];
|
2016-10-13 18:55:34 +00:00
|
|
|
$sk->getOutput()->addModuleStyles( 'ext.echo.styles.alert' );
|
|
|
|
}
|
2012-12-12 02:18:51 +00:00
|
|
|
}
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
2012-07-17 22:19:32 +00:00
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
2013-06-08 01:05:35 +00:00
|
|
|
* Handler for AbortTalkPageEmailNotification hook.
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/AbortTalkPageEmailNotification
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $targetUser
|
|
|
|
* @param Title $title
|
2013-06-08 01:05:35 +00:00
|
|
|
* @return bool
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2016-05-20 10:10:51 +00:00
|
|
|
public static function onAbortTalkPageEmailNotification( $targetUser, $title ) {
|
2013-06-08 01:05:35 +00:00
|
|
|
global $wgEchoNotifications;
|
|
|
|
|
|
|
|
// Send legacy talk page email notification if
|
|
|
|
// 1. echo is disabled for them or
|
|
|
|
// 2. echo talk page notification is disabled
|
2015-06-01 23:22:48 +00:00
|
|
|
if ( !isset( $wgEchoNotifications['edit-user-talk'] ) ) {
|
2013-06-08 01:05:35 +00:00
|
|
|
// Legacy talk page email notification
|
|
|
|
return true;
|
2012-11-16 21:03:57 +00:00
|
|
|
}
|
2013-06-08 01:05:35 +00:00
|
|
|
|
|
|
|
// Echo talk page email notification
|
|
|
|
return false;
|
2012-07-17 22:19:32 +00:00
|
|
|
}
|
2012-07-31 21:18:16 +00:00
|
|
|
|
2014-02-21 01:48:08 +00:00
|
|
|
/**
|
|
|
|
* Handler for AbortWatchlistEmailNotification hook.
|
2018-10-23 20:35:09 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/AbortWatchlistEmailNotification
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $targetUser
|
|
|
|
* @param Title $title
|
|
|
|
* @param EmailNotification $emailNotification The email notification object that sends non-echo notifications
|
2014-02-21 01:48:08 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2016-05-20 10:10:51 +00:00
|
|
|
public static function onSendWatchlistEmailNotification( $targetUser, $title, $emailNotification ) {
|
2019-12-09 02:42:55 +00:00
|
|
|
global $wgEchoNotifications, $wgEchoWatchlistNotifications;
|
|
|
|
if ( $wgEchoWatchlistNotifications && isset( $wgEchoNotifications["watchlist-change"] ) ) {
|
|
|
|
// Let echo handle watchlist notifications entirely
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-21 01:48:08 +00:00
|
|
|
// If a user is watching his/her own talk page, do not send talk page watchlist
|
|
|
|
// email notification if the user is receiving Echo talk page notification
|
|
|
|
if ( $title->isTalkPage() && $targetUser->getTalkPage()->equals( $title ) ) {
|
2014-07-22 21:33:22 +00:00
|
|
|
$attributeManager = EchoAttributeManager::newFromGlobalVars();
|
|
|
|
$events = $attributeManager->getUserEnabledEvents( $targetUser, 'email' );
|
2015-06-01 23:22:48 +00:00
|
|
|
if ( in_array( 'edit-user-talk', $events ) ) {
|
2014-02-21 01:48:08 +00:00
|
|
|
// Do not send watchlist email notification, the user will receive an Echo notification
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-02-21 01:48:08 +00:00
|
|
|
// Proceed to send watchlist email notification
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:16:14 +00:00
|
|
|
public static function onOutputPageCheckLastModified( array &$modifiedTimes, OutputPage $out ) {
|
|
|
|
$user = $out->getUser();
|
2016-05-10 23:56:07 +00:00
|
|
|
if ( $user->isLoggedIn() ) {
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
|
|
|
$lastUpdate = $notifUser->getGlobalUpdateTime();
|
|
|
|
if ( $lastUpdate !== false ) {
|
2016-08-15 23:41:44 +00:00
|
|
|
$modifiedTimes['notifications-global'] = $lastUpdate;
|
2016-05-10 23:56:07 +00:00
|
|
|
}
|
2016-09-06 17:38:01 +00:00
|
|
|
|
2016-09-13 20:00:35 +00:00
|
|
|
$modifiedTimes['notifications-seen-alert'] = EchoSeenTime::newFromUser( $user )->getTime( 'alert' );
|
|
|
|
$modifiedTimes['notifications-seen-message'] = EchoSeenTime::newFromUser( $user )->getTime( 'message' );
|
2016-05-10 23:56:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-01 21:59:53 +00:00
|
|
|
/**
|
2013-05-05 00:49:08 +00:00
|
|
|
* Handler for GetNewMessagesAlert hook.
|
|
|
|
* We're using the GetNewMessagesAlert hook instead of the
|
|
|
|
* ArticleEditUpdateNewTalk hook since we still want the user_newtalk data
|
2018-11-16 00:23:25 +00:00
|
|
|
* to be updated and available to client-side tools and the API.
|
2018-10-30 16:52:08 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetNewMessagesAlert
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param string &$newMessagesAlert An alert that the user has new messages
|
2013-05-05 00:49:08 +00:00
|
|
|
* or an empty string if the user does not (empty by default)
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param array $newtalks This will be empty if the user has no new messages
|
2013-05-05 00:49:08 +00:00
|
|
|
* or an Array containing links and revisions if there are new messages
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user The user who is loading the page
|
2018-06-17 16:56:02 +00:00
|
|
|
* @param OutputPage $out
|
2013-05-05 00:49:08 +00:00
|
|
|
* @return bool Should return false to prevent the new messages alert (OBOD)
|
|
|
|
* or true to allow the new messages alert
|
2012-11-01 21:59:53 +00:00
|
|
|
*/
|
2016-05-20 10:10:51 +00:00
|
|
|
public static function abortNewMessagesAlert( &$newMessagesAlert, $newtalks, $user, $out ) {
|
2013-03-20 01:10:23 +00:00
|
|
|
global $wgEchoNotifications;
|
2013-06-08 01:05:35 +00:00
|
|
|
|
2012-11-01 21:59:53 +00:00
|
|
|
// If the user has the notifications flyout turned on and is receiving
|
2013-05-05 00:49:08 +00:00
|
|
|
// notifications for talk page messages, disable the new messages alert.
|
|
|
|
if ( $user->isLoggedIn()
|
2013-03-20 01:10:23 +00:00
|
|
|
&& isset( $wgEchoNotifications['edit-user-talk'] )
|
|
|
|
) {
|
2013-05-05 00:49:08 +00:00
|
|
|
// hide new messages alert
|
2012-11-01 21:59:53 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
2013-05-05 00:49:08 +00:00
|
|
|
// show new messages alert
|
2012-11-01 21:59:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-07-31 20:44:43 +00:00
|
|
|
}
|
2012-07-18 19:39:33 +00:00
|
|
|
|
2018-03-26 18:54:03 +00:00
|
|
|
/**
|
|
|
|
* Handler for ArticleRollbackComplete hook.
|
2018-10-30 16:52:08 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleRollbackComplete
|
2018-03-26 18:54:03 +00:00
|
|
|
*
|
|
|
|
* @param WikiPage $wikiPage The article that was edited
|
|
|
|
* @param User $agent The user who did the rollback
|
|
|
|
* @param Revision $newRevision The revision the page was reverted back to
|
|
|
|
* @param Revision $oldRevision The revision of the top edit that was reverted
|
|
|
|
*/
|
|
|
|
public static function onRollbackComplete( WikiPage $wikiPage, $agent, $newRevision, $oldRevision ) {
|
|
|
|
$victimId = $oldRevision->getUser();
|
2019-04-17 15:46:06 +00:00
|
|
|
$latestRevision = $wikiPage->getRevisionRecord();
|
2018-03-26 22:32:30 +00:00
|
|
|
self::$lastRevertedRevision = $latestRevision;
|
2018-03-26 18:54:03 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
$victimId && // No notifications for anonymous users
|
|
|
|
!$oldRevision->getContent()->equals( $newRevision->getContent() ) // No notifications for null rollbacks
|
|
|
|
) {
|
|
|
|
EchoEvent::create( [
|
|
|
|
'type' => 'reverted',
|
|
|
|
'title' => $wikiPage->getTitle(),
|
|
|
|
'extra' => [
|
2018-03-26 22:32:30 +00:00
|
|
|
'revid' => $latestRevision->getId(),
|
2018-03-26 18:54:03 +00:00
|
|
|
'reverted-user-id' => $victimId,
|
|
|
|
'reverted-revision-id' => $oldRevision->getId(),
|
|
|
|
'method' => 'rollback',
|
|
|
|
],
|
|
|
|
'agent' => $agent,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 22:12:22 +00:00
|
|
|
/**
|
|
|
|
* Handler for UserSaveSettings hook.
|
2018-10-30 16:52:08 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSaveSettings
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user whose settings were saved
|
2013-04-12 22:12:22 +00:00
|
|
|
*/
|
2016-05-20 10:10:51 +00:00
|
|
|
public static function onUserSaveSettings( $user ) {
|
2013-11-21 00:31:01 +00:00
|
|
|
// Extensions like AbuseFilter might create an account, but
|
|
|
|
// the tables we need might not exist. Bug 57335
|
|
|
|
if ( !defined( 'MW_UPDATER' ) ) {
|
|
|
|
// Reset the notification count since it may have changed due to user
|
|
|
|
// option changes. This covers both explicit changes in the preferences
|
|
|
|
// and changes made through the options API (since both call this hook).
|
2016-12-08 20:50:03 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $user ) {
|
|
|
|
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount();
|
|
|
|
} );
|
2013-11-21 00:31:01 +00:00
|
|
|
}
|
2013-04-12 22:12:22 +00:00
|
|
|
}
|
2013-04-26 16:08:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for UserLoadOptions hook.
|
2018-10-30 16:52:08 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserLoadOptions
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user User whose options were loaded
|
|
|
|
* @param array &$options Options can be modified
|
2013-04-26 16:08:40 +00:00
|
|
|
*/
|
|
|
|
public static function onUserLoadOptions( $user, &$options ) {
|
2019-12-09 02:42:55 +00:00
|
|
|
global $wgEchoWatchlistNotifications;
|
2013-05-09 21:23:15 +00:00
|
|
|
// Use existing enotifusertalkpages option for echo-subscriptions-email-edit-user-talk
|
|
|
|
if ( isset( $options['enotifusertalkpages'] ) ) {
|
2015-10-01 13:48:52 +00:00
|
|
|
$options['echo-subscriptions-email-edit-user-talk'] = $options['enotifusertalkpages'];
|
2013-04-26 16:08:40 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2019-12-09 02:42:55 +00:00
|
|
|
if ( $wgEchoWatchlistNotifications ) {
|
|
|
|
// Use existing enotifwatchlistpages option for echo-subscriptions-email-watchlist
|
|
|
|
if ( isset( $options['enotifwatchlistpages'] ) ) {
|
|
|
|
$options['echo-subscriptions-email-watchlist'] = $options['enotifwatchlistpages'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use existing enotifminoredits option for echo-subscriptions-email-minor-watchlist
|
|
|
|
if ( isset( $options['enotifminoredits'] ) ) {
|
|
|
|
$options['echo-subscriptions-email-minor-watchlist'] = $options['enotifminoredits'];
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 16:08:40 +00:00
|
|
|
}
|
2013-04-30 02:53:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for UserSaveOptions hook.
|
2018-10-30 16:52:08 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSaveOptions
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user User whose options are being saved
|
|
|
|
* @param array &$options Options can be modified
|
2013-04-30 02:53:33 +00:00
|
|
|
*/
|
|
|
|
public static function onUserSaveOptions( $user, &$options ) {
|
2019-12-09 02:42:55 +00:00
|
|
|
global $wgEchoWatchlistNotifications;
|
|
|
|
// save virtual option values in corresponding real option values
|
2013-05-09 21:23:15 +00:00
|
|
|
if ( isset( $options['echo-subscriptions-email-edit-user-talk'] ) ) {
|
|
|
|
$options['enotifusertalkpages'] = $options['echo-subscriptions-email-edit-user-talk'];
|
|
|
|
unset( $options['echo-subscriptions-email-edit-user-talk'] );
|
2013-04-30 02:53:33 +00:00
|
|
|
}
|
2019-12-09 02:42:55 +00:00
|
|
|
if ( $wgEchoWatchlistNotifications ) {
|
|
|
|
if ( isset( $options['echo-subscriptions-email-watchlist'] ) ) {
|
|
|
|
$options['enotifwatchlistpages'] = $options['echo-subscriptions-email-watchlist'];
|
|
|
|
unset( $options['echo-subscriptions-email-watchlist'] );
|
|
|
|
}
|
|
|
|
if ( isset( $options['echo-subscriptions-email-minor-watchlist'] ) ) {
|
|
|
|
$options['enotifminoredits'] = $options['echo-subscriptions-email-minor-watchlist'];
|
|
|
|
unset( $options['echo-subscriptions-email-minor-watchlist'] );
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 02:53:33 +00:00
|
|
|
}
|
2013-05-24 22:51:47 +00:00
|
|
|
|
2017-11-13 16:36:11 +00:00
|
|
|
/**
|
|
|
|
* Convert all values in an array to integers and filter out zeroes.
|
|
|
|
*
|
|
|
|
* @param array $numbers
|
|
|
|
*
|
|
|
|
* @return int[]
|
|
|
|
*/
|
|
|
|
protected static function mapToInt( array $numbers ) {
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
foreach ( $numbers as $value ) {
|
|
|
|
$int = intval( $value );
|
|
|
|
if ( $int === 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$data[] = $int;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2013-05-24 22:51:47 +00:00
|
|
|
/**
|
|
|
|
* Handler for UserClearNewTalkNotification hook.
|
2018-10-30 16:52:08 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserClearNewTalkNotification
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user User whose talk page notification should be marked as read
|
2013-05-24 22:51:47 +00:00
|
|
|
*/
|
|
|
|
public static function onUserClearNewTalkNotification( User $user ) {
|
|
|
|
if ( !$user->isAnon() ) {
|
2015-10-01 13:48:52 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $user ) {
|
2018-05-31 23:33:23 +00:00
|
|
|
MWEchoNotifUser::newFromUser( $user )->clearUserTalkNotifications();
|
2015-08-26 23:31:58 +00:00
|
|
|
} );
|
2013-05-24 22:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 01:04:31 +00:00
|
|
|
/**
|
|
|
|
* Handler for ParserTestTables hook, makes sure that Echo's tables are present during tests
|
2018-10-30 16:52:08 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserTestTables
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param array &$tables List of DB tables to be used for parser tests
|
2014-06-26 01:04:31 +00:00
|
|
|
*/
|
|
|
|
public static function onParserTestTables( &$tables ) {
|
|
|
|
$tables[] = 'echo_event';
|
|
|
|
$tables[] = 'echo_notification';
|
|
|
|
$tables[] = 'echo_email_batch';
|
|
|
|
}
|
|
|
|
|
2015-09-19 20:49:34 +00:00
|
|
|
/**
|
|
|
|
* Handler for EmailUserComplete hook.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/EmailUserComplete
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param MailAddress $address Adress of receiving user
|
|
|
|
* @param MailAddress $from Adress of sending user
|
|
|
|
* @param string $subject Subject of the mail
|
|
|
|
* @param string $text Text of the mail
|
2015-09-19 20:49:34 +00:00
|
|
|
*/
|
|
|
|
public static function onEmailUserComplete( $address, $from, $subject, $text ) {
|
|
|
|
if ( $from->name === $address->name ) {
|
|
|
|
// nothing to notify
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2015-09-19 20:49:34 +00:00
|
|
|
}
|
|
|
|
$userTo = User::newFromName( $address->name );
|
|
|
|
$userFrom = User::newFromName( $from->name );
|
|
|
|
|
2016-02-10 22:09:41 +00:00
|
|
|
$autoSubject = wfMessage( 'defemailsubject', $from->name )->inContentLanguage()->text();
|
|
|
|
if ( $subject === $autoSubject ) {
|
2018-08-25 10:51:14 +00:00
|
|
|
$autoFooter = "\n\n-- \n" . wfMessage( 'emailuserfooter', $from->name, $address->name )
|
|
|
|
->inContentLanguage()->text();
|
2016-02-23 21:26:55 +00:00
|
|
|
$textWithoutFooter = preg_replace( '/' . preg_quote( $autoFooter, '/' ) . '$/', '', $text );
|
2018-08-13 21:29:50 +00:00
|
|
|
$preview = MediaWikiServices::getInstance()->getContentLanguage()
|
|
|
|
->truncateForVisual( $textWithoutFooter, 125 );
|
2016-02-10 22:09:41 +00:00
|
|
|
} else {
|
|
|
|
$preview = $subject;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
EchoEvent::create( [
|
2015-09-19 20:49:34 +00:00
|
|
|
'type' => 'emailuser',
|
2016-12-05 18:51:07 +00:00
|
|
|
'extra' => [
|
2015-09-19 20:49:34 +00:00
|
|
|
'to-user-id' => $userTo->getId(),
|
2016-02-10 22:09:41 +00:00
|
|
|
'preview' => $preview,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2015-09-19 20:49:34 +00:00
|
|
|
'agent' => $userFrom,
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2015-09-19 20:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 03:09:46 +00:00
|
|
|
/**
|
|
|
|
* For integration with the UserMerge extension.
|
|
|
|
*
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param array &$updateFields
|
2014-08-26 03:09:46 +00:00
|
|
|
*/
|
|
|
|
public static function onUserMergeAccountFields( &$updateFields ) {
|
|
|
|
// array( tableName, idField, textField )
|
2014-10-24 19:16:37 +00:00
|
|
|
$dbw = MWEchoDbFactory::newFromDefault()->getEchoDb( DB_MASTER );
|
2016-12-05 18:51:07 +00:00
|
|
|
$updateFields[] = [ 'echo_event', 'event_agent_id', 'db' => $dbw ];
|
|
|
|
$updateFields[] = [ 'echo_notification', 'notification_user', 'db' => $dbw, 'options' => [ 'IGNORE' ] ];
|
|
|
|
$updateFields[] = [ 'echo_email_batch', 'eeb_user_id', 'db' => $dbw, 'options' => [ 'IGNORE' ] ];
|
2014-08-26 03:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function onMergeAccountFromTo( User &$oldUser, User &$newUser ) {
|
2018-09-18 12:56:59 +00:00
|
|
|
$method = __METHOD__;
|
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $oldUser, $newUser, $method ) {
|
|
|
|
if ( !$newUser->isAnon() ) {
|
|
|
|
// Select notifications that are now sent to the same user
|
|
|
|
$dbw = MWEchoDbFactory::newFromDefault()->getEchoDb( DB_MASTER );
|
|
|
|
$attributeManager = EchoAttributeManager::newFromGlobalVars();
|
|
|
|
$selfIds = $dbw->selectFieldValues(
|
|
|
|
[ 'echo_notification', 'echo_event' ],
|
|
|
|
'event_id',
|
|
|
|
[
|
|
|
|
'notification_user' => $newUser->getId(),
|
|
|
|
'notification_event = event_id',
|
|
|
|
'notification_user = event_agent_id',
|
2019-02-15 20:25:27 +00:00
|
|
|
'event_type NOT IN (' . $dbw->makeList( $attributeManager->getNotifyAgentEvents() ) . ')'
|
2018-09-18 12:56:59 +00:00
|
|
|
],
|
|
|
|
$method
|
|
|
|
) ?: [];
|
|
|
|
|
|
|
|
// Select newer welcome notification(s)
|
|
|
|
$welcomeIds = $dbw->selectFieldValues(
|
|
|
|
[ 'echo_notification', 'echo_event' ],
|
|
|
|
'event_id',
|
|
|
|
[
|
|
|
|
'notification_user' => $newUser->getId(),
|
|
|
|
'notification_event = event_id',
|
|
|
|
'event_type' => 'welcome',
|
|
|
|
],
|
|
|
|
$method,
|
|
|
|
[
|
|
|
|
'ORDER BY' => 'notification_timestamp ASC',
|
|
|
|
'OFFSET' => 1,
|
|
|
|
]
|
|
|
|
) ?: [];
|
|
|
|
|
|
|
|
// Select newer milestone notifications (per milestone level)
|
|
|
|
$counts = [];
|
|
|
|
$thankYouIds = [];
|
|
|
|
$thankYouRows = $dbw->select(
|
|
|
|
[ 'echo_notification', 'echo_event' ],
|
2019-03-02 20:25:33 +00:00
|
|
|
EchoEvent::selectFields(),
|
2018-09-18 12:56:59 +00:00
|
|
|
[
|
|
|
|
'notification_user' => $newUser->getId(),
|
|
|
|
'notification_event = event_id',
|
|
|
|
'event_type' => 'thank-you-edit',
|
|
|
|
],
|
|
|
|
$method,
|
|
|
|
[ 'ORDER BY' => 'notification_timestamp ASC' ]
|
|
|
|
) ?: [];
|
|
|
|
foreach ( $thankYouRows as $row ) {
|
|
|
|
$event = EchoEvent::newFromRow( $row );
|
|
|
|
$editCount = $event ? $event->getExtraParam( 'editCount' ) : null;
|
|
|
|
if ( $editCount ) {
|
|
|
|
if ( isset( $counts[$editCount] ) ) {
|
|
|
|
$thankYouIds[] = $row->event_id;
|
|
|
|
} else {
|
|
|
|
$counts[$editCount] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete notifications
|
|
|
|
$ids = array_merge( $selfIds, $welcomeIds, $thankYouIds );
|
2020-01-29 04:01:51 +00:00
|
|
|
// @phan-suppress-next-line PhanImpossibleTypeComparison Each array in the merge may be empty
|
|
|
|
if ( $ids !== [] ) {
|
2018-09-18 12:56:59 +00:00
|
|
|
$dbw->delete(
|
|
|
|
'echo_notification',
|
|
|
|
[
|
|
|
|
'notification_user' => $newUser->getId(),
|
|
|
|
'notification_event' => $ids
|
|
|
|
],
|
|
|
|
$method
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 17:45:49 +00:00
|
|
|
MWEchoNotifUser::newFromUser( $oldUser )->resetNotificationCount();
|
2016-12-08 20:50:03 +00:00
|
|
|
if ( !$newUser->isAnon() ) {
|
2018-05-25 17:45:49 +00:00
|
|
|
MWEchoNotifUser::newFromUser( $newUser )->resetNotificationCount();
|
2016-12-08 20:50:03 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-08-26 03:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function onUserMergeAccountDeleteTables( &$tables ) {
|
2014-10-24 19:16:37 +00:00
|
|
|
$dbw = MWEchoDbFactory::newFromDefault()->getEchoDb( DB_MASTER );
|
2016-12-05 18:51:07 +00:00
|
|
|
$tables['echo_notification'] = [ 'notification_user', 'db' => $dbw ];
|
|
|
|
$tables['echo_email_batch'] = [ 'eeb_user_id', 'db' => $dbw ];
|
2014-08-26 03:09:46 +00:00
|
|
|
}
|
2015-12-08 18:54:44 +00:00
|
|
|
|
2017-06-22 08:03:10 +00:00
|
|
|
/**
|
|
|
|
* Sets custom login message for redirect from notification page
|
|
|
|
*
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param array &$messages
|
2017-06-22 08:03:10 +00:00
|
|
|
*/
|
2015-12-08 18:54:44 +00:00
|
|
|
public static function onLoginFormValidErrorMessages( &$messages ) {
|
|
|
|
$messages[] = 'echo-notification-loginrequired';
|
|
|
|
}
|
|
|
|
|
2019-07-18 21:51:19 +00:00
|
|
|
public static function getConfigVars( ResourceLoaderContext $context, Config $config ) {
|
2019-07-03 23:04:14 +00:00
|
|
|
return [
|
|
|
|
'EchoMaxNotificationCount' => MWEchoNotifUser::MAX_BADGE_COUNT,
|
2019-07-18 21:51:19 +00:00
|
|
|
'EchoPollForUpdates' => $config->get( 'EchoPollForUpdates' )
|
2019-07-03 23:04:14 +00:00
|
|
|
];
|
2016-02-18 22:36:58 +00:00
|
|
|
}
|
|
|
|
|
2019-07-20 07:07:05 +00:00
|
|
|
public static function getLoggerConfigVars( ResourceLoaderContext $context, Config $config ) {
|
|
|
|
$schemas = $config->get( 'EchoEventLoggingSchemas' );
|
|
|
|
return [
|
|
|
|
'EchoInteractionLogging' => $schemas['EchoInteraction']['enabled'] &&
|
|
|
|
ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' ),
|
|
|
|
'EchoEventLoggingVersion' => $config->get( 'EchoEventLoggingVersion' )
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-03-11 13:25:18 +00:00
|
|
|
/**
|
|
|
|
* @param WikiPage &$article
|
|
|
|
* @param User &$user
|
|
|
|
* @param string $reason
|
|
|
|
* @param int $articleId
|
|
|
|
* @param Content|null $content
|
|
|
|
* @param LogEntry $logEntry
|
|
|
|
*/
|
2018-08-25 10:51:14 +00:00
|
|
|
public static function onArticleDeleteComplete(
|
|
|
|
WikiPage &$article,
|
|
|
|
User &$user,
|
|
|
|
$reason,
|
|
|
|
$articleId,
|
2019-10-09 22:57:35 +00:00
|
|
|
?Content $content,
|
2018-08-25 10:51:14 +00:00
|
|
|
LogEntry $logEntry
|
|
|
|
) {
|
2016-07-27 14:52:18 +00:00
|
|
|
\DeferredUpdates::addCallableUpdate( function () use ( $articleId ) {
|
|
|
|
$eventMapper = new EchoEventMapper();
|
|
|
|
$eventIds = $eventMapper->fetchIdsByPage( $articleId );
|
|
|
|
EchoModerationController::moderate( $eventIds, true );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function onArticleUndelete( Title $title, $create, $comment, $oldPageId ) {
|
|
|
|
if ( $create ) {
|
|
|
|
\DeferredUpdates::addCallableUpdate( function () use ( $oldPageId ) {
|
|
|
|
$eventMapper = new EchoEventMapper();
|
|
|
|
$eventIds = $eventMapper->fetchIdsByPage( $oldPageId );
|
|
|
|
EchoModerationController::moderate( $eventIds, false );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-01 17:49:31 +00:00
|
|
|
/**
|
|
|
|
* Handler for SpecialMuteModifyFormFields hook
|
|
|
|
*
|
|
|
|
* @param SpecialMute $specialMute
|
|
|
|
* @param array &$fields
|
|
|
|
*/
|
|
|
|
public static function onSpecialMuteModifyFormFields( SpecialMute $specialMute, &$fields ) {
|
|
|
|
$echoPerUserBlacklist = MediaWikiServices::getInstance()->getMainConfig()->get( 'EchoPerUserBlacklist' );
|
|
|
|
if ( $echoPerUserBlacklist ) {
|
|
|
|
$fields[ 'echo-notifications-blacklist'] = [
|
|
|
|
'type' => 'check',
|
|
|
|
'label-message' => 'echo-specialmute-label-mute-notifications',
|
|
|
|
'default' => $specialMute->isTargetBlacklisted( 'echo-notifications-blacklist' ),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 02:42:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for RecentChange_save hook
|
|
|
|
*
|
|
|
|
* @param RecentChange $change The change that has just been made to the wiki
|
|
|
|
*/
|
|
|
|
public static function onRecentChangeSave( RecentChange $change ) {
|
|
|
|
global $wgEchoWatchlistNotifications;
|
|
|
|
if ( !$wgEchoWatchlistNotifications ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( $change->getAttribute( 'rc_minor' ) ) {
|
|
|
|
$type = 'minor-watchlist-change';
|
|
|
|
} else {
|
|
|
|
$type = 'watchlist-change';
|
|
|
|
}
|
|
|
|
EchoEvent::create( [
|
|
|
|
'type' => $type,
|
|
|
|
'title' => $change->getTitle(),
|
|
|
|
'extra' => [
|
|
|
|
'revid' => $change->getAttribute( "rc_this_oldid" ),
|
|
|
|
'logid' => $change->getAttribute( "rc_logid" ),
|
|
|
|
'status' => $change->mExtra["pageStatus"],
|
|
|
|
'timestamp' => $change->getAttribute( "rc_timestamp" )
|
|
|
|
],
|
|
|
|
'agent' => $change->getPerformer()
|
|
|
|
] );
|
|
|
|
}
|
2012-07-18 16:28:41 +00:00
|
|
|
}
|