2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
2016-02-29 06:13:25 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
class EchoHooks {
|
2012-11-16 21:03:57 +00:00
|
|
|
const EMAIL_NEVER = -1; // Never send email notifications
|
|
|
|
const EMAIL_IMMEDIATELY = 0; // Send email notificaitons immediately as they come in
|
|
|
|
const EMAIL_DAILY_DIGEST = 1; // Send daily email digests
|
|
|
|
const EMAIL_WEEKLY_DIGEST = 7; // Send weekly email digests
|
2013-06-24 00:22:08 +00:00
|
|
|
const EMAIL_FORMAT_HTML = 'html';
|
|
|
|
const EMAIL_FORMAT_PLAIN_TEXT = 'plain-text';
|
2012-05-17 00:29:37 +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,
|
2014-08-08 20:35:58 +00:00
|
|
|
$wgEchoConfig;
|
2013-02-16 02:20:34 +00:00
|
|
|
|
|
|
|
// allow extensions to define their own event
|
2015-06-01 18:36:35 +00:00
|
|
|
Hooks::run( 'BeforeCreateEchoEvent', array( &$wgEchoNotifications, &$wgEchoNotificationCategories, &$wgEchoNotificationIcons ) );
|
2013-02-16 02:20:34 +00:00
|
|
|
|
2013-03-06 21:22:17 +00:00
|
|
|
// turn schema off if eventLogging is not enabled
|
2015-01-07 18:26:29 +00:00
|
|
|
if ( !class_exists( 'EventLogging' ) ) {
|
2013-03-06 21:22:17 +00:00
|
|
|
foreach ( $wgEchoConfig['eventlogging'] as $schema => $property ) {
|
|
|
|
if ( $property['enabled'] ) {
|
|
|
|
$wgEchoConfig['eventlogging'][$schema]['enabled'] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-08 20:35:58 +00:00
|
|
|
}
|
2014-02-25 06:09:27 +00:00
|
|
|
|
2014-08-08 20:35:58 +00:00
|
|
|
public static function getNotificationSenderName() {
|
|
|
|
global $wgNotificationSenderName;
|
2014-02-25 06:09:27 +00:00
|
|
|
if ( $wgNotificationSenderName === null ) {
|
|
|
|
$wgNotificationSenderName = wfMessage( 'emailsender' )->inContentLanguage()->text();
|
|
|
|
}
|
|
|
|
|
2014-08-08 20:35:58 +00:00
|
|
|
return $wgNotificationSenderName;
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
|
2014-08-05 22:18:38 +00:00
|
|
|
/**
|
|
|
|
* ResourceLoaderTestModules hook handler
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
|
|
|
|
*
|
|
|
|
* @param array $testModules
|
|
|
|
* @param ResourceLoader $resourceLoader
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderTestModules( array &$testModules,
|
|
|
|
ResourceLoader $resourceLoader
|
|
|
|
) {
|
|
|
|
global $wgResourceModules;
|
|
|
|
|
|
|
|
$testModuleBoilerplate = array(
|
|
|
|
'localBasePath' => __DIR__,
|
|
|
|
'remoteExtPath' => 'Echo',
|
|
|
|
);
|
|
|
|
|
|
|
|
// 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'] ) ) {
|
|
|
|
$testFiles = array();
|
|
|
|
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
|
|
|
|
if ( count( $testFiles ) > 0 ) {
|
|
|
|
$testModules['qunit']["$key.tests"] = $testModuleBoilerplate + array(
|
|
|
|
'dependencies' => array( $key ),
|
|
|
|
'scripts' => $testFiles,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-01 18:58:37 +00:00
|
|
|
public static function onEventLoggingRegisterSchemas( array &$schemas ) {
|
|
|
|
global $wgEchoConfig;
|
|
|
|
foreach ( $wgEchoConfig['eventlogging'] as $schema => $property ) {
|
2015-07-08 19:29:00 +00:00
|
|
|
if ( $property['enabled'] && $property['client'] ) {
|
2015-06-01 18:58:37 +00:00
|
|
|
$schemas[$schema] = $property['revision'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 00:26:59 +00:00
|
|
|
/**
|
|
|
|
* Handler for ResourceLoaderRegisterModules hook
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) {
|
2015-06-01 18:58:37 +00:00
|
|
|
global $wgEchoConfig;
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
// ext.echo.logger is used by mobile notifications as well, so be sure not to add any
|
2015-06-01 18:58:37 +00:00
|
|
|
// dependencies that do not target mobile.
|
|
|
|
$definition = array(
|
|
|
|
'position' => 'top',
|
|
|
|
'scripts' => array(
|
2015-08-13 00:54:16 +00:00
|
|
|
'logger/mw.echo.Logger.js',
|
|
|
|
),
|
|
|
|
'dependencies' => array(
|
|
|
|
'oojs'
|
2015-06-01 18:58:37 +00:00
|
|
|
),
|
|
|
|
'localBasePath' => __DIR__ . '/modules',
|
|
|
|
'remoteExtPath' => 'Echo/modules',
|
|
|
|
'targets' => array( 'desktop', 'mobile' ),
|
|
|
|
);
|
2013-03-01 00:26:59 +00:00
|
|
|
|
2015-09-16 19:29:01 +00:00
|
|
|
$hasSchemas = false;
|
2013-03-01 00:26:59 +00:00
|
|
|
foreach ( $wgEchoConfig['eventlogging'] as $schema => $property ) {
|
2015-07-08 19:29:00 +00:00
|
|
|
if ( $property['enabled'] && $property['client'] ) {
|
2015-06-01 18:58:37 +00:00
|
|
|
$definition['dependencies'][] = 'schema.' . $schema;
|
2015-09-16 19:29:01 +00:00
|
|
|
$hasSchemas = true;
|
2013-03-01 00:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 19:29:01 +00:00
|
|
|
if ( $hasSchemas ) {
|
|
|
|
$definition['dependencies'][] = 'ext.eventLogging';
|
|
|
|
}
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
$resourceLoader->register( 'ext.echo.logger', $definition );
|
2013-03-01 00:26:59 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* @param $updater DatabaseUpdater object
|
|
|
|
*/
|
2015-06-02 00:28:25 +00:00
|
|
|
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
|
|
|
|
global $wgEchoCluster;
|
|
|
|
if ( $wgEchoCluster !== false ) {
|
|
|
|
// DatabaseUpdater does not support other databases, so skip
|
|
|
|
return;
|
|
|
|
}
|
2012-08-31 21:50:46 +00:00
|
|
|
$dir = __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' ) {
|
|
|
|
$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" );
|
2015-03-16 15:47:13 +00:00
|
|
|
$updater->addExtensionField( 'echo_target_page', 'etp_id', "$dir/db_patches/patch-multiple_target_pages.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 {
|
|
|
|
$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" );
|
2015-03-16 15:47:13 +00:00
|
|
|
$updater->addExtensionField( 'echo_target_page', 'etp_id', "$dir/db_patches/patch-multiple_target_pages.sql" );
|
2013-05-20 17:23:51 +00:00
|
|
|
}
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
$updater->addExtensionField( 'echo_notification', 'notification_bundle_base',
|
|
|
|
"$dir/db_patches/patch-notification-bundling-field.sql" );
|
2013-05-20 17:23:51 +00:00
|
|
|
// This index was renamed twice, first from type_page to event_type and later from event_type to echo_event_type
|
|
|
|
if ( $updater->getDB()->indexExists( 'echo_event', 'type_page', __METHOD__ ) ) {
|
|
|
|
$updater->addExtensionIndex( 'echo_event', 'event_type', "$dir/db_patches/patch-alter-type_page-index.sql" );
|
|
|
|
}
|
2013-03-26 00:57:42 +00:00
|
|
|
$updater->dropTable( 'echo_subscription' );
|
|
|
|
$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" );
|
2013-05-09 18:50:05 +00:00
|
|
|
$updater->addExtensionField( 'echo_event', 'event_page_id', "$dir/db_patches/patch-add-echo_event-event_page_id.sql" );
|
2013-05-20 17:23:51 +00:00
|
|
|
$updater->addExtensionIndex( 'echo_event', 'echo_event_type', "$dir/db_patches/patch-alter-event_type-index.sql" );
|
2013-06-14 20:14:21 +00:00
|
|
|
$updater->addExtensionIndex( 'echo_notification', 'echo_user_timestamp', "$dir/db_patches/patch-alter-user_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
|
|
|
*
|
2013-01-15 23:21:39 +00:00
|
|
|
* @param $event EchoEvent
|
|
|
|
* @param $bundleString string Determines how the notification should be bundled, for example,
|
|
|
|
* 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
|
|
|
|
*
|
2014-05-27 18:28:37 +00:00
|
|
|
* @return bool
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
|
|
|
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;
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-30 23:14:57 +00:00
|
|
|
/**
|
|
|
|
* Handler for the GetBetaFeaturePreferences hook.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetBetaFeaturePreferences
|
|
|
|
*
|
|
|
|
* @param $user User to get preferences for
|
|
|
|
* @param &$preferences Preferences array
|
|
|
|
*
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
public static function getBetaFeaturePreferences( User $user, array &$preferences ) {
|
|
|
|
global $wgExtensionAssetsPath, $wgEchoUseCrossWikiBetaFeature;
|
|
|
|
|
|
|
|
if ( $wgEchoUseCrossWikiBetaFeature ) {
|
|
|
|
$preferences['echo-cross-wiki-notifications'] = array(
|
|
|
|
'label-message' => 'echo-pref-beta-feature-cross-wiki-message',
|
|
|
|
'desc-message' => 'echo-pref-beta-feature-cross-wiki-description',
|
|
|
|
// Paths to images that represents the feature.
|
|
|
|
'screenshot' => array(
|
|
|
|
'rtl' => "$wgExtensionAssetsPath/Echo/images/betafeatures-icon-notifications-rtl.svg",
|
|
|
|
'ltr' => "$wgExtensionAssetsPath/Echo/images/betafeatures-icon-notifications-ltr.svg",
|
|
|
|
),
|
2016-01-15 19:00:12 +00:00
|
|
|
'info-link' => 'https://www.mediawiki.org/wiki/Special:Mylanguage/Help:Notifications/Cross-wiki',
|
2015-11-30 23:14:57 +00:00
|
|
|
// Link to discussion about the feature - talk pages might work
|
2016-01-15 19:00:12 +00:00
|
|
|
'discussion-link' => 'https://www.mediawiki.org/wiki/Help_talk:Notifications',
|
2015-11-30 23:14:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for GetPreferences hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
2012-05-17 00:29:37 +00:00
|
|
|
* @param $user User to get preferences for
|
|
|
|
* @param &$preferences Preferences array
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
|
|
|
* @throws MWException
|
2012-09-02 09:30:38 +00:00
|
|
|
* @return bool true in all cases
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public static function getPreferences( $user, &$preferences ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
global $wgEchoDefaultNotificationTypes, $wgAuth, $wgEchoEnableEmailBatch,
|
2013-05-01 20:48:12 +00:00
|
|
|
$wgEchoNotifiers, $wgEchoNotificationCategories, $wgEchoNotifications,
|
2014-05-27 18:28:37 +00:00
|
|
|
$wgEchoNewMsgAlert, $wgAllowHTMLEmail;
|
2012-11-16 21:03:57 +00:00
|
|
|
|
|
|
|
// Show email frequency options
|
|
|
|
$never = wfMessage( 'echo-pref-email-frequency-never' )->plain();
|
|
|
|
$immediately = wfMessage( 'echo-pref-email-frequency-immediately' )->plain();
|
2012-12-14 20:48:41 +00:00
|
|
|
$freqOptions = array(
|
|
|
|
$never => self::EMAIL_NEVER,
|
|
|
|
$immediately => self::EMAIL_IMMEDIATELY,
|
|
|
|
);
|
|
|
|
// Only show digest options if email batch is enabled
|
|
|
|
if ( $wgEchoEnableEmailBatch ) {
|
|
|
|
$daily = wfMessage( 'echo-pref-email-frequency-daily' )->plain();
|
|
|
|
$weekly = wfMessage( 'echo-pref-email-frequency-weekly' )->plain();
|
|
|
|
$freqOptions += array(
|
|
|
|
$daily => self::EMAIL_DAILY_DIGEST,
|
|
|
|
$weekly => self::EMAIL_WEEKLY_DIGEST
|
|
|
|
);
|
|
|
|
}
|
2012-11-16 21:03:57 +00:00
|
|
|
$preferences['echo-email-frequency'] = array(
|
|
|
|
'type' => 'select',
|
2013-04-18 00:44:20 +00:00
|
|
|
'label-message' => 'echo-pref-send-me',
|
|
|
|
'section' => 'echo/emailsettings',
|
2012-12-14 20:48:41 +00:00
|
|
|
'options' => $freqOptions
|
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' );
|
|
|
|
$link = Linker::link(
|
|
|
|
SpecialPage::getTitleFor( 'ChangeEmail' ),
|
|
|
|
wfMessage( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->escaped(),
|
|
|
|
array(),
|
|
|
|
array( 'returnto' => $prefsTitle->getFullText() )
|
|
|
|
);
|
|
|
|
$emailAddress = $user->getEmail() ? htmlspecialchars( $user->getEmail() ) : '';
|
|
|
|
if ( $wgAuth->allowPropChange( 'emailaddress' ) ) {
|
|
|
|
if ( $emailAddress === '' ) {
|
|
|
|
$emailAddress .= $link;
|
|
|
|
} else {
|
|
|
|
$emailAddress .= wfMessage( 'word-separator' )->escaped()
|
|
|
|
. wfMessage( 'parentheses' )->rawParams( $link )->escaped();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$preferences['echo-emailaddress'] = array(
|
|
|
|
'type' => 'info',
|
|
|
|
'raw' => true,
|
2013-04-18 00:44:20 +00:00
|
|
|
'default' => $emailAddress,
|
|
|
|
'label-message' => 'echo-pref-send-to',
|
|
|
|
'section' => 'echo/emailsettings'
|
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
|
|
|
|
$preferences['echo-email-format'] = array(
|
|
|
|
'type' => 'select',
|
|
|
|
'label-message' => 'echo-pref-email-format',
|
|
|
|
'section' => 'echo/emailsettings',
|
2015-10-01 13:48:52 +00:00
|
|
|
'options' => array(
|
2013-06-24 00:22:08 +00:00
|
|
|
wfMessage( 'echo-pref-email-format-html' )->plain() => self::EMAIL_FORMAT_HTML,
|
|
|
|
wfMessage( 'echo-pref-email-format-plain-text' )->plain() => self::EMAIL_FORMAT_PLAIN_TEXT
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-16 02:20:34 +00:00
|
|
|
// Sort notification categories by priority
|
|
|
|
$categoriesAndPriorities = array();
|
|
|
|
foreach ( $wgEchoNotificationCategories as $category => $categoryData ) {
|
|
|
|
// See if the category is not dismissable at all. Must do strict
|
|
|
|
// comparison to true since no-dismiss can also be an array
|
2015-10-01 13:48:52 +00:00
|
|
|
if ( isset( $categoryData['no-dismiss'] ) && in_array( 'all', $categoryData['no-dismiss'] ) ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-07-22 21:33:22 +00:00
|
|
|
$attributeManager = EchoAttributeManager::newFromGlobalVars();
|
2013-02-16 02:20:34 +00:00
|
|
|
// See if user is eligible to recieve 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
|
|
|
|
2013-05-09 21:23:15 +00:00
|
|
|
// Show subscription options. IMPORTANT: 'echo-subscriptions-email-edit-user-talk' is a
|
|
|
|
// virtual option, its value is saved to existing talk page notification option
|
|
|
|
// 'enotifusertalkpages', see onUserLoadOptions() and onUserSaveOptions() for more
|
|
|
|
// information on how it is handled. Doing it in this way, we can avoid keeping running
|
|
|
|
// 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
|
|
|
|
|
|
|
// Build the columns (output formats)
|
|
|
|
$columns = array();
|
|
|
|
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)
|
|
|
|
$rows = array();
|
2013-05-02 00:12:59 +00:00
|
|
|
$tooltips = array();
|
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'] ) ) {
|
2013-08-20 20:39:05 +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
|
2013-04-29 17:58:05 +00:00
|
|
|
$forceOptionsOff = $forceOptionsOn = array();
|
2013-02-16 02:20:34 +00:00
|
|
|
foreach ( $wgEchoNotifiers as $notifierType => $notifierData ) {
|
|
|
|
foreach ( $validSortedCategories as $category ) {
|
|
|
|
// See if this output format is non-dismissable
|
|
|
|
if ( isset( $wgEchoNotificationCategories[$category]['no-dismiss'] )
|
2015-10-01 13:48:52 +00:00
|
|
|
&& in_array( $notifierType, $wgEchoNotificationCategories[$category]['no-dismiss'] )
|
|
|
|
) {
|
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
|
|
|
|
|
|
|
// Make sure this output format is possible for this notification category
|
|
|
|
if ( isset( $wgEchoDefaultNotificationTypes[$category] ) ) {
|
|
|
|
if ( !$wgEchoDefaultNotificationTypes[$category][$notifierType] ) {
|
2013-04-29 17:58:05 +00:00
|
|
|
$forceOptionsOff[] = "$notifierType-$category";
|
2013-01-14 23:52:46 +00:00
|
|
|
}
|
2013-02-16 02:20:34 +00:00
|
|
|
} elseif ( !$wgEchoDefaultNotificationTypes['all'][$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 )
|
|
|
|
) );
|
|
|
|
}
|
2013-02-16 02:20:34 +00:00
|
|
|
$preferences['echo-subscriptions'] = array(
|
|
|
|
'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,
|
2012-04-27 15:14:24 +00:00
|
|
|
);
|
2013-03-20 01:10:23 +00:00
|
|
|
|
2013-05-14 07:05:09 +00:00
|
|
|
if ( $wgEchoNewMsgAlert ) {
|
|
|
|
$preferences['echo-show-alert'] = array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'echo-pref-new-message-indicator',
|
|
|
|
'section' => 'echo/newmessageindicator',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:55:05 +00:00
|
|
|
// If we're using Echo to handle user talk page post notifications,
|
|
|
|
// hide the old (non-Echo) preference for this. If Echo is moved to core
|
|
|
|
// we'll want to remove this old user option entirely. For now, though,
|
|
|
|
// we need to keep it defined in case Echo is ever uninstalled.
|
|
|
|
// Otherwise, that preference could be lost entirely. This hiding logic
|
|
|
|
// is not abstracted since there is only a single preference in core
|
|
|
|
// that is potentially made obsolete by Echo.
|
|
|
|
if ( isset( $wgEchoNotifications['edit-user-talk'] ) ) {
|
|
|
|
$preferences['enotifusertalkpages']['type'] = 'hidden';
|
|
|
|
unset( $preferences['enotifusertalkpages']['section'] );
|
|
|
|
}
|
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for ArticleSaveComplete hook
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleSaveComplete
|
|
|
|
* @param $article Article edited
|
|
|
|
* @param $user User who edited
|
2012-09-02 09:30:38 +00:00
|
|
|
* @param $text string New article text
|
|
|
|
* @param $summary string Edit summary
|
|
|
|
* @param $minoredit bool Minor edit or not
|
|
|
|
* @param $watchthis bool Watch this article?
|
2012-09-26 05:09:43 +00:00
|
|
|
* @param $sectionanchor string Section that was edited
|
|
|
|
* @param $flags int Edit flags
|
2012-05-17 00:29:37 +00:00
|
|
|
* @param $revision Revision that was created
|
|
|
|
* @param $status Status
|
2012-09-02 09:30:38 +00:00
|
|
|
* @return bool true in all cases
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2012-08-31 21:50:46 +00:00
|
|
|
public static function onArticleSaved( &$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
global $wgEchoNotifications, $wgRequest;
|
2013-11-04 17:58:47 +00:00
|
|
|
|
2015-05-18 19:58:15 +00:00
|
|
|
if ( !$revision ) {
|
|
|
|
return true;
|
|
|
|
}
|
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() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-18 23:55:47 +00:00
|
|
|
$title = $article->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
|
2015-10-01 13:48:52 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $revision ) {
|
2015-05-18 19:58:15 +00:00
|
|
|
EchoDiscussionParser::generateEventsForRevision( $revision );
|
|
|
|
} );
|
|
|
|
|
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'] ) {
|
|
|
|
// This edit hasn't been added to the edit count yet
|
2016-03-09 01:05:05 +00:00
|
|
|
$thresholdCount = $user->getEditCount() + 1;
|
|
|
|
if ( in_array( $thresholdCount, $thresholds ) ) {
|
2016-03-04 05:48:01 +00:00
|
|
|
$id = $user->getId();
|
2016-03-09 01:05:05 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $id, $title, $thresholdCount ) {
|
2016-03-04 05:48:01 +00:00
|
|
|
// Fresh User object
|
|
|
|
$user = User::newFromId( $id );
|
2016-03-09 01:05:05 +00:00
|
|
|
$userEditCount = $user->getEditCount();
|
|
|
|
if ( $userEditCount !== $thresholdCount ) {
|
2016-03-04 05:48:01 +00:00
|
|
|
// Race condition with multiple simultaneous requests, skip
|
2016-03-08 20:04:45 +00:00
|
|
|
LoggerFactory::getInstance( 'Echo' )->debug(
|
|
|
|
'thank-you-edit race condition detected: {user} (id: {id}) should ' .
|
|
|
|
'have had {expectedCount} edits but has {actualCount}',
|
|
|
|
array(
|
|
|
|
'user' => $user->getName(),
|
|
|
|
'id' => $user->getId(),
|
2016-03-09 01:05:05 +00:00
|
|
|
'expectedCount' => $thresholdCount,
|
|
|
|
'actualCount' => $userEditCount,
|
2016-03-08 20:04:45 +00:00
|
|
|
)
|
|
|
|
);
|
2016-03-04 05:48:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
LoggerFactory::getInstance( 'Echo' )->debug(
|
|
|
|
'Thanking {user} (id: {id}) for their {count} edit',
|
|
|
|
array(
|
|
|
|
'user' => $user->getName(),
|
|
|
|
'id' => $user->getId(),
|
2016-03-09 01:05:05 +00:00
|
|
|
'count' => $thresholdCount,
|
2016-03-04 05:48:01 +00:00
|
|
|
)
|
|
|
|
);
|
2016-01-18 23:55:47 +00:00
|
|
|
EchoEvent::create( array(
|
|
|
|
'type' => 'thank-you-edit',
|
|
|
|
'title' => $title,
|
|
|
|
'agent' => $user,
|
|
|
|
// Edit threshold notifications are sent to the agent
|
|
|
|
'extra' => array(
|
|
|
|
'notifyAgent' => true,
|
2016-03-09 01:05:05 +00:00
|
|
|
'thresholdCount' => $thresholdCount,
|
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.
|
|
|
|
if ( isset( $wgEchoNotifications['reverted'] ) ) {
|
|
|
|
$undidRevId = $wgRequest->getVal( 'wpUndidRevision' );
|
|
|
|
if ( $undidRevId ) {
|
|
|
|
$undidRevision = Revision::newFromId( $undidRevId );
|
|
|
|
if ( $undidRevision && $undidRevision->getTitle()->equals( $title ) ) {
|
|
|
|
$victimId = $undidRevision->getUser();
|
|
|
|
if ( $victimId ) { // No notifications for anonymous users
|
|
|
|
EchoEvent::create( array(
|
|
|
|
'type' => 'reverted',
|
|
|
|
'title' => $title,
|
|
|
|
'extra' => array(
|
|
|
|
'revid' => $revision->getId(),
|
|
|
|
'reverted-user-id' => $victimId,
|
|
|
|
'reverted-revision-id' => $undidRevId,
|
|
|
|
'method' => 'undo',
|
2016-01-14 19:58:21 +00:00
|
|
|
'summary' => $summary,
|
2015-05-18 19:58:15 +00:00
|
|
|
),
|
|
|
|
'agent' => $user,
|
|
|
|
) );
|
2012-07-18 19:39:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-01 20:15:37 +00:00
|
|
|
}
|
2015-05-18 19:58:15 +00:00
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2013-05-01 19:27:32 +00:00
|
|
|
/**
|
|
|
|
* Handler for EchoAbortEmailNotification hook
|
|
|
|
* @param $user User
|
|
|
|
* @param $event EchoEvent
|
|
|
|
* @return bool true - send email, false - do not send email
|
|
|
|
*/
|
|
|
|
public static function onEchoAbortEmailNotification( $user, $event ) {
|
|
|
|
if ( $event->getType() === 'edit-user-talk' ) {
|
|
|
|
$extra = $event->getExtra();
|
|
|
|
if ( !empty( $extra['minoredit'] ) ) {
|
|
|
|
global $wgEnotifMinorEdits;
|
|
|
|
if ( !$wgEnotifMinorEdits || !$user->getOption( 'enotifminoredits' ) ) {
|
|
|
|
// Do not send talk page notification email
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proceed to send talk page notification email
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-31 23:35:16 +00:00
|
|
|
/**
|
|
|
|
* Handler for AddNewAccount hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/AddNewAccount
|
|
|
|
* @param $user User object that was created.
|
|
|
|
* @param $byEmail bool True when account was created "by email".
|
2012-09-26 05:09:43 +00:00
|
|
|
* @return bool
|
2012-08-31 23:35:16 +00:00
|
|
|
*/
|
|
|
|
public static function onAccountCreated( $user, $byEmail ) {
|
2013-04-25 00:41:47 +00:00
|
|
|
|
|
|
|
// new users get echo preferences set that are not the default settings for existing users
|
|
|
|
$user->setOption( 'echo-subscriptions-web-reverted', false );
|
|
|
|
$user->setOption( 'echo-subscriptions-email-reverted', false );
|
|
|
|
$user->setOption( 'echo-subscriptions-web-article-linked', true );
|
|
|
|
$user->setOption( 'echo-subscriptions-email-mention', true );
|
|
|
|
$user->setOption( 'echo-subscriptions-email-article-linked', true );
|
|
|
|
$user->saveSettings();
|
|
|
|
|
2012-09-26 05:09:43 +00:00
|
|
|
EchoEvent::create( array(
|
2012-08-31 23:35:16 +00:00
|
|
|
'type' => 'welcome',
|
|
|
|
'agent' => $user,
|
2016-01-18 23:55:47 +00:00
|
|
|
// Welcome notification is sent to the agent
|
2015-10-01 13:48:52 +00:00
|
|
|
'extra' => array(
|
2014-08-28 21:29:01 +00:00
|
|
|
'notifyAgent' => true
|
|
|
|
)
|
2012-08-31 23:35:16 +00:00
|
|
|
) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-13 00:49:19 +00:00
|
|
|
/**
|
2015-09-22 18:16:59 +00:00
|
|
|
* Handler for UserGroupsChanged hook.
|
|
|
|
* @see http://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
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
2013-03-13 00:49:19 +00:00
|
|
|
*/
|
2016-02-08 20:45:44 +00:00
|
|
|
public static function onUserGroupsChanged( $user, $add, $remove, $performer, $reason ) {
|
2015-09-22 18:16:59 +00:00
|
|
|
if ( !$performer ) {
|
|
|
|
// TODO: Implement support for autopromotion
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$user instanceof User ) {
|
|
|
|
// TODO: Support UserRightsProxy
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $user->equals( $performer ) ) {
|
|
|
|
// Don't notify for self changes
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-13 00:49:19 +00:00
|
|
|
|
2015-09-22 18:16:59 +00:00
|
|
|
if ( $add || $remove ) {
|
2013-03-13 00:49:19 +00:00
|
|
|
EchoEvent::create(
|
|
|
|
array(
|
|
|
|
'type' => 'user-rights',
|
|
|
|
'title' => Title::newMainPage(),
|
|
|
|
'extra' => array(
|
|
|
|
'user' => $user->getID(),
|
|
|
|
'add' => $add,
|
2016-02-08 20:45:44 +00:00
|
|
|
'remove' => $remove,
|
|
|
|
'reason' => $reason,
|
2013-03-13 00:49:19 +00:00
|
|
|
),
|
2015-09-22 18:16:59 +00:00
|
|
|
'agent' => $performer,
|
2013-03-13 00:49:19 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2013-03-13 00:49:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-26 22:05:29 +00:00
|
|
|
/**
|
|
|
|
* Handler for LinksUpdateAfterInsert hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdateAfterInsert
|
|
|
|
* @param $linksUpdate LinksUpdate
|
|
|
|
* @param $table string
|
|
|
|
* @param $insertions array
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
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' ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
) {
|
2013-01-04 01:36:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-27 23:17:25 +00:00
|
|
|
if ( is_callable( array( $linksUpdate, 'getTriggeringUser' ) ) ) {
|
|
|
|
$user = $linksUpdate->getTriggeringUser();
|
|
|
|
} else {
|
|
|
|
global $wgUser;
|
|
|
|
$user = $wgUser;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
EchoEvent::create( array(
|
|
|
|
'type' => 'page-linked',
|
|
|
|
'title' => $title,
|
2015-10-27 23:17:25 +00:00
|
|
|
'agent' => $user,
|
2013-01-15 23:21:39 +00:00
|
|
|
'extra' => array(
|
2013-05-09 18:50:05 +00:00
|
|
|
'link-from-page-id' => $linksUpdate->mTitle->getArticleId(),
|
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
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for BeforePageDisplay hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
|
|
|
|
* @param $out OutputPage object
|
|
|
|
* @param $skin Skin being used.
|
2012-09-02 09:30:38 +00:00
|
|
|
* @return bool true in all cases
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2012-06-01 10:57:09 +00:00
|
|
|
static function beforePageDisplay( $out, $skin ) {
|
2015-09-14 21:12:59 +00:00
|
|
|
if ( $out->getUser()->isLoggedIn() && $skin->getSkinName() !== 'minerva' ) {
|
2012-11-01 21:59:53 +00:00
|
|
|
// Load the module for the Notifications flyout
|
2015-08-13 00:54:16 +00:00
|
|
|
$out->addModules( array( 'ext.echo.init' ) );
|
2013-05-15 23:10:49 +00:00
|
|
|
// Load the styles for the Notifications badge
|
2015-08-13 00:54:16 +00:00
|
|
|
$out->addModuleStyles( array(
|
2015-09-16 19:48:56 +00:00
|
|
|
'ext.echo.styles.badge',
|
2015-09-14 19:52:01 +00:00
|
|
|
'ext.echo.badgeicons'
|
2015-08-13 00:54:16 +00:00
|
|
|
) );
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
2013-11-13 03:17:04 +00:00
|
|
|
|
2012-06-01 10:57:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for PersonalUrls hook.
|
2012-11-01 21:59:53 +00:00
|
|
|
* Add a "Notifications" item to the user toolbar ('personal URLs').
|
2012-05-17 00:29:37 +00:00
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
|
|
|
|
* @param &$personal_urls Array of URLs to append to.
|
|
|
|
* @param &$title Title of page being visited.
|
2013-11-13 03:17:04 +00:00
|
|
|
* @param SkinTemplate $sk
|
2012-09-02 09:30:38 +00:00
|
|
|
* @return bool true in all cases
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2013-11-13 03:17:04 +00:00
|
|
|
static function onPersonalUrls( &$personal_urls, &$title, $sk ) {
|
|
|
|
global $wgEchoNewMsgAlert;
|
|
|
|
$user = $sk->getUser();
|
2015-06-01 23:22:48 +00:00
|
|
|
if ( $user->isAnon() ) {
|
2012-06-01 10:57:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-09 19:01:42 +00:00
|
|
|
// Attempt to mark a notification as read when visiting a page
|
|
|
|
// @todo should this really be here?
|
|
|
|
$subtractAlerts = 0;
|
|
|
|
$subtractMessages = 0;
|
2014-08-07 00:07:34 +00:00
|
|
|
if ( $title->getArticleID() ) {
|
|
|
|
$mapper = new EchoTargetPageMapper();
|
2016-03-09 19:01:42 +00:00
|
|
|
$fetchedTargetPages = $mapper->fetchByUserPageId( $user, $title->getArticleID() );
|
|
|
|
if ( $fetchedTargetPages ) {
|
|
|
|
$eventIds = array();
|
|
|
|
$attribManager = EchoAttributeManager::newFromGlobalVars();
|
|
|
|
/* @var EchoTargetPage[] $targetPages */
|
|
|
|
foreach ( $fetchedTargetPages as $id => $targetPages ) {
|
|
|
|
// Only look at the first target page since they'll
|
|
|
|
// all point to the same event
|
|
|
|
$section = $attribManager->getNotificationSection(
|
|
|
|
$targetPages[0]->getEventType()
|
|
|
|
);
|
|
|
|
if ( $section === EchoAttributeManager::MESSAGE ) {
|
|
|
|
$subtractMessages += 1;
|
|
|
|
} else {
|
|
|
|
// ALERT
|
|
|
|
$subtractAlerts += 1;
|
|
|
|
}
|
|
|
|
$eventIds[] = $id;
|
|
|
|
}
|
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $user, $eventIds ) {
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
|
|
|
$notifUser->markRead( $eventIds );
|
|
|
|
} );
|
2014-08-07 00:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
2016-03-09 19:01:42 +00:00
|
|
|
$msgCount = $notifUser->getMessageCount() - $subtractMessages;
|
|
|
|
$alertCount = $notifUser->getAlertCount() - $subtractAlerts;
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
$msgNotificationTimestamp = $notifUser->getLastUnreadMessageTime();
|
|
|
|
$alertNotificationTimestamp = $notifUser->getLastUnreadAlertTime();
|
|
|
|
|
2015-09-03 01:11:10 +00:00
|
|
|
$seenAlertTime = EchoSeenTime::newFromUser( $user )->getTime( 'alert' );
|
|
|
|
$seenMsgTime = EchoSeenTime::newFromUser( $user )->getTime( 'message' );
|
|
|
|
|
|
|
|
$sk->getOutput()->addJsConfigVars( 'wgEchoSeenTime', array(
|
|
|
|
'alert' => $seenAlertTime,
|
|
|
|
'message' => $seenMsgTime
|
|
|
|
) );
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
$msgText = EchoNotificationController::formatNotificationCount( $msgCount );
|
|
|
|
$alertText = EchoNotificationController::formatNotificationCount( $alertCount );
|
|
|
|
|
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)
|
2015-09-14 10:38:44 +00:00
|
|
|
$sk->getOutput()->setupOOUI( strtolower( $sk->getSkinName() ), $sk->getOutput()->getLanguage()->getDir() );
|
2015-09-10 17:15:30 +00:00
|
|
|
$oouiImageClass = get_class( OOUI\Theme::singleton() ) === 'OOUI\\MediaWikiTheme'
|
2015-10-01 13:48:52 +00:00
|
|
|
? 'oo-ui-image-invert'
|
|
|
|
: '';
|
2015-09-10 17:15:30 +00:00
|
|
|
|
2015-12-16 23:14:06 +00:00
|
|
|
$msgLinkClasses = array( "mw-echo-notifications-badge mw-echo-notification-badge-nojs $oouiImageClass oo-ui-iconElement oo-ui-iconElement-icon oo-ui-icon-speechBubbles" );
|
2015-09-15 06:13:51 +00:00
|
|
|
$alertLinkClasses = array( "mw-echo-notifications-badge mw-echo-notification-badge-nojs $oouiImageClass oo-ui-iconElement oo-ui-iconElement-icon" );
|
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
|
2015-09-03 01:11:10 +00:00
|
|
|
( $seenMsgTime === null || $seenMsgTime < $msgNotificationTimestamp->getTimestamp( TS_MW ) ) // there are no unseen notifications
|
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;
|
2013-11-13 03:17:04 +00:00
|
|
|
}
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
$alertIcon = "bell";
|
|
|
|
if (
|
|
|
|
$alertCount != 0 && // no unread notifications
|
|
|
|
$alertNotificationTimestamp !== false && // should already always be false if count === 0
|
2015-09-03 01:11:10 +00:00
|
|
|
( $seenAlertTime === null || $seenAlertTime < $alertNotificationTimestamp->getTimestamp( TS_MW ) ) // all notifications have already been seen
|
2015-08-13 00:54:16 +00:00
|
|
|
) {
|
|
|
|
$alertLinkClasses[] = 'mw-echo-unseen-notifications';
|
|
|
|
$alertIcon = "bellOn";
|
2015-09-15 22:58:13 +00:00
|
|
|
$hasUnseen = true;
|
2015-08-13 00:54:16 +00:00
|
|
|
}
|
|
|
|
$alertLinkClasses[] = 'oo-ui-icon-' . $alertIcon;
|
|
|
|
|
|
|
|
$alertLink = array(
|
2015-07-08 00:10:49 +00:00
|
|
|
'href' => $url,
|
2015-08-13 00:54:16 +00:00
|
|
|
'text' => $alertText,
|
2015-07-08 00:10:49 +00:00
|
|
|
'active' => ( $url == $title->getLocalUrl() ),
|
2015-08-13 00:54:16 +00:00
|
|
|
'class' => $alertLinkClasses,
|
|
|
|
);
|
|
|
|
|
|
|
|
$insertUrls = array(
|
2015-09-07 23:54:47 +00:00
|
|
|
'notifications-alert' => $alertLink,
|
2015-07-08 00:10:49 +00:00
|
|
|
);
|
|
|
|
|
2016-02-23 09:20:24 +00:00
|
|
|
$msgLink = array(
|
|
|
|
'href' => $url,
|
|
|
|
'text' => $msgText,
|
|
|
|
'active' => ( $url == $title->getLocalUrl() ),
|
|
|
|
'class' => $msgLinkClasses,
|
|
|
|
);
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-02-23 09:20:24 +00:00
|
|
|
$insertUrls['notifications-message'] = $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 ) {
|
|
|
|
// Record that the user is going to see an indicator that they have unread notifications
|
2015-09-23 00:46:22 +00:00
|
|
|
RequestContext::getMain()->getStats()->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:
|
|
|
|
// * Orange alert is enabled in configuration
|
|
|
|
// * Enabled in user preferences
|
|
|
|
// * User actually has new messages
|
|
|
|
// * User is not viewing their user talk page, as user_newtalk
|
|
|
|
// will not have been cleared yet. (bug T107655).
|
|
|
|
if ( $wgEchoNewMsgAlert && $user->getOption( 'echo-show-alert' )
|
2015-10-01 13:48:52 +00:00
|
|
|
&& $user->getNewtalk() && !$user->getTalkPage()->equals( $title )
|
2015-09-14 17:34:44 +00:00
|
|
|
) {
|
2013-11-13 03:17:04 +00:00
|
|
|
$personal_urls['mytalk']['text'] = $sk->msg( 'echo-new-messages' )->text();
|
|
|
|
$personal_urls['mytalk']['class'] = array( 'mw-echo-alert' );
|
2015-09-16 19:48:56 +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
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
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.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/AbortTalkPageEmailNotification
|
|
|
|
* @param $targetUser User
|
|
|
|
* @param $title Title
|
|
|
|
* @return bool
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2013-06-08 01:05:35 +00:00
|
|
|
static function onAbortTalkPageEmailNotification( $targetUser, $title ) {
|
|
|
|
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.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/AbortWatchlistEmailNotification
|
|
|
|
* @param $targetUser User
|
|
|
|
* @param $title Title
|
|
|
|
* @param $emailNotification EmailNotification The email notification object that sends non-echo notifications
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
static function onSendWatchlistEmailNotification( $targetUser, $title, $emailNotification ) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2012-11-01 21:59:53 +00:00
|
|
|
/**
|
|
|
|
* Handler for MakeGlobalVariablesScript hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
|
2013-02-28 23:52:12 +00:00
|
|
|
* @param &$vars array Variables to be added into the output
|
2012-11-01 21:59:53 +00:00
|
|
|
* @param $outputPage OutputPage instance calling the hook
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
2012-09-02 09:30:38 +00:00
|
|
|
public static function makeGlobalVariablesScript( &$vars, OutputPage $outputPage ) {
|
2015-11-12 18:38:04 +00:00
|
|
|
global $wgEchoConfig;
|
2012-07-31 21:18:16 +00:00
|
|
|
$user = $outputPage->getUser();
|
|
|
|
|
2012-08-01 19:53:05 +00:00
|
|
|
// Provide info for the Overlay
|
|
|
|
|
2015-11-12 18:38:04 +00:00
|
|
|
if ( $user->isLoggedIn() ) {
|
2013-06-05 20:44:06 +00:00
|
|
|
$vars['wgEchoConfig'] = $wgEchoConfig;
|
2015-06-02 00:59:05 +00:00
|
|
|
} elseif (
|
2015-03-21 02:41:54 +00:00
|
|
|
$outputPage->getTitle()->equals( SpecialPage::getTitleFor( 'JavaScriptTest', 'qunit' ) ) ||
|
|
|
|
// Also if running from /plain or /export
|
|
|
|
$outputPage->getTitle()->isSubpageOf( SpecialPage::getTitleFor( 'JavaScriptTest', 'qunit' ) )
|
|
|
|
) {
|
2014-08-05 22:18:38 +00:00
|
|
|
// For testing purposes
|
|
|
|
$vars['wgEchoConfig'] = array(
|
|
|
|
'eventlogging' => array(
|
|
|
|
'EchoInteraction' => array(),
|
|
|
|
),
|
|
|
|
);
|
2012-07-31 21:18:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-31 00:29:49 +00:00
|
|
|
|
2012-11-01 21:59:53 +00:00
|
|
|
/**
|
|
|
|
* Handler for UnitTestsList hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
|
|
|
|
* @param &$files Array of unit test files
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
2012-07-31 00:29:49 +00:00
|
|
|
static function getUnitTests( &$files ) {
|
2014-08-14 18:46:26 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2014-08-23 00:39:00 +00:00
|
|
|
$directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/phpunit/' );
|
2014-08-14 18:46:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var SplFileInfo $fileInfo
|
|
|
|
*/
|
|
|
|
$ourFiles = array();
|
|
|
|
foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
|
|
|
|
if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
|
|
|
|
$ourFiles[] = $fileInfo->getPathname();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$files = array_merge( $files, $ourFiles );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2012-08-07 18:54:42 +00:00
|
|
|
return true;
|
2014-08-14 18:46:26 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2012-07-31 00:29:49 +00:00
|
|
|
}
|
2012-07-31 20:44:43 +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
|
|
|
|
* to be updated and availble to client-side tools and the API.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/GetNewMessagesAlert
|
|
|
|
* @param &$newMessagesAlert String An alert that the user has new messages
|
|
|
|
* or an empty string if the user does not (empty by default)
|
|
|
|
* @param $newtalks Array This will be empty if the user has no new messages
|
|
|
|
* or an Array containing links and revisions if there are new messages
|
|
|
|
* @param $user User The user who is loading the page
|
|
|
|
* @param $out Output object
|
|
|
|
* @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
|
|
|
*/
|
2013-05-05 00:49:08 +00:00
|
|
|
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
|
|
|
|
2012-11-01 21:59:53 +00:00
|
|
|
/**
|
|
|
|
* Handler for ArticleRollbackComplete hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleRollbackComplete
|
2013-02-28 23:52:12 +00:00
|
|
|
* @param $page WikiPage The article that was edited
|
|
|
|
* @param $agent User The user who did the rollback
|
|
|
|
* @param $newRevision Revision The revision the page was reverted back to
|
|
|
|
* @param $oldRevision Revision The revision of the top edit that was reverted
|
2012-11-01 21:59:53 +00:00
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
2012-07-18 19:39:33 +00:00
|
|
|
static function onRollbackComplete( $page, $agent, $newRevision, $oldRevision ) {
|
|
|
|
$victimId = $oldRevision->getUser();
|
|
|
|
|
2013-11-16 19:24:04 +00:00
|
|
|
if (
|
|
|
|
$victimId && // No notifications for anonymous users
|
|
|
|
!$oldRevision->getContent()->equals( $newRevision->getContent() ) // No notifications for null rollbacks
|
|
|
|
) {
|
2012-07-18 19:39:33 +00:00
|
|
|
EchoEvent::create( array(
|
|
|
|
'type' => 'reverted',
|
|
|
|
'title' => $page->getTitle(),
|
|
|
|
'extra' => array(
|
|
|
|
'revid' => $page->getRevision()->getId(),
|
|
|
|
'reverted-user-id' => $victimId,
|
|
|
|
'reverted-revision-id' => $oldRevision->getId(),
|
|
|
|
'method' => 'rollback',
|
|
|
|
),
|
|
|
|
'agent' => $agent,
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-12 22:12:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for UserSaveSettings hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UserSaveSettings
|
|
|
|
* @param $user User whose settings were saved
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
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).
|
|
|
|
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount();
|
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2013-04-12 22:12:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-04-26 16:08:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for UserLoadOptions hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UserLoadOptions
|
|
|
|
* @param $user User whose options were loaded
|
|
|
|
* @param $options Options can be modified
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
public static function onUserLoadOptions( $user, &$options ) {
|
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
|
|
|
|
2013-04-26 16:08:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-04-30 02:53:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for UserSaveOptions hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UserSaveOptions
|
|
|
|
* @param $user User whose options are being saved
|
|
|
|
* @param $options Options can be modified
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
public static function onUserSaveOptions( $user, &$options ) {
|
2013-05-09 21:23:15 +00:00
|
|
|
// echo-subscriptions-email-edit-user-talk is just a virtual option,
|
|
|
|
// save the value in the real option enotifusertalkpages
|
|
|
|
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
|
|
|
}
|
2013-05-16 21:14:26 +00:00
|
|
|
|
2013-04-30 02:53:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-05-24 22:51:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for UserClearNewTalkNotification hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UserClearNewTalkNotification
|
|
|
|
* @param $user User whose talk page notification should be marked as read
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
public static function onUserClearNewTalkNotification( User $user ) {
|
|
|
|
if ( !$user->isAnon() ) {
|
2015-10-01 13:48:52 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $user ) {
|
2015-08-26 23:31:58 +00:00
|
|
|
MWEchoNotifUser::newFromUser( $user )->clearTalkNotification();
|
|
|
|
} );
|
2013-05-24 22:51:47 +00:00
|
|
|
}
|
2015-08-26 23:31:58 +00:00
|
|
|
|
2013-05-24 22:51:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-26 01:04:31 +00:00
|
|
|
/**
|
|
|
|
* Handler for ParserTestTables hook, makes sure that Echo's tables are present during tests
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UserClearNewTalkNotification
|
|
|
|
* @param array $tables List of DB tables to be used for parser tests
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
public static function onParserTestTables( &$tables ) {
|
|
|
|
$tables[] = 'echo_event';
|
|
|
|
$tables[] = 'echo_notification';
|
|
|
|
$tables[] = 'echo_email_batch';
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-06-26 01:04:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-19 20:49:34 +00:00
|
|
|
/**
|
|
|
|
* Handler for EmailUserComplete hook.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/EmailUserComplete
|
|
|
|
* @param $address MailAddress Adress of receiving user
|
|
|
|
* @param $from MailAddress Adress of sending user
|
|
|
|
* @param $subject string Subject of the mail
|
|
|
|
* @param $text string Text of the mail
|
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
public static function onEmailUserComplete( $address, $from, $subject, $text ) {
|
2016-02-10 22:09:41 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
2015-09-19 20:49:34 +00:00
|
|
|
if ( $from->name === $address->name ) {
|
|
|
|
// nothing to notify
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$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 ) {
|
2016-02-23 21:26:55 +00:00
|
|
|
$autoFooter = "\n\n-- \n" . wfMessage( 'emailuserfooter', $from->name, $address->name )->inContentLanguage()->text();
|
|
|
|
$textWithoutFooter = preg_replace( '/' . preg_quote( $autoFooter, '/' ) . '$/', '', $text );
|
|
|
|
$preview = $wgContLang->truncate( $textWithoutFooter, 125 );
|
2016-02-10 22:09:41 +00:00
|
|
|
} else {
|
|
|
|
$preview = $subject;
|
|
|
|
}
|
|
|
|
|
2015-09-19 20:49:34 +00:00
|
|
|
EchoEvent::create( array(
|
|
|
|
'type' => 'emailuser',
|
|
|
|
'extra' => array(
|
|
|
|
'to-user-id' => $userTo->getId(),
|
2016-02-10 22:09:41 +00:00
|
|
|
'preview' => $preview,
|
2015-09-19 20:49:34 +00:00
|
|
|
),
|
|
|
|
'agent' => $userFrom,
|
|
|
|
) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-26 03:09:46 +00:00
|
|
|
/**
|
|
|
|
* For integration with the UserMerge extension.
|
|
|
|
*
|
|
|
|
* @param array $updateFields
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onUserMergeAccountFields( &$updateFields ) {
|
|
|
|
// array( tableName, idField, textField )
|
2014-10-24 19:16:37 +00:00
|
|
|
$dbw = MWEchoDbFactory::newFromDefault()->getEchoDb( DB_MASTER );
|
2014-08-26 03:09:46 +00:00
|
|
|
$updateFields[] = array( 'echo_event', 'event_agent_id', 'db' => $dbw );
|
|
|
|
$updateFields[] = array( 'echo_notification', 'notification_user', 'db' => $dbw, 'options' => array( 'IGNORE' ) );
|
|
|
|
$updateFields[] = array( 'echo_email_batch', 'eeb_user_id', 'db' => $dbw, 'options' => array( 'IGNORE' ) );
|
|
|
|
$updateFields[] = array( 'echo_target_page', 'etp_user', 'db' => $dbw, 'options' => array( 'IGNORE' ) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function onMergeAccountFromTo( User &$oldUser, User &$newUser ) {
|
|
|
|
MWEchoNotifUser::newFromUser( $oldUser )->resetNotificationCount( DB_MASTER );
|
2015-10-12 15:28:45 +00:00
|
|
|
|
|
|
|
if ( !$newUser->isAnon() ) {
|
|
|
|
MWEchoNotifUser::newFromUser( $newUser )->resetNotificationCount( DB_MASTER );
|
|
|
|
}
|
2014-08-26 03:09:46 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function onUserMergeAccountDeleteTables( &$tables ) {
|
2014-10-24 19:16:37 +00:00
|
|
|
$dbw = MWEchoDbFactory::newFromDefault()->getEchoDb( DB_MASTER );
|
2014-08-26 03:09:46 +00:00
|
|
|
$tables['echo_notification'] = array( 'notification_user', 'db' => $dbw );
|
|
|
|
$tables['echo_email_batch'] = array( 'eeb_user_id', 'db' => $dbw );
|
|
|
|
$tables['echo_target_page'] = array( 'etp_user', 'db' => $dbw );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-12-08 18:54:44 +00:00
|
|
|
|
|
|
|
// Sets custom login message for redirect from notification page
|
|
|
|
public static function onLoginFormValidErrorMessages( &$messages ) {
|
|
|
|
$messages[] = 'echo-notification-loginrequired';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-18 22:36:58 +00:00
|
|
|
public static function onResourceLoaderGetConfigVars( &$vars ) {
|
|
|
|
global $wgEchoMaxNotificationCount;
|
|
|
|
$vars['wgEchoMaxNotificationCount'] = $wgEchoMaxNotificationCount;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-18 16:28:41 +00:00
|
|
|
}
|