2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-08 00:28:15 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications;
|
|
|
|
|
|
|
|
use EmailNotification;
|
|
|
|
use LogEntry;
|
2023-06-07 17:46:16 +00:00
|
|
|
use LogicException;
|
2022-04-08 00:28:15 +00:00
|
|
|
use MailAddress;
|
2024-10-19 22:55:03 +00:00
|
|
|
use MediaWiki\Api\ApiModuleManager;
|
2022-08-22 22:46:42 +00:00
|
|
|
use MediaWiki\Api\Hook\ApiMain__moduleManagerHook;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\Auth\AuthManager;
|
2022-08-22 22:46:42 +00:00
|
|
|
use MediaWiki\Auth\Hook\LocalUserCreatedHook;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Config\Config;
|
2024-10-19 22:55:03 +00:00
|
|
|
use MediaWiki\Content\Content;
|
2022-05-01 15:16:32 +00:00
|
|
|
use MediaWiki\DAO\WikiAwareEntity;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Deferred\DeferredUpdates;
|
2024-07-29 23:50:17 +00:00
|
|
|
use MediaWiki\Deferred\LinksUpdate\LinksTable;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Deferred\LinksUpdate\LinksUpdate;
|
2022-11-02 03:51:15 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Controller\ModerationController;
|
|
|
|
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
2022-11-01 22:01:23 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel;
|
2023-06-06 21:02:02 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Hooks\HookRunner;
|
2022-11-02 20:47:04 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
|
|
|
|
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
|
|
|
use MediaWiki\Extension\Notifications\Model\Notification;
|
2022-04-08 00:47:34 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Push\Api\ApiEchoPushSubscriptions;
|
2022-08-22 22:46:42 +00:00
|
|
|
use MediaWiki\Hook\AbortTalkPageEmailNotificationHook;
|
2022-08-22 22:31:10 +00:00
|
|
|
use MediaWiki\Hook\EmailUserCompleteHook;
|
2022-08-22 22:46:42 +00:00
|
|
|
use MediaWiki\Hook\GetNewMessagesAlertHook;
|
|
|
|
use MediaWiki\Hook\LinksUpdateCompleteHook;
|
2022-08-22 22:36:48 +00:00
|
|
|
use MediaWiki\Hook\LoginFormValidErrorMessagesHook;
|
2022-10-12 00:50:11 +00:00
|
|
|
use MediaWiki\Hook\PreferencesGetIconHook;
|
2020-06-03 09:20:46 +00:00
|
|
|
use MediaWiki\Hook\RecentChange_saveHook;
|
2022-08-22 22:46:42 +00:00
|
|
|
use MediaWiki\Hook\SendWatchlistEmailNotificationHook;
|
|
|
|
use MediaWiki\Hook\SkinTemplateNavigation__UniversalHook;
|
2023-08-15 15:30:57 +00:00
|
|
|
use MediaWiki\Hook\SpecialMuteModifyFormFieldsHook;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
2024-06-12 18:31:47 +00:00
|
|
|
use MediaWiki\HTMLForm\Field\HTMLCheckMatrix;
|
2024-10-19 22:55:03 +00:00
|
|
|
use MediaWiki\Language\Language;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2016-02-29 06:13:25 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2023-10-15 06:08:48 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2017-03-17 11:16:28 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-06-12 18:31:47 +00:00
|
|
|
use MediaWiki\Output\Hook\BeforePageDisplayHook;
|
|
|
|
use MediaWiki\Output\Hook\OutputPageCheckLastModifiedHook;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Output\OutputPage;
|
2022-08-22 22:36:48 +00:00
|
|
|
use MediaWiki\Page\Hook\ArticleDeleteCompleteHook;
|
|
|
|
use MediaWiki\Page\Hook\ArticleUndeleteHook;
|
2022-08-22 22:46:42 +00:00
|
|
|
use MediaWiki\Page\Hook\RollbackCompleteHook;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2022-08-22 22:31:10 +00:00
|
|
|
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
2020-04-20 19:40:07 +00:00
|
|
|
use MediaWiki\Preferences\MultiTitleFilter;
|
2018-07-09 22:45:54 +00:00
|
|
|
use MediaWiki\Preferences\MultiUsernameFilter;
|
2024-10-19 22:55:03 +00:00
|
|
|
use MediaWiki\Registration\ExtensionRegistry;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Request\WebRequest;
|
2022-05-20 02:11:31 +00:00
|
|
|
use MediaWiki\ResourceLoader as RL;
|
2022-08-22 22:31:10 +00:00
|
|
|
use MediaWiki\ResourceLoader\Hook\ResourceLoaderRegisterModulesHook;
|
2022-05-20 02:11:31 +00:00
|
|
|
use MediaWiki\ResourceLoader\ResourceLoader;
|
2019-04-17 15:46:06 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\Revision\RevisionStore;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2020-06-16 04:03:45 +00:00
|
|
|
use MediaWiki\Storage\EditResult;
|
2022-08-22 22:36:48 +00:00
|
|
|
use MediaWiki\Storage\Hook\PageSaveCompleteHook;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\Title\NamespaceInfo;
|
2023-08-19 04:14:59 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\User\CentralId\CentralIdLookup;
|
2022-08-22 22:31:10 +00:00
|
|
|
use MediaWiki\User\Hook\UserClearNewTalkNotificationHook;
|
|
|
|
use MediaWiki\User\Hook\UserGetDefaultOptionsHook;
|
|
|
|
use MediaWiki\User\Hook\UserGroupsChangedHook;
|
2022-08-22 22:46:42 +00:00
|
|
|
use MediaWiki\User\Hook\UserSaveSettingsHook;
|
2022-08-22 22:31:10 +00:00
|
|
|
use MediaWiki\User\Options\Hook\LoadUserOptionsHook;
|
|
|
|
use MediaWiki\User\Options\Hook\SaveUserOptionsHook;
|
2023-11-29 12:44:46 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsManager;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\User\TalkPageNotificationManager;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\User;
|
2023-10-14 16:26:42 +00:00
|
|
|
use MediaWiki\User\UserEditTracker;
|
|
|
|
use MediaWiki\User\UserFactory;
|
2020-04-20 23:03:54 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2023-04-25 09:53:21 +00:00
|
|
|
use MediaWiki\WikiMap\WikiMap;
|
2022-04-08 00:28:15 +00:00
|
|
|
use RecentChange;
|
|
|
|
use Skin;
|
|
|
|
use SkinTemplate;
|
2024-05-03 09:03:03 +00:00
|
|
|
use Wikimedia\Stats\StatsFactory;
|
2022-04-08 00:28:15 +00:00
|
|
|
use WikiPage;
|
2024-12-08 20:55:30 +00:00
|
|
|
|
|
|
|
// phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
|
2022-04-08 00:28:15 +00:00
|
|
|
|
2022-08-22 22:31:10 +00:00
|
|
|
class Hooks implements
|
2022-08-22 22:46:42 +00:00
|
|
|
AbortTalkPageEmailNotificationHook,
|
|
|
|
ApiMain__moduleManagerHook,
|
2022-08-22 22:36:48 +00:00
|
|
|
ArticleDeleteCompleteHook,
|
|
|
|
ArticleUndeleteHook,
|
2022-08-22 22:31:10 +00:00
|
|
|
BeforePageDisplayHook,
|
|
|
|
EmailUserCompleteHook,
|
2022-08-22 22:46:42 +00:00
|
|
|
GetNewMessagesAlertHook,
|
2022-08-22 22:31:10 +00:00
|
|
|
GetPreferencesHook,
|
2022-08-22 22:46:42 +00:00
|
|
|
LinksUpdateCompleteHook,
|
2022-08-22 22:31:10 +00:00
|
|
|
LoadUserOptionsHook,
|
2022-08-22 22:46:42 +00:00
|
|
|
LocalUserCreatedHook,
|
2022-08-22 22:36:48 +00:00
|
|
|
LoginFormValidErrorMessagesHook,
|
|
|
|
OutputPageCheckLastModifiedHook,
|
|
|
|
PageSaveCompleteHook,
|
2022-08-22 22:31:10 +00:00
|
|
|
PreferencesGetIconHook,
|
|
|
|
RecentChange_saveHook,
|
|
|
|
ResourceLoaderRegisterModulesHook,
|
2022-08-22 22:46:42 +00:00
|
|
|
RollbackCompleteHook,
|
2022-08-22 22:31:10 +00:00
|
|
|
SaveUserOptionsHook,
|
2022-08-22 22:46:42 +00:00
|
|
|
SendWatchlistEmailNotificationHook,
|
|
|
|
SkinTemplateNavigation__UniversalHook,
|
2022-08-22 22:31:10 +00:00
|
|
|
UserClearNewTalkNotificationHook,
|
|
|
|
UserGetDefaultOptionsHook,
|
2022-08-22 22:46:42 +00:00
|
|
|
UserGroupsChangedHook,
|
2023-08-15 15:30:57 +00:00
|
|
|
UserSaveSettingsHook,
|
|
|
|
SpecialMuteModifyFormFieldsHook
|
2022-08-22 22:31:10 +00:00
|
|
|
{
|
2023-10-14 16:26:42 +00:00
|
|
|
private AuthManager $authManager;
|
|
|
|
private CentralIdLookup $centralIdLookup;
|
|
|
|
private Config $config;
|
2024-06-12 18:31:47 +00:00
|
|
|
private AttributeManager $attributeManager;
|
2023-10-14 16:26:42 +00:00
|
|
|
private HookContainer $hookContainer;
|
|
|
|
private Language $contentLanguage;
|
|
|
|
private LinkRenderer $linkRenderer;
|
|
|
|
private NamespaceInfo $namespaceInfo;
|
|
|
|
private PermissionManager $permissionManager;
|
|
|
|
private RevisionStore $revisionStore;
|
2024-05-04 07:10:31 +00:00
|
|
|
private StatsFactory $statsFactory;
|
2023-10-14 16:26:42 +00:00
|
|
|
private TalkPageNotificationManager $talkPageNotificationManager;
|
|
|
|
private UserEditTracker $userEditTracker;
|
|
|
|
private UserFactory $userFactory;
|
|
|
|
private UserOptionsManager $userOptionsManager;
|
|
|
|
|
|
|
|
private static array $revertedRevIds = [];
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
AuthManager $authManager,
|
|
|
|
CentralIdLookup $centralIdLookup,
|
|
|
|
Config $config,
|
2024-06-12 18:31:47 +00:00
|
|
|
AttributeManager $attributeManager,
|
2023-10-14 16:26:42 +00:00
|
|
|
HookContainer $hookContainer,
|
|
|
|
Language $contentLanguage,
|
|
|
|
LinkRenderer $linkRenderer,
|
|
|
|
NamespaceInfo $namespaceInfo,
|
|
|
|
PermissionManager $permissionManager,
|
|
|
|
RevisionStore $revisionStore,
|
2024-05-04 07:10:31 +00:00
|
|
|
StatsFactory $statsFactory,
|
2023-10-14 16:26:42 +00:00
|
|
|
TalkPageNotificationManager $talkPageNotificationManager,
|
|
|
|
UserEditTracker $userEditTracker,
|
|
|
|
UserFactory $userFactory,
|
|
|
|
UserOptionsManager $userOptionsManager
|
|
|
|
) {
|
|
|
|
$this->authManager = $authManager;
|
|
|
|
$this->centralIdLookup = $centralIdLookup;
|
2020-06-03 09:20:46 +00:00
|
|
|
$this->config = $config;
|
2023-10-14 16:26:42 +00:00
|
|
|
$this->attributeManager = $attributeManager;
|
|
|
|
$this->hookContainer = $hookContainer;
|
|
|
|
$this->contentLanguage = $contentLanguage;
|
|
|
|
$this->linkRenderer = $linkRenderer;
|
|
|
|
$this->namespaceInfo = $namespaceInfo;
|
|
|
|
$this->permissionManager = $permissionManager;
|
|
|
|
$this->revisionStore = $revisionStore;
|
2024-05-04 07:10:31 +00:00
|
|
|
$this->statsFactory = $statsFactory->withComponent( 'Echo' );
|
2023-10-14 16:26:42 +00:00
|
|
|
$this->talkPageNotificationManager = $talkPageNotificationManager;
|
|
|
|
$this->userEditTracker = $userEditTracker;
|
|
|
|
$this->userFactory = $userFactory;
|
|
|
|
$this->userOptionsManager = $userOptionsManager;
|
2020-06-03 09:20:46 +00:00
|
|
|
}
|
2018-03-26 22:32:30 +00:00
|
|
|
|
2018-07-26 00:19:17 +00:00
|
|
|
/**
|
|
|
|
* @param array &$defaults
|
|
|
|
*/
|
2022-08-22 22:31:10 +00:00
|
|
|
public function onUserGetDefaultOptions( &$defaults ) {
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $this->config->get( MainConfigNames::AllowHTMLEmail ) ) {
|
2022-11-12 06:37:37 +00:00
|
|
|
$defaults['echo-email-format'] = 'html';
|
2016-12-01 00:17:30 +00:00
|
|
|
} else {
|
2022-11-12 06:37:37 +00:00
|
|
|
$defaults['echo-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,
|
|
|
|
],
|
2023-06-07 20:18:51 +00:00
|
|
|
'api-triggered' => [
|
|
|
|
// emails are sent only if sender also sets the API option, which is disabled by default
|
|
|
|
'email' => true,
|
|
|
|
],
|
2018-09-21 00:15:09 +00:00
|
|
|
];
|
2023-10-15 06:08:48 +00:00
|
|
|
|
|
|
|
$echoPushEnabled = $this->config->get( ConfigNames::EnablePush );
|
|
|
|
if ( $echoPushEnabled ) {
|
2021-08-18 21:47:33 +00:00
|
|
|
$presets['default']['push'] = true;
|
|
|
|
$presets['article-linked']['push'] = false;
|
|
|
|
$presets['mention-failure']['push'] = false;
|
|
|
|
$presets['mention-success']['push'] = false;
|
|
|
|
$presets['watchlist']['push'] = false;
|
|
|
|
$presets['minor-watchlist']['push'] = false;
|
|
|
|
}
|
2018-09-21 00:15:09 +00:00
|
|
|
|
2023-10-15 06:08:48 +00:00
|
|
|
foreach ( $this->config->get( ConfigNames::NotificationCategories ) 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'];
|
|
|
|
}
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $echoPushEnabled && !isset( $defaults["echo-subscriptions-push-{$category}"] ) ) {
|
2021-08-18 21:47:33 +00:00
|
|
|
$defaults["echo-subscriptions-push-{$category}"] = $presets[$category]['push']
|
|
|
|
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
|
|
|
|
?? $presets['default']['push'];
|
|
|
|
}
|
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,
|
2021-03-08 22:03:20 +00:00
|
|
|
$wgEchoWatchlistNotifications, $wgEchoSeenTimeCacheType, $wgMainStash, $wgEnableEmail,
|
2023-06-07 20:18:51 +00:00
|
|
|
$wgEnableUserEmail, $wgEchoEnableApiEvents;
|
2013-02-16 02:20:34 +00:00
|
|
|
|
|
|
|
// allow extensions to define their own event
|
2023-06-06 21:02:02 +00:00
|
|
|
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onBeforeCreateEchoEvent(
|
|
|
|
$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'] );
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:03:20 +00:00
|
|
|
// Only allow user email notifications when enabled
|
|
|
|
if ( !$wgEnableEmail || !$wgEnableUserEmail ) {
|
|
|
|
unset( $wgEchoNotificationCategories['emailuser'] );
|
|
|
|
}
|
|
|
|
|
2023-06-07 20:18:51 +00:00
|
|
|
// Only allow API-triggered notifications when enabled
|
|
|
|
if ( !$wgEchoEnableApiEvents ) {
|
|
|
|
unset( $wgEchoNotificationCategories['api-triggered'] );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
*/
|
2022-08-22 22:31:10 +00:00
|
|
|
public function onResourceLoaderRegisterModules( ResourceLoader $resourceLoader ): void {
|
2016-12-14 23:08:34 +00:00
|
|
|
$resourceLoader->register( 'ext.echo.emailicons', [
|
2021-05-07 22:03:13 +00:00
|
|
|
'class' => ResourceLoaderEchoImageModule::class,
|
2023-10-15 06:08:48 +00:00
|
|
|
'icons' => $this->config->get( ConfigNames::NotificationIcons ),
|
2017-03-02 05:01:56 +00:00
|
|
|
'selector' => '.mw-echo-icon-{name}',
|
2023-10-15 06:08:48 +00:00
|
|
|
'localBasePath' => $this->config->get( MainConfigNames::ExtensionDirectory ),
|
2017-03-02 05:01:56 +00:00
|
|
|
'remoteExtPath' => 'Echo/modules'
|
|
|
|
] );
|
|
|
|
$resourceLoader->register( 'ext.echo.secondaryicons', [
|
2021-05-07 22:03:13 +00:00
|
|
|
'class' => ResourceLoaderEchoImageModule::class,
|
2023-10-15 06:08:48 +00:00
|
|
|
'icons' => $this->config->get( ConfigNames::SecondaryIcons ),
|
2016-12-14 23:08:34 +00:00
|
|
|
'selector' => '.mw-echo-icon-{name}',
|
2023-10-15 06:08:48 +00:00
|
|
|
'localBasePath' => $this->config->get( MainConfigNames::ExtensionDirectory ),
|
2016-12-14 23:08:34 +00:00
|
|
|
'remoteExtPath' => 'Echo/modules'
|
|
|
|
] );
|
2013-03-01 00:26:59 +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
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2022-08-22 22:31:10 +00:00
|
|
|
public function onGetPreferences( $user, &$preferences ) {
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following messages are generated upstrem:
|
|
|
|
// * prefs-echo
|
|
|
|
// * prefs-description-echo
|
|
|
|
|
2012-11-16 21:03:57 +00:00
|
|
|
// Show email frequency options
|
2016-12-05 18:51:07 +00:00
|
|
|
$freqOptions = [
|
2022-11-13 06:43:40 +00:00
|
|
|
'echo-pref-email-frequency-never' => EmailFrequency::NEVER,
|
|
|
|
'echo-pref-email-frequency-immediately' => EmailFrequency::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
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $this->config->get( ConfigNames::EnableEmailBatch ) ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$freqOptions += [
|
2022-11-13 06:43:40 +00:00
|
|
|
'echo-pref-email-frequency-daily' => EmailFrequency::DAILY_DIGEST,
|
|
|
|
'echo-pref-email-frequency-weekly' => EmailFrequency::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',
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-emailsettings
|
2013-04-18 00:44:20 +00:00
|
|
|
'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',
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-emailsettings
|
2019-12-10 00:13:29 +00:00
|
|
|
'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' );
|
2023-10-14 16:26:42 +00:00
|
|
|
$link = $this->linkRenderer->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
|
|
|
);
|
2023-10-14 16:26:42 +00:00
|
|
|
$emailAddress = $user->getEmail() && $this->permissionManager->userHasRight( $user, 'viewmyprivateinfo' )
|
2016-05-12 17:18:58 +00:00
|
|
|
? htmlspecialchars( $user->getEmail() ) : '';
|
2023-10-14 16:26:42 +00:00
|
|
|
if ( $this->permissionManager->userHasRight( $user, 'editmyprivateinfo' ) && $this->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',
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-emailsettings
|
2013-04-18 00:44:20 +00:00
|
|
|
'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
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $this->config->get( MainConfigNames::AllowHTMLEmail ) ) {
|
2013-06-24 00:22:08 +00:00
|
|
|
// 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',
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-emailsettings
|
2013-06-24 00:22:08 +00:00
|
|
|
'section' => 'echo/emailsettings',
|
2018-12-31 15:54:19 +00:00
|
|
|
'options-messages' => [
|
2022-11-13 06:43:40 +00:00
|
|
|
'echo-pref-email-format-html' => EmailFormat::HTML,
|
|
|
|
'echo-pref-email-format-plain-text' => EmailFormat::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 = [];
|
2023-10-14 16:26:42 +00:00
|
|
|
foreach ( $this->attributeManager->getInternalCategoryNames() 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 the category should be hidden from preferences.
|
2023-10-14 16:26:42 +00:00
|
|
|
if ( !$this->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)
|
2023-10-14 16:26:42 +00:00
|
|
|
if ( $this->attributeManager->getCategoryEligibility( $user, $category ) ) {
|
|
|
|
$categoriesAndPriorities[$category] = $this->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',
|
2022-01-09 19:16:10 +00:00
|
|
|
// 'enotifwatchlistpages', and 'enotifminoredits', see onLoadUserOptions() and onSaveUserOptions()
|
2019-12-09 02:42:55 +00:00
|
|
|
// 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 = [];
|
2023-10-15 06:08:48 +00:00
|
|
|
foreach ( $this->config->get( ConfigNames::Notifiers ) as $notifierType => $notifierData ) {
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following messages are generated here
|
|
|
|
// * echo-pref-web
|
|
|
|
// * echo-pref-email
|
|
|
|
// * echo-pref-push
|
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 = [];
|
2023-10-15 06:08:48 +00:00
|
|
|
$notificationCategories = $this->config->get( ConfigNames::NotificationCategories );
|
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;
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( isset( $notificationCategories[$category]['tooltip'] ) ) {
|
|
|
|
$tooltips[$categoryMessage] = wfMessage( $notificationCategories[$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 = [];
|
2023-10-15 06:08:48 +00:00
|
|
|
foreach ( $this->config->get( ConfigNames::Notifiers ) as $notifierType => $notifierData ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
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
|
2023-10-14 16:26:42 +00:00
|
|
|
if ( !$this->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
|
|
|
|
2023-10-14 16:26:42 +00:00
|
|
|
if ( !$this->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 ) {
|
2023-06-07 17:46:16 +00:00
|
|
|
throw new LogicException( sprintf(
|
2013-04-29 17:58:05 +00:00
|
|
|
'The following notifications are both forced and removed: %s',
|
|
|
|
implode( ', ', $invalid )
|
|
|
|
) );
|
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
$preferences['echo-subscriptions'] = [
|
2021-05-07 22:03:13 +00:00
|
|
|
'class' => HTMLCheckMatrix::class,
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-echosubscriptions
|
2013-02-16 02:20:34 +00:00
|
|
|
'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
|
|
|
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $this->config->get( ConfigNames::CrossWikiNotifications ) ) {
|
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',
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-echocrosswiki
|
2016-03-11 01:48:06 +00:00
|
|
|
'section' => 'echo/echocrosswiki'
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-03-11 01:48:06 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $this->config->get( ConfigNames::PollForUpdates ) ) {
|
2019-08-02 20:14:05 +00:00
|
|
|
$preferences['echo-show-poll-updates'] = [
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'echo-pref-show-poll-updates',
|
|
|
|
'help-message' => 'echo-pref-show-poll-updates-help',
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-echopollupdates
|
2019-08-02 20:14:05 +00:00
|
|
|
'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.
|
2023-10-15 06:08:48 +00:00
|
|
|
$notifications = $this->config->get( ConfigNames::Notifications );
|
|
|
|
if ( isset( $notifications['edit-user-talk'] ) ) {
|
2013-04-28 21:55:05 +00:00
|
|
|
$preferences['enotifusertalkpages']['type'] = 'hidden';
|
|
|
|
unset( $preferences['enotifusertalkpages']['section'] );
|
|
|
|
}
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $this->config->get( ConfigNames::WatchlistNotifications ) &&
|
2023-10-29 14:55:20 +00:00
|
|
|
isset( $notifications['watchlist-change'] )
|
|
|
|
) {
|
2019-12-09 02:42:55 +00:00
|
|
|
$preferences['enotifwatchlistpages']['type'] = 'hidden';
|
|
|
|
unset( $preferences['enotifusertalkpages']['section'] );
|
|
|
|
$preferences['enotifminoredits']['type'] = 'hidden';
|
|
|
|
unset( $preferences['enotifminoredits']['section'] );
|
|
|
|
}
|
2013-04-28 21:55:05 +00:00
|
|
|
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $this->config->get( ConfigNames::PerUserBlacklist ) ) {
|
2016-11-10 04:37:10 +00:00
|
|
|
$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',
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-blocknotificationslist
|
2016-11-10 04:37:10 +00:00
|
|
|
'section' => 'echo/blocknotificationslist',
|
2018-07-09 22:45:54 +00:00
|
|
|
'filter' => MultiUsernameFilter::class,
|
2016-11-10 04:37:10 +00:00
|
|
|
];
|
2020-04-20 19:40:07 +00:00
|
|
|
$preferences['echo-notifications-page-linked-title-muted-list'] = [
|
|
|
|
'type' => 'titlesmultiselect',
|
|
|
|
'label-message' => 'echo-pref-notifications-page-linked-title-muted-list',
|
2023-11-02 19:02:16 +00:00
|
|
|
// The following message is generated upstrem:
|
|
|
|
// * prefs-mutedpageslist
|
2020-04-20 19:40:07 +00:00
|
|
|
'section' => 'echo/mutedpageslist',
|
2020-06-03 10:49:26 +00:00
|
|
|
'showMissing' => false,
|
2022-01-09 19:16:10 +00:00
|
|
|
'excludeDynamicNamespaces' => true,
|
|
|
|
'filter' => new MultiTitleFilter()
|
2020-04-20 19:40:07 +00:00
|
|
|
];
|
2016-11-10 04:37:10 +00:00
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 00:50:11 +00:00
|
|
|
/**
|
|
|
|
* Add icon for Special:Preferences mobile layout
|
|
|
|
*
|
|
|
|
* @param array &$iconNames Array of icon names for their respective sections.
|
|
|
|
*/
|
|
|
|
public function onPreferencesGetIcon( &$iconNames ) {
|
|
|
|
$iconNames[ 'echo' ] = 'bell';
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2023-10-14 16:26:42 +00:00
|
|
|
private function isEmailChangeAllowed() {
|
|
|
|
return $this->authManager->allowsPropertyChange( 'emailaddress' );
|
2016-05-25 19:03:29 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
2020-06-16 04:03:45 +00:00
|
|
|
* Handler for PageSaveComplete hook
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/PageSaveComplete
|
2017-12-08 13:49:55 +00:00
|
|
|
*
|
2019-04-17 15:46:06 +00:00
|
|
|
* @param WikiPage $wikiPage modified WikiPage
|
2020-06-16 04:03:45 +00:00
|
|
|
* @param UserIdentity $userIdentity User who edited
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param string $summary Edit summary
|
2020-06-16 04:03:45 +00:00
|
|
|
* @param int $flags Edit flags
|
|
|
|
* @param RevisionRecord $revisionRecord RevisionRecord for the revision that was created
|
|
|
|
* @param EditResult $editResult
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2022-08-22 22:36:48 +00:00
|
|
|
public function onPageSaveComplete(
|
|
|
|
$wikiPage,
|
|
|
|
$userIdentity,
|
|
|
|
$summary,
|
|
|
|
$flags,
|
|
|
|
$revisionRecord,
|
|
|
|
$editResult
|
2018-08-25 10:51:14 +00:00
|
|
|
) {
|
2020-06-16 04:03:45 +00:00
|
|
|
if ( $editResult->isNullEdit() ) {
|
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();
|
2021-03-17 11:07:45 +00:00
|
|
|
$isRevert = $editResult->getRevertMethod() === EditResult::REVERT_UNDO ||
|
|
|
|
$editResult->getRevertMethod() === EditResult::REVERT_ROLLBACK;
|
2012-07-27 22:16:19 +00:00
|
|
|
|
2021-12-08 05:19:00 +00:00
|
|
|
// Save the revert status for the LinksUpdateComplete hook
|
|
|
|
if ( $isRevert ) {
|
|
|
|
self::$revertedRevIds[$revisionRecord->getId()] = true;
|
|
|
|
}
|
|
|
|
|
2015-05-18 19:58:15 +00:00
|
|
|
// Try to do this after the HTTP response
|
2021-03-17 11:07:45 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( static function () use ( $revisionRecord, $isRevert ) {
|
2022-11-12 07:19:00 +00:00
|
|
|
DiscussionParser::generateEventsForRevision( $revisionRecord, $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
|
2020-06-17 18:39:39 +00:00
|
|
|
$thresholds = [ 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000 ];
|
2021-12-19 01:16:52 +00:00
|
|
|
if ( $userIdentity->isRegistered() ) {
|
2024-11-26 02:38:43 +00:00
|
|
|
$thresholdCount = $this->getPredictedEditCount( $userIdentity );
|
2016-03-09 01:05:05 +00:00
|
|
|
if ( in_array( $thresholdCount, $thresholds ) ) {
|
2022-12-21 20:50:29 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( static function () use (
|
2023-10-29 14:55:20 +00:00
|
|
|
$revisionRecord, $userIdentity, $title, $thresholdCount
|
|
|
|
) {
|
2022-11-02 20:47:04 +00:00
|
|
|
$notificationMapper = new NotificationMapper();
|
2021-12-19 01:16:52 +00:00
|
|
|
$notifications = $notificationMapper->fetchByUser( $userIdentity, 10, null, [ 'thank-you-edit' ] );
|
2022-11-02 21:34:17 +00:00
|
|
|
/** @var Notification $notification */
|
2016-08-03 15:41:50 +00:00
|
|
|
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
|
|
|
[
|
2021-12-19 01:16:52 +00:00
|
|
|
'user' => $userIdentity->getName(),
|
|
|
|
'id' => $userIdentity->getId(),
|
2016-08-03 15:41:50 +00:00
|
|
|
'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
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::create( [
|
2022-06-23 09:17:10 +00:00
|
|
|
'type' => 'thank-you-edit',
|
|
|
|
'title' => $title,
|
|
|
|
'agent' => $userIdentity,
|
|
|
|
// Edit threshold notifications are sent to the agent
|
|
|
|
'extra' => [
|
|
|
|
'editCount' => $thresholdCount,
|
2022-12-21 20:50:29 +00:00
|
|
|
'revid' => $revisionRecord->getId(),
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2022-06-23 09:17:10 +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.
|
2021-03-17 11:07:45 +00:00
|
|
|
// Reverts through the 'rollback' link (EditResult::REVERT_ROLLBACK)
|
|
|
|
// are handled in ::onRollbackComplete().
|
|
|
|
if ( $editResult->getRevertMethod() === EditResult::REVERT_UNDO ) {
|
|
|
|
$undidRevId = $editResult->getUndidRevId();
|
2023-10-14 16:26:42 +00:00
|
|
|
$undidRevision = $this->revisionStore->getRevisionById( $undidRevId );
|
2019-04-17 15:46:06 +00:00
|
|
|
if (
|
|
|
|
$undidRevision &&
|
|
|
|
Title::newFromLinkTarget( $undidRevision->getPageAsLinkTarget() )->equals( $title )
|
|
|
|
) {
|
2020-07-21 11:15:09 +00:00
|
|
|
$revertedUser = $undidRevision->getUser();
|
2020-07-21 11:18:29 +00:00
|
|
|
// No notifications for anonymous users
|
|
|
|
if ( $revertedUser && $revertedUser->getId() ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::create( [
|
2016-12-18 02:21:53 +00:00
|
|
|
'type' => 'reverted',
|
|
|
|
'title' => $title,
|
|
|
|
'extra' => [
|
2020-06-16 04:03:45 +00:00
|
|
|
'revid' => $revisionRecord->getId(),
|
2020-07-21 11:18:29 +00:00
|
|
|
'reverted-user-id' => $revertedUser->getId(),
|
2016-12-18 02:21:53 +00:00
|
|
|
'reverted-revision-id' => $undidRevId,
|
2018-03-26 18:54:03 +00:00
|
|
|
'method' => 'undo',
|
2016-12-18 02:21:53 +00:00
|
|
|
'summary' => $summary,
|
|
|
|
],
|
2021-12-19 01:16:52 +00:00
|
|
|
'agent' => $userIdentity,
|
2016-12-18 02:21:53 +00:00
|
|
|
] );
|
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
|
|
|
/**
|
2024-11-26 02:38:43 +00:00
|
|
|
* Get the predicted edit count after a page save hook
|
|
|
|
*
|
2021-12-19 01:16:52 +00:00
|
|
|
* @param UserIdentity $user
|
2019-03-04 15:49:19 +00:00
|
|
|
* @return int
|
|
|
|
*/
|
2024-11-26 02:38:43 +00:00
|
|
|
private function getPredictedEditCount( UserIdentity $user ) {
|
2023-10-14 16:26:42 +00:00
|
|
|
$editCount = $this->userEditTracker->getUserEditCount( $user ) ?: 0;
|
2024-11-26 02:38:43 +00:00
|
|
|
// When this code runs, the deferred update that increments the edit count
|
|
|
|
// will still be pending.
|
|
|
|
|
2021-12-19 01:16:52 +00:00
|
|
|
return $editCount + 1;
|
2019-03-04 15:49:19 +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
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public function onLocalUserCreated( $user, $autocreated ) {
|
2016-05-25 19:03:29 +00:00
|
|
|
if ( !$autocreated ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::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
|
|
|
|
2022-11-13 06:43:40 +00:00
|
|
|
$seenTime = SeenTime::newFromUser( $user );
|
2016-09-09 21:46:11 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
*
|
2022-05-01 15:16:32 +00:00
|
|
|
* @param UserIdentity $userId user that was changed
|
2015-09-22 18:16:59 +00:00
|
|
|
* @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
|
|
|
*/
|
2023-10-29 14:55:20 +00:00
|
|
|
public function onUserGroupsChanged( $userId, $add, $remove, $performer, $reason, $oldUGMs, $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
|
|
|
}
|
|
|
|
|
2022-05-01 15:16:32 +00:00
|
|
|
if ( $userId->getWikiId() !== WikiAwareEntity::LOCAL ) {
|
|
|
|
// TODO: Support external users
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2015-09-22 18:16:59 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 16:26:42 +00:00
|
|
|
$user = $this->userFactory->newFromUserIdentity( $userId );
|
2022-05-01 15:16:32 +00:00
|
|
|
|
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
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::create(
|
2017-04-08 07:43:05 +00:00
|
|
|
[
|
|
|
|
'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 ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::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
|
|
|
/**
|
2021-12-08 05:19:00 +00:00
|
|
|
* Handler for LinksUpdateComplete hook.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdateComplete
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param LinksUpdate $linksUpdate
|
2021-12-08 05:19:00 +00:00
|
|
|
* @param mixed $ticket
|
2012-12-26 22:05:29 +00:00
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public function onLinksUpdateComplete( $linksUpdate, $ticket ) {
|
2013-03-18 21:48:33 +00:00
|
|
|
// Rollback or undo should not trigger link notification
|
2021-12-08 05:19:00 +00:00
|
|
|
if ( $linksUpdate->getRevisionRecord() ) {
|
|
|
|
$revId = $linksUpdate->getRevisionRecord()->getId();
|
|
|
|
if ( isset( self::$revertedRevIds[$revId] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-18 21:48:33 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 00:13:58 +00:00
|
|
|
// Handle only
|
2021-12-08 05:19:00 +00:00
|
|
|
// 1. content namespace pages &&
|
|
|
|
// 2. non-transcluding pages &&
|
|
|
|
// 3. non-redirect pages
|
2023-10-14 16:26:42 +00:00
|
|
|
if ( !$this->namespaceInfo->isContent( $linksUpdate->getTitle()->getNamespace() )
|
2021-12-08 04:00:37 +00:00
|
|
|
|| !$linksUpdate->isRecursive() || $linksUpdate->getTitle()->isRedirect()
|
2015-10-01 13:48:52 +00:00
|
|
|
) {
|
2019-12-27 11:11:11 +00:00
|
|
|
return;
|
2013-01-04 01:36:12 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 02:31:12 +00:00
|
|
|
$revRecord = $linksUpdate->getRevisionRecord();
|
|
|
|
$revid = $revRecord ? $revRecord->getId() : null;
|
|
|
|
$user = $revRecord ? $revRecord->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
|
2024-07-29 23:50:17 +00:00
|
|
|
foreach ( $linksUpdate->getPageReferenceIterator( 'pagelinks', LinksTable::INSERTED ) as $pageReference ) {
|
|
|
|
if ( $this->namespaceInfo->isContent( $pageReference->getNamespace() ) ) {
|
|
|
|
$title = Title::newFromPageReference( $pageReference );
|
2013-05-03 16:30:29 +00:00
|
|
|
if ( $title->isRedirect() ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-12-08 04:00:37 +00:00
|
|
|
$linkFromPageId = $linksUpdate->getTitle()->getArticleID();
|
2023-05-16 12:43:49 +00:00
|
|
|
// T318523: Don't send page-linked notifications for pages created by bot users.
|
2024-06-12 18:31:47 +00:00
|
|
|
$articleAuthor = UserLocator::getArticleAuthorByArticleId( $title->getArticleID() );
|
2023-05-16 12:43:49 +00:00
|
|
|
if ( $articleAuthor && $articleAuthor->isBot() ) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::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
|
|
|
*/
|
2022-08-22 22:31:10 +00:00
|
|
|
public function onBeforePageDisplay( $out, $skin ): void {
|
2020-08-07 23:41:30 +00:00
|
|
|
$user = $out->getUser();
|
|
|
|
|
2020-12-18 02:32:42 +00:00
|
|
|
if ( !$user->isRegistered() ) {
|
2022-11-20 07:17:50 +00:00
|
|
|
if ( ExtensionRegistry::getInstance()->isLoaded( 'CentralAuth' ) ) {
|
|
|
|
$out->addModules( [ 'ext.echo.centralauth' ] );
|
|
|
|
}
|
2020-08-07 23:41:30 +00:00
|
|
|
return;
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
2020-08-07 23:41:30 +00:00
|
|
|
|
2023-10-14 16:26:42 +00:00
|
|
|
if ( $this->shouldDisplayTalkAlert( $user, $out->getTitle() ) ) {
|
2020-08-07 23:41:30 +00:00
|
|
|
// Load the module for the Orange alert
|
|
|
|
$out->addModuleStyles( 'ext.echo.styles.alert' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the module for the Notifications flyout
|
|
|
|
$out->addModules( [ 'ext.echo.init' ] );
|
|
|
|
// Load the styles for the Notifications badge
|
|
|
|
$out->addModuleStyles( [
|
|
|
|
'ext.echo.styles.badge',
|
|
|
|
'oojs-ui.styles.icons-alerts'
|
|
|
|
] );
|
2012-06-01 10:57:09 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:08:48 +00:00
|
|
|
private function processMarkAsRead( User $user, WebRequest $request, Title $title ) {
|
2018-09-03 17:01:06 +00:00
|
|
|
$subtractions = [
|
2022-11-12 07:19:00 +00:00
|
|
|
AttributeManager::ALERT => 0,
|
|
|
|
AttributeManager::MESSAGE => 0
|
2018-09-03 17:01:06 +00:00
|
|
|
];
|
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() ) {
|
2022-11-02 20:47:04 +00:00
|
|
|
$eventMapper = new EventMapper();
|
2016-03-04 19:23:02 +00:00
|
|
|
$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
|
2021-09-18 23:39:22 +00:00
|
|
|
$markAsReadIds = array_filter( explode( '|', $request->getText( 'markasread' ) ) );
|
2021-12-21 00:47:31 +00:00
|
|
|
$markAsReadWiki = $request->getText( 'markasreadwiki', WikiMap::getCurrentWikiId() );
|
2023-10-15 06:08:48 +00:00
|
|
|
$markAsReadLocal = !$this->config->get( ConfigNames::CrossWikiNotifications ) ||
|
|
|
|
$markAsReadWiki === WikiMap::getCurrentWikiId();
|
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
|
2022-11-02 20:47:04 +00:00
|
|
|
$notifMapper = new NotificationMapper();
|
2018-09-03 17:01:06 +00:00
|
|
|
$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
|
2022-11-13 07:48:43 +00:00
|
|
|
$notifUser = NotifUser::newFromUser( $user );
|
2021-10-21 11:19:39 +00:00
|
|
|
$notifInfo = $notifUser->getForeignNotificationInfo( $markAsReadIds, $markAsReadWiki, $request );
|
2018-09-03 17:01:06 +00:00
|
|
|
foreach ( $notifInfo as $id => $info ) {
|
|
|
|
$subtractions[$info['section']]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Schedule a deferred update to mark these notifications as read on the foreign wiki
|
2021-10-21 11:19:39 +00:00
|
|
|
DeferredUpdates::addCallableUpdate(
|
|
|
|
static function () use ( $user, $markAsReadIds, $markAsReadWiki, $request ) {
|
2022-11-13 07:48:43 +00:00
|
|
|
$notifUser = NotifUser::newFromUser( $user );
|
2021-10-21 11:19:39 +00:00
|
|
|
$notifUser->markReadForeign( $markAsReadIds, $markAsReadWiki, $request );
|
|
|
|
}
|
|
|
|
);
|
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 ) {
|
2021-05-04 16:06:42 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( static function () use ( $user, $eventIds ) {
|
2022-11-13 07:48:43 +00:00
|
|
|
$notifUser = NotifUser::newFromUser( $user );
|
2016-05-03 01:56:13 +00:00
|
|
|
$notifUser->markRead( $eventIds );
|
|
|
|
} );
|
|
|
|
}
|
2014-08-07 00:07:34 +00:00
|
|
|
|
2018-09-03 17:01:06 +00:00
|
|
|
return $subtractions;
|
|
|
|
}
|
|
|
|
|
2021-01-06 17:46:19 +00:00
|
|
|
/**
|
|
|
|
* Determine if a talk page alert should be displayed.
|
|
|
|
* We need to check:
|
|
|
|
* - User actually has new messages
|
|
|
|
* - User is not viewing their user talk page, as user_newtalk will not have been cleared yet.
|
|
|
|
* (bug T107655).
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @param Title $title
|
|
|
|
* @return bool
|
|
|
|
*/
|
2023-10-14 16:26:42 +00:00
|
|
|
private function shouldDisplayTalkAlert( $user, $title ) {
|
|
|
|
$userHasNewMessages = $this->talkPageNotificationManager->userHasNewMessages( $user );
|
2021-01-06 17:46:19 +00:00
|
|
|
|
|
|
|
return $userHasNewMessages && !$user->getTalkPage()->equals( $title );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for SkinTemplateNavigation::Universal hook.
|
|
|
|
* Adds "Notifications" items to the notifications content navigation.
|
|
|
|
* SkinTemplate automatically merges these into the personal tools for older skins.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation::Universal
|
|
|
|
* @param SkinTemplate $skinTemplate
|
|
|
|
* @param array &$links Array of URLs to append to.
|
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public function onSkinTemplateNavigation__Universal( $skinTemplate, &$links ): void {
|
2021-01-06 17:46:19 +00:00
|
|
|
$user = $skinTemplate->getUser();
|
|
|
|
if ( !$user->isRegistered() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $skinTemplate->getTitle();
|
|
|
|
$out = $skinTemplate->getOutput();
|
|
|
|
|
2023-10-15 06:08:48 +00:00
|
|
|
$subtractions = $this->processMarkAsRead( $user, $out->getRequest(), $title );
|
2018-09-03 17:01:06 +00:00
|
|
|
|
2013-11-13 03:17:04 +00:00
|
|
|
// Add a "My notifications" item to personal URLs
|
2022-11-13 07:48:43 +00:00
|
|
|
$notifUser = NotifUser::newFromUser( $user );
|
2022-11-12 07:19:00 +00:00
|
|
|
$msgCount = $notifUser->getMessageCount() - $subtractions[AttributeManager::MESSAGE];
|
|
|
|
$alertCount = $notifUser->getAlertCount() - $subtractions[AttributeManager::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();
|
|
|
|
|
2022-11-13 06:43:40 +00:00
|
|
|
$seenTime = SeenTime::newFromUser( $user );
|
2016-09-15 21:16:06 +00:00
|
|
|
if ( $title->isSpecial( 'Notifications' ) ) {
|
|
|
|
// If this is the Special:Notifications page, seenTime to now
|
2022-11-12 07:19:00 +00:00
|
|
|
$seenTime->setTime( wfTimestamp( TS_MW ), AttributeManager::ALL );
|
2016-09-15 21:16:06 +00:00
|
|
|
}
|
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
|
|
|
|
2021-01-06 17:46:19 +00:00
|
|
|
$out->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
|
|
|
|
2022-11-02 03:51:15 +00:00
|
|
|
$msgFormattedCount = NotificationController::formatNotificationCount( $msgCount );
|
|
|
|
$alertFormattedCount = NotificationController::formatNotificationCount( $alertCount );
|
2017-03-12 13:04:20 +00:00
|
|
|
|
2015-07-08 00:10:49 +00:00
|
|
|
$url = SpecialPage::getTitleFor( 'Notifications' )->getLocalURL();
|
|
|
|
|
2022-02-08 16:41:48 +00:00
|
|
|
$skinName = strtolower( $skinTemplate->getSkinName() );
|
|
|
|
$isMinervaSkin = $skinName === 'minerva';
|
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)
|
2022-02-08 16:41:48 +00:00
|
|
|
$out::setupOOUI( $skinName, $out->getLanguage()->getDir() );
|
|
|
|
$bellIconClass = $isMinervaSkin ? 'oo-ui-icon-bellOutline' : 'oo-ui-icon-bell';
|
2015-09-10 17:15:30 +00:00
|
|
|
|
2023-08-19 02:53:14 +00:00
|
|
|
$msgLinkClasses = [ "mw-echo-notifications-badge", "mw-echo-notification-badge-nojs", "oo-ui-icon-tray" ];
|
2022-02-08 16:41:48 +00:00
|
|
|
$alertLinkClasses = [ "mw-echo-notifications-badge", "mw-echo-notification-badge-nojs", $bellIconClass ];
|
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 (
|
2022-11-12 06:37:37 +00:00
|
|
|
// no unread notifications
|
|
|
|
$msgCount !== 0 &&
|
|
|
|
// should already always be false if count === 0
|
|
|
|
$msgNotificationTimestamp !== false &&
|
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
|
|
|
|
2022-11-13 07:48:43 +00:00
|
|
|
if ( $msgCount > NotifUser::MAX_BADGE_COUNT ) {
|
2016-12-20 18:40:54 +00:00
|
|
|
$msgLinkClasses[] = 'mw-echo-notifications-badge-long-label';
|
|
|
|
}
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
if (
|
2022-11-12 06:37:37 +00:00
|
|
|
// no unread notifications
|
|
|
|
$alertCount !== 0 &&
|
|
|
|
// should already always be false if count === 0
|
|
|
|
$alertNotificationTimestamp !== false &&
|
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
|
|
|
}
|
|
|
|
|
2022-11-13 07:48:43 +00:00
|
|
|
if ( $alertCount > NotifUser::MAX_BADGE_COUNT ) {
|
2016-12-20 18:40:54 +00:00
|
|
|
$alertLinkClasses[] = 'mw-echo-notifications-badge-long-label';
|
|
|
|
}
|
|
|
|
|
2021-06-01 21:14:41 +00:00
|
|
|
$mytalk = $links['user-menu']['mytalk'] ?? false;
|
2021-05-14 20:44:10 +00:00
|
|
|
if (
|
2021-06-01 21:14:41 +00:00
|
|
|
$mytalk &&
|
2023-10-14 16:26:42 +00:00
|
|
|
$this->shouldDisplayTalkAlert( $user, $title ) &&
|
|
|
|
( new HookRunner( $this->hookContainer ) )->onBeforeDisplayOrangeAlert( $user, $title )
|
2021-05-14 20:44:10 +00:00
|
|
|
) {
|
2021-05-27 00:58:05 +00:00
|
|
|
// Create new talk alert inheriting from the talk link data.
|
|
|
|
$links['notifications']['talk-alert'] = array_merge(
|
|
|
|
$links['user-menu']['mytalk'],
|
|
|
|
[
|
2021-07-13 15:00:42 +00:00
|
|
|
// Hardcode id, which is needed to dismiss the talk alert notification
|
|
|
|
'id' => 'pt-talk-alert',
|
2021-07-22 20:19:14 +00:00
|
|
|
// If Vector hook ran anicon will have been copied to the link class.
|
|
|
|
// We must reset it.
|
|
|
|
'link-class' => [],
|
2021-05-27 00:58:05 +00:00
|
|
|
'text' => $skinTemplate->msg( 'echo-new-messages' )->text(),
|
2021-06-08 11:29:59 +00:00
|
|
|
'class' => [ 'mw-echo-alert' ],
|
2021-09-02 22:35:35 +00:00
|
|
|
// unset icon
|
2023-11-13 19:15:35 +00:00
|
|
|
'icon' => null,
|
2021-05-27 00:58:05 +00:00
|
|
|
]
|
|
|
|
);
|
2021-04-30 16:26:51 +00:00
|
|
|
|
|
|
|
// If there's exactly one new user talk message, then link directly to it from the alert.
|
2022-11-02 20:47:04 +00:00
|
|
|
$notificationMapper = new NotificationMapper();
|
2021-04-30 16:26:51 +00:00
|
|
|
$notifications = $notificationMapper->fetchUnreadByUser( $user, 2, null, [ 'edit-user-talk' ] );
|
|
|
|
if ( count( $notifications ) === 1 ) {
|
|
|
|
$presModel = EchoEventPresentationModel::factory(
|
|
|
|
current( $notifications )->getEvent(),
|
|
|
|
$out->getLanguage(),
|
|
|
|
$user
|
|
|
|
);
|
|
|
|
$links['notifications']['talk-alert']['href'] = $presModel->getPrimaryLink()['url'];
|
|
|
|
}
|
2021-05-14 20:44:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 17:46:19 +00:00
|
|
|
$links['notifications']['notifications-alert'] = [
|
2015-07-08 00:10:49 +00:00
|
|
|
'href' => $url,
|
2021-08-19 22:44:31 +00:00
|
|
|
'text' => $skinTemplate->msg( 'echo-notification-alert', $alertCount )->text(),
|
2019-06-11 21:43:05 +00:00
|
|
|
'active' => ( $url == $title->getLocalURL() ),
|
2021-01-06 17:46:19 +00:00
|
|
|
'link-class' => $alertLinkClasses,
|
2022-09-14 22:12:00 +00:00
|
|
|
'icon' => 'bell',
|
2016-12-05 18:51:07 +00:00
|
|
|
'data' => [
|
2022-02-08 16:41:48 +00:00
|
|
|
'event-name' => 'ui.notifications',
|
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
|
|
|
],
|
2021-01-06 17:46:19 +00:00
|
|
|
// This item used to be part of personal tools, and much CSS relies on it using this id.
|
|
|
|
'id' => 'pt-notifications-alert',
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2021-01-06 17:46:19 +00:00
|
|
|
$links['notifications']['notifications-notice'] = [
|
2016-02-23 09:20:24 +00:00
|
|
|
'href' => $url,
|
2021-08-19 22:44:31 +00:00
|
|
|
'text' => $skinTemplate->msg( 'echo-notification-notice', $msgCount )->text(),
|
2019-06-11 21:43:05 +00:00
|
|
|
'active' => ( $url == $title->getLocalURL() ),
|
2021-01-06 17:46:19 +00:00
|
|
|
'link-class' => $msgLinkClasses,
|
2022-09-14 22:12:00 +00:00
|
|
|
'icon' => 'tray',
|
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
|
|
|
],
|
2021-01-06 17:46:19 +00:00
|
|
|
// This item used to be part of personal tools, and much CSS relies on it using this id.
|
|
|
|
'id' => 'pt-notifications-notice',
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-08-13 00:54:16 +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.
|
2024-05-04 07:10:31 +00:00
|
|
|
$this->statsFactory->getCounter( 'unseen_total' )
|
|
|
|
->copyToStatsdAt( 'echo.unseen' )
|
|
|
|
->increment();
|
2015-09-15 22:58:13 +00:00
|
|
|
}
|
2020-08-07 23:41:30 +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
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public function onAbortTalkPageEmailNotification( $targetUser, $title ) {
|
2013-06-08 01:05:35 +00:00
|
|
|
// Send legacy talk page email notification if
|
|
|
|
// 1. echo is disabled for them or
|
|
|
|
// 2. echo talk page notification is disabled
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( !isset( $this->config->get( ConfigNames::Notifications )['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
|
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public function onSendWatchlistEmailNotification( $targetUser, $title, $emailNotification ) {
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $this->config->get( ConfigNames::WatchlistNotifications ) &&
|
2023-10-29 14:55:20 +00:00
|
|
|
isset( $this->config->get( ConfigNames::Notifications )["watchlist-change"] )
|
|
|
|
) {
|
2019-12-09 02:42:55 +00:00
|
|
|
// Let echo handle watchlist notifications entirely
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-09 14:18:07 +00:00
|
|
|
$eventName = false;
|
|
|
|
// The edit-user-talk and edit-user-page events effectively duplicate watchlist notifications.
|
|
|
|
// If we are sending Echo notification emails, suppress the watchlist notifications.
|
|
|
|
if ( $title->inNamespace( NS_USER_TALK ) && $targetUser->getTalkPage()->equals( $title ) ) {
|
|
|
|
$eventName = 'edit-user-talk';
|
|
|
|
} elseif ( $title->inNamespace( NS_USER ) && $targetUser->getUserPage()->equals( $title ) ) {
|
|
|
|
$eventName = 'edit-user-page';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $eventName !== false ) {
|
2023-10-14 16:26:42 +00:00
|
|
|
$events = $this->attributeManager->getUserEnabledEvents( $targetUser, 'email' );
|
2023-03-09 14:18:07 +00:00
|
|
|
if ( in_array( $eventName, $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;
|
|
|
|
}
|
|
|
|
|
2022-08-22 22:36:48 +00:00
|
|
|
/**
|
|
|
|
* @param array &$modifiedTimes
|
|
|
|
* @param OutputPage $out
|
|
|
|
*/
|
|
|
|
public function onOutputPageCheckLastModified( &$modifiedTimes, $out ) {
|
2021-04-02 22:39:15 +00:00
|
|
|
$req = $out->getRequest();
|
|
|
|
if ( $req->getRawVal( 'action' ) === 'raw' || $req->getRawVal( 'action' ) === 'render' ) {
|
2022-11-13 06:43:40 +00:00
|
|
|
// Optimisation: Avoid expensive SeenTime compute on non-skin responses (T279213)
|
2021-04-02 22:39:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:16:14 +00:00
|
|
|
$user = $out->getUser();
|
2020-12-18 02:32:42 +00:00
|
|
|
if ( $user->isRegistered() ) {
|
2022-11-13 07:48:43 +00:00
|
|
|
$notifUser = NotifUser::newFromUser( $user );
|
2016-05-10 23:56:07 +00:00
|
|
|
$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
|
|
|
|
2022-11-13 06:43:40 +00:00
|
|
|
$modifiedTimes['notifications-seen-alert'] = SeenTime::newFromUser( $user )->getTime( 'alert' );
|
|
|
|
$modifiedTimes['notifications-seen-message'] = SeenTime::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
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public function onGetNewMessagesAlert( &$newMessagesAlert, $newtalks, $user, $out ) {
|
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.
|
2020-12-18 02:32:42 +00:00
|
|
|
if ( $user->isRegistered()
|
2023-10-15 06:08:48 +00:00
|
|
|
&& isset( $this->config->get( ConfigNames::Notifications )['edit-user-talk'] )
|
2023-10-14 16:26:42 +00:00
|
|
|
&& ( new HookRunner( $this->hookContainer ) )->onEchoCanAbortNewMessagesAlert()
|
2013-03-20 01:10:23 +00:00
|
|
|
) {
|
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
|
|
|
/**
|
2020-04-20 23:03:54 +00:00
|
|
|
* Handler for RollbackComplete hook.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/RollbackComplete
|
2018-03-26 18:54:03 +00:00
|
|
|
*
|
|
|
|
* @param WikiPage $wikiPage The article that was edited
|
2020-04-20 23:03:54 +00:00
|
|
|
* @param UserIdentity $agent The user who did the rollback
|
|
|
|
* @param RevisionRecord $newRevision The revision the page was reverted back to
|
|
|
|
* @param RevisionRecord $oldRevision The revision of the top edit that was reverted
|
2018-03-26 18:54:03 +00:00
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public function onRollbackComplete(
|
|
|
|
$wikiPage,
|
|
|
|
$agent,
|
|
|
|
$newRevision,
|
|
|
|
$oldRevision
|
2020-04-20 23:03:54 +00:00
|
|
|
) {
|
2020-07-21 11:15:09 +00:00
|
|
|
$revertedUser = $oldRevision->getUser();
|
2019-04-17 15:46:06 +00:00
|
|
|
$latestRevision = $wikiPage->getRevisionRecord();
|
2018-03-26 18:54:03 +00:00
|
|
|
|
|
|
|
if (
|
2020-07-21 11:18:29 +00:00
|
|
|
$revertedUser &&
|
2022-11-12 06:37:37 +00:00
|
|
|
// No notifications for anonymous users
|
|
|
|
$revertedUser->isRegistered() &&
|
|
|
|
// No notifications for null rollbacks
|
|
|
|
!$oldRevision->hasSameContent( $newRevision )
|
2018-03-26 18:54:03 +00:00
|
|
|
) {
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::create( [
|
2018-03-26 18:54:03 +00:00
|
|
|
'type' => 'reverted',
|
|
|
|
'title' => $wikiPage->getTitle(),
|
|
|
|
'extra' => [
|
2018-03-26 22:32:30 +00:00
|
|
|
'revid' => $latestRevision->getId(),
|
2020-07-21 11:18:29 +00:00
|
|
|
'reverted-user-id' => $revertedUser->getId(),
|
2018-03-26 18:54:03 +00:00
|
|
|
'reverted-revision-id' => $oldRevision->getId(),
|
|
|
|
'method' => 'rollback',
|
|
|
|
],
|
2021-12-19 01:16:52 +00:00
|
|
|
'agent' => $agent,
|
2018-03-26 18:54:03 +00:00
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public 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).
|
2021-05-04 16:06:42 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( static function () use ( $user ) {
|
2022-12-20 11:53:45 +00:00
|
|
|
if ( !$user->isRegistered() ) {
|
|
|
|
// It's possible the user account was deleted before the deferred
|
|
|
|
// update runs (T318081)
|
|
|
|
return;
|
|
|
|
}
|
2022-11-13 07:48:43 +00:00
|
|
|
NotifUser::newFromUser( $user )->resetNotificationCount();
|
2016-12-08 20:50:03 +00:00
|
|
|
} );
|
2013-11-21 00:31:01 +00:00
|
|
|
}
|
2013-04-12 22:12:22 +00:00
|
|
|
}
|
2013-04-26 16:08:40 +00:00
|
|
|
|
2021-07-27 17:53:58 +00:00
|
|
|
/**
|
|
|
|
* Some of Echo's subscription user preferences are mapped to existing user preferences defined in
|
|
|
|
* core MediaWiki. This returns the map of Echo preference names to core preference names.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getVirtualUserOptions() {
|
2023-10-15 06:08:48 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
2021-07-27 17:53:58 +00:00
|
|
|
$options = [];
|
|
|
|
$options['echo-subscriptions-email-edit-user-talk'] = 'enotifusertalkpages';
|
2023-10-15 06:08:48 +00:00
|
|
|
if ( $config->get( ConfigNames::WatchlistNotifications ) ) {
|
2021-07-27 17:53:58 +00:00
|
|
|
$options['echo-subscriptions-email-watchlist'] = 'enotifwatchlistpages';
|
|
|
|
$options['echo-subscriptions-email-minor-watchlist'] = 'enotifminoredits';
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
2013-04-26 16:08:40 +00:00
|
|
|
/**
|
2022-01-09 19:16:10 +00:00
|
|
|
* Handler for LoadUserOptions hook.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/LoadUserOptions
|
2021-07-26 16:28:06 +00:00
|
|
|
* @param UserIdentity $user User whose options were loaded
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param array &$options Options can be modified
|
2013-04-26 16:08:40 +00:00
|
|
|
*/
|
2022-08-22 22:31:10 +00:00
|
|
|
public function onLoadUserOptions( UserIdentity $user, &$options ): void {
|
2021-07-27 17:53:58 +00:00
|
|
|
foreach ( self::getVirtualUserOptions() as $echoPref => $mwPref ) {
|
|
|
|
// Use the existing core option's value for the Echo option
|
|
|
|
if ( isset( $options[ $mwPref ] ) ) {
|
|
|
|
$options[ $echoPref ] = $options[ $mwPref ];
|
2019-12-09 02:42:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-26 16:08:40 +00:00
|
|
|
}
|
2013-04-30 02:53:33 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-27 13:57:21 +00:00
|
|
|
* Handler for SaveUserOptions hook.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SaveUserOptions
|
|
|
|
* @param UserIdentity $user User whose options are being saved
|
|
|
|
* @param array &$modifiedOptions Options can be modified
|
2022-08-22 22:31:10 +00:00
|
|
|
* @param array $originalOptions
|
2013-04-30 02:53:33 +00:00
|
|
|
*/
|
2022-08-22 22:31:10 +00:00
|
|
|
public function onSaveUserOptions( UserIdentity $user, array &$modifiedOptions, array $originalOptions ) {
|
2021-07-27 17:53:58 +00:00
|
|
|
foreach ( self::getVirtualUserOptions() as $echoPref => $mwPref ) {
|
|
|
|
// Save virtual option values in corresponding real option values
|
2021-07-27 13:57:21 +00:00
|
|
|
if ( isset( $modifiedOptions[ $echoPref ] ) ) {
|
|
|
|
$modifiedOptions[ $mwPref ] = $modifiedOptions[ $echoPref ];
|
|
|
|
unset( $modifiedOptions[ $echoPref ] );
|
2019-12-09 02:42:55 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
2020-05-23 05:06:12 +00:00
|
|
|
* @param UserIdentity $user User whose talk page notification should be marked as read
|
2022-08-22 22:31:10 +00:00
|
|
|
* @param int $oldid
|
2013-05-24 22:51:47 +00:00
|
|
|
*/
|
2022-08-22 22:31:10 +00:00
|
|
|
public function onUserClearNewTalkNotification( $user, $oldid ) {
|
2020-05-23 05:06:12 +00:00
|
|
|
if ( $user->isRegistered() ) {
|
2021-12-19 01:16:52 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( static function () use ( $user ) {
|
2022-11-13 07:48:43 +00:00
|
|
|
NotifUser::newFromUser( $user )->clearUserTalkNotifications();
|
2015-08-26 23:31:58 +00:00
|
|
|
} );
|
2013-05-24 22:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2022-08-22 22:31:10 +00:00
|
|
|
public function onEmailUserComplete( $address, $from, $subject, $text ) {
|
2015-09-19 20:49:34 +00:00
|
|
|
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 );
|
2023-10-14 16:26:42 +00:00
|
|
|
$preview = $this->contentLanguage->truncateForVisual( $textWithoutFooter, 125 );
|
2016-02-10 22:09:41 +00:00
|
|
|
} else {
|
|
|
|
$preview = $subject;
|
|
|
|
}
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::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
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2022-08-22 22:36:48 +00:00
|
|
|
public function onLoginFormValidErrorMessages( array &$messages ) {
|
2015-12-08 18:54:44 +00:00
|
|
|
$messages[] = 'echo-notification-loginrequired';
|
|
|
|
}
|
|
|
|
|
2022-05-20 02:11:31 +00:00
|
|
|
public static function getConfigVars( RL\Context $context, Config $config ) {
|
2019-07-03 23:04:14 +00:00
|
|
|
return [
|
2022-11-13 07:48:43 +00:00
|
|
|
'EchoMaxNotificationCount' => NotifUser::MAX_BADGE_COUNT,
|
2023-10-15 06:08:48 +00:00
|
|
|
'EchoPollForUpdates' => $config->get( ConfigNames::PollForUpdates )
|
2019-07-03 23:04:14 +00:00
|
|
|
];
|
2016-02-18 22:36:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 13:25:18 +00:00
|
|
|
/**
|
2022-08-22 22:36:48 +00:00
|
|
|
* @param WikiPage $article
|
|
|
|
* @param User $user
|
2019-03-11 13:25:18 +00:00
|
|
|
* @param string $reason
|
|
|
|
* @param int $articleId
|
|
|
|
* @param Content|null $content
|
|
|
|
* @param LogEntry $logEntry
|
2022-08-22 22:36:48 +00:00
|
|
|
* @param int $archivedRevisionCount
|
2019-03-11 13:25:18 +00:00
|
|
|
*/
|
2022-08-22 22:36:48 +00:00
|
|
|
public function onArticleDeleteComplete(
|
|
|
|
$article,
|
|
|
|
$user,
|
2018-08-25 10:51:14 +00:00
|
|
|
$reason,
|
|
|
|
$articleId,
|
2022-08-22 22:36:48 +00:00
|
|
|
$content,
|
|
|
|
$logEntry,
|
|
|
|
$archivedRevisionCount
|
2018-08-25 10:51:14 +00:00
|
|
|
) {
|
2022-04-08 00:28:15 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( static function () use ( $articleId ) {
|
2022-11-02 20:47:04 +00:00
|
|
|
$eventMapper = new EventMapper();
|
2016-07-27 14:52:18 +00:00
|
|
|
$eventIds = $eventMapper->fetchIdsByPage( $articleId );
|
2022-11-02 03:51:15 +00:00
|
|
|
ModerationController::moderate( $eventIds, true );
|
2016-07-27 14:52:18 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2022-08-22 22:36:48 +00:00
|
|
|
/**
|
|
|
|
* @param Title $title
|
|
|
|
* @param bool $create
|
|
|
|
* @param string $comment
|
|
|
|
* @param int $oldPageId
|
|
|
|
* @param array $restoredPages
|
|
|
|
*/
|
|
|
|
public function onArticleUndelete( $title, $create, $comment, $oldPageId, $restoredPages ) {
|
2016-07-27 14:52:18 +00:00
|
|
|
if ( $create ) {
|
2022-04-08 00:28:15 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( static function () use ( $oldPageId ) {
|
2022-11-02 20:47:04 +00:00
|
|
|
$eventMapper = new EventMapper();
|
2016-07-27 14:52:18 +00:00
|
|
|
$eventIds = $eventMapper->fetchIdsByPage( $oldPageId );
|
2022-11-02 03:51:15 +00:00
|
|
|
ModerationController::moderate( $eventIds, false );
|
2016-07-27 14:52:18 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-01 17:49:31 +00:00
|
|
|
/**
|
|
|
|
* Handler for SpecialMuteModifyFormFields hook
|
|
|
|
*
|
2021-06-24 19:21:49 +00:00
|
|
|
* @param UserIdentity|null $target
|
2020-10-30 14:26:36 +00:00
|
|
|
* @param User $user
|
2019-07-01 17:49:31 +00:00
|
|
|
* @param array &$fields
|
|
|
|
*/
|
2023-08-15 15:30:57 +00:00
|
|
|
public function onSpecialMuteModifyFormFields( $target, $user, &$fields ) {
|
2023-10-15 06:08:48 +00:00
|
|
|
$echoPerUserBlacklist = $this->config->get( ConfigNames::PerUserBlacklist );
|
2019-07-01 17:49:31 +00:00
|
|
|
if ( $echoPerUserBlacklist ) {
|
2023-10-14 16:26:42 +00:00
|
|
|
$id = $target ? $this->centralIdLookup->centralIdFromLocalUser( $target ) : 0;
|
2021-12-01 18:29:00 +00:00
|
|
|
$list = MultiUsernameFilter::splitIds(
|
2023-10-14 16:26:42 +00:00
|
|
|
$this->userOptionsManager->getOption( $user, 'echo-notifications-blacklist' )
|
2021-12-01 18:29:00 +00:00
|
|
|
);
|
2019-07-01 17:49:31 +00:00
|
|
|
$fields[ 'echo-notifications-blacklist'] = [
|
|
|
|
'type' => 'check',
|
2020-05-03 07:27:58 +00:00
|
|
|
'label-message' => [
|
|
|
|
'echo-specialmute-label-mute-notifications',
|
2020-06-25 10:53:12 +00:00
|
|
|
$target ? $target->getName() : ''
|
2020-05-03 07:27:58 +00:00
|
|
|
],
|
2020-10-30 14:26:36 +00:00
|
|
|
'default' => in_array( $id, $list, true ),
|
2019-07-01 17:49:31 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 02:42:55 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-03 09:20:46 +00:00
|
|
|
* @param RecentChange $change
|
|
|
|
* @return bool|void
|
2019-12-09 02:42:55 +00:00
|
|
|
*/
|
2020-06-03 09:20:46 +00:00
|
|
|
public function onRecentChange_save( $change ) {
|
|
|
|
if ( !$this->config->get( 'EchoWatchlistNotifications' ) ) {
|
2019-12-09 02:42:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( $change->getAttribute( 'rc_minor' ) ) {
|
|
|
|
$type = 'minor-watchlist-change';
|
|
|
|
} else {
|
|
|
|
$type = 'watchlist-change';
|
|
|
|
}
|
2022-11-02 21:34:17 +00:00
|
|
|
Event::create( [
|
2019-12-09 02:42:55 +00:00
|
|
|
'type' => $type,
|
|
|
|
'title' => $change->getTitle(),
|
|
|
|
'extra' => [
|
2021-11-03 14:47:50 +00:00
|
|
|
'page_title' => $change->getPage()->getDBkey(),
|
|
|
|
'page_namespace' => $change->getPage()->getNamespace(),
|
2019-12-09 02:42:55 +00:00
|
|
|
'revid' => $change->getAttribute( "rc_this_oldid" ),
|
|
|
|
'logid' => $change->getAttribute( "rc_logid" ),
|
|
|
|
'status' => $change->mExtra["pageStatus"],
|
2020-06-01 02:17:13 +00:00
|
|
|
'timestamp' => $change->getAttribute( "rc_timestamp" ),
|
2023-10-15 06:08:48 +00:00
|
|
|
'emailonce' => $this->config->get( ConfigNames::WatchlistEmailOncePerPage ),
|
2019-12-09 02:42:55 +00:00
|
|
|
],
|
2021-12-19 01:16:52 +00:00
|
|
|
'agent' => $change->getPerformerIdentity(),
|
2019-12-09 02:42:55 +00:00
|
|
|
] );
|
|
|
|
}
|
2020-05-15 17:19:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook handler for ApiMain::moduleManager.
|
|
|
|
* Used here to put the echopushsubscriptions API module behind our push feature flag.
|
|
|
|
* TODO: Register this the usual way in extension.json when we don't need the feature flag
|
|
|
|
* anymore.
|
|
|
|
* @param ApiModuleManager $moduleManager
|
|
|
|
*/
|
2022-08-22 22:46:42 +00:00
|
|
|
public function onApiMain__ModuleManager( $moduleManager ) {
|
2023-10-14 16:26:42 +00:00
|
|
|
$pushEnabled = $this->config->get( 'EchoEnablePush' );
|
2020-05-15 17:19:03 +00:00
|
|
|
if ( $pushEnabled ) {
|
|
|
|
$moduleManager->addModule(
|
|
|
|
'echopushsubscriptions',
|
|
|
|
'action',
|
2022-04-08 00:28:15 +00:00
|
|
|
ApiEchoPushSubscriptions::class
|
2020-05-15 17:19:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-06-03 09:20:46 +00:00
|
|
|
|
2012-07-18 16:28:41 +00:00
|
|
|
}
|