From 3f9b5eea71d7658c7ed2f173385d8db15f0dc665 Mon Sep 17 00:00:00 2001 From: Lens0021 Date: Tue, 15 Dec 2020 10:05:39 +0900 Subject: [PATCH] Notify when a sanction against the user is proposed (#112) (cherry picked from commit 0426c1bf403e5da3a3853049313725e02456fda0) --- extension.json | 8 ++++- i18n/en.json | 14 +++++--- i18n/ko.json | 6 +++- i18n/qqq.json | 6 +++- includes/Sanction.php | 11 ++++++ includes/SanctionsHooks.php | 23 ++++++++++++ .../ProposedPresentationModel.php | 36 +++++++++++++++++++ 7 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 includes/notifications/ProposedPresentationModel.php diff --git a/extension.json b/extension.json index 34b55e1..4f187e4 100644 --- a/extension.json +++ b/extension.json @@ -20,7 +20,8 @@ "SanctionsPager": "includes/SanctionsPager.php", "Sanction": "includes/Sanction.php", "SanctionsHooks": "includes/SanctionsHooks.php", - "SanctionsUtils": "includes/SanctionsUtils.php" + "SanctionsUtils": "includes/SanctionsUtils.php", + "ProposedPresentationModel": "includes/notifications/ProposedPresentationModel.php" }, "ResourceModules": { "ext.sanctions.special.sanctions.styles": { @@ -97,6 +98,7 @@ "LoadExtensionSchemaUpdates": "SanctionsHooks::onLoadExtensionSchemaUpdates", "AbortEmailNotification": "SanctionsHooks::onAbortEmailNotification", "BeforeEchoEventInsert": "SanctionsHooks::onBeforeEchoEventInsert", + "BeforeCreateEchoEvent": "SanctionsHooks::onBeforeCreateEchoEvent", "EmailConfirmed": "SanctionsHooks::onEmailConfirmed", "ResourceLoaderGetConfigVars": "SanctionsHooks::onResourceLoaderGetConfigVars", "UserToolLinksEdit": "SanctionsHooks::onUserToolLinksEdit", @@ -109,6 +111,10 @@ "SpecialPages": { "Sanctions": "SpacialSanctions" }, + "DefaultUserOptions": { + "echo-subscriptions-web-sanctions-against-me": true, + "echo-subscriptions-email-sanctions-against-me": true + }, "MessagesDirs": { "Sanctions": [ "i18n" ] }, diff --git a/i18n/en.json b/i18n/en.json index f126b22..c739946 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -24,7 +24,7 @@ "sanctions-unable-create-new-logged-in": "You cannot participate in sanction process because of following reason(s). Visit [[Project:Block]] for detail.", "sanctions-form-target": "Target :", "sanctions-form-for-insulting-name": "Is it for insulting name?", - "sanctions-content-placeholder": "Enter the content of the sacntion.", + "sanctions-content-placeholder": "Enter the content of the sanction.", "sanctions-submit": "Submit", "sanctions-topic-no-description": "No description provided.", "sanctions-topic-revision": "* [[Special:Redirect/revision/$1|$2 (New page)]]", @@ -72,7 +72,7 @@ "sanctions-topic-summary-reason-more-than-three-and-not-agreed": "Number of participants is over three with agreed by $1 of them(under ⅔)", "sanctions-topic-summary-deadline": "End date: $1", "sanctions-topic-auto-reply-no-count": "Above reply is not counted because:", - "sanctions-topic-auto-reply-unable-self-agree": "Cannot vote to a sanction made by youself.", + "sanctions-topic-auto-reply-unable-self-agree": "Cannot vote to a sanction made by yourself.", "sanctions-log-take-temporary-measure": "Raising priority of [[Topic:$1|sanction]].", "sanctions-log-remove-temporary-measure": "lowering priority of [[Topic:$1|sanction]].", "sanctions-log-take-measure": "[[Topic:$1|Sanction]] passed.", @@ -85,8 +85,8 @@ "sanctions-reason-blocked": "Being blocked", "sanctions-reason-recently-blocked": "$2 days from unblocked $1 does not elapse", "sanctions-link-on-user-tool": "Sanctions", - "sanctions-link-on-diff": "Issue a new sanction based on this", - "sanctions-link-on-history": "Issue a new sanction based on this", + "sanctions-link-on-diff": "Propose a new sanction based on this", + "sanctions-link-on-history": "Propose a new sanction based on this", "sanctions-link-on-user-contributes": "Sanctions", "sanctions-link-on-user-page": "Sanctions", "sanctions-agree-template-title": "Support", @@ -98,5 +98,9 @@ "sanctions-ve-vote-disagree-tool-title": "Oppose", "sanctions-ve-agree-days-inspector-title": "Expiration", "sanctions-ve-agree-days-inspector-remove-label": "Remove", - "sanctions-ve-agree-days-inspector-invalid-value": "\"$1\" is not valid." + "sanctions-ve-agree-days-inspector-invalid-value": "\"$1\" is not valid.", + "echo-category-title-sanctions-against-me": "Sanction against me", + "sanctions-pref-tooltip-sanctions-against-me": "Notify me when a sanction against me is proposed or issued.", + "notification-header-sanctions-proposed-against-insulting-name": "A sanction against {{GENDER:$2|your}} username have been proposed.", + "notification-header-sanctions-proposed": "A sanction against {{GENDER:$2|your}} future edit have been proposed." } diff --git a/i18n/ko.json b/i18n/ko.json index 227a6a1..b6ae11d 100644 --- a/i18n/ko.json +++ b/i18n/ko.json @@ -99,5 +99,9 @@ "sanctions-ve-vote-disagree-tool-title": "반대하기", "sanctions-ve-agree-days-inspector-title": "기한", "sanctions-ve-agree-days-inspector-remove-label": "제거", - "sanctions-ve-agree-days-inspector-invalid-value": "$1 입력은 올바른 값이 아닙니다." + "sanctions-ve-agree-days-inspector-invalid-value": "$1 입력은 올바른 값이 아닙니다.", + "echo-category-title-sanctions-against-me": "나에 대한 제재안", + "sanctions-pref-tooltip-sanctions-against-me": "나에 대한 제재안이 발의됐거나 집행되었을 때 내게 알립니다.", + "notification-header-sanctions-proposed-against-insulting-name": "{{GENDER:$2|내}} 사용자명에 대한 변경 건의가 있습니다.", + "notification-header-sanctions-proposed": "{{GENDER:$2|나에}} 대한 편집 차단 건의가 있습니다." } diff --git a/i18n/qqq.json b/i18n/qqq.json index 430479b..e41af0e 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -99,5 +99,9 @@ "sanctions-ve-vote-disagree-tool-title": "Title text for the disagree tool on Structured Discussions's VisualEditor toolbar.", "sanctions-ve-agree-days-inspector-title": "Title text for day selector inspector", "sanctions-ve-agree-days-inspector-remove-label": "Text of remove button on Structured Discussions's choose expiration panel (inspector) in the VisualEditor.", - "sanctions-ve-agree-days-inspector-invalid-value": "Error message. Parameters:\n$1: Entered value." + "sanctions-ve-agree-days-inspector-invalid-value": "Error message. Parameters:\n$1: Entered value.", + "echo-category-title-sanctions-against-me": "{{doc-echo-category-title|tooltip=sanctions-pref-tooltip-sanctions-against-me}}", + "sanctions-pref-tooltip-sanctions-against-me": "{{doc-echo-pref-tooltip|title=echo-category-title-sanctions-against-me}}", + "notification-header-sanctions-proposed-against-insulting-name": "Header text for a notification when a sanction against your username have been proposed.", + "notification-header-sanctions-proposed": "Header text for a notification when a sanction against your future edit have been proposed." } diff --git a/includes/Sanction.php b/includes/Sanction.php index 01638dc..ea695cb 100644 --- a/includes/Sanction.php +++ b/includes/Sanction.php @@ -153,6 +153,17 @@ public static function write( $user, $target, $forInsultingName, $content ) { if ( !$sanction->updateTopicSummary() ) { // @todo } + + EchoEvent::create( [ + 'type' => 'sanctions-proposed', + 'title' => $sanction->getTopic(), + 'extra' => [ + 'target-id' => $targetId, + 'is-for-insulting-name' => $forInsultingName, + ], + 'agent' => $user, + ] ); + return $sanction; } diff --git a/includes/SanctionsHooks.php b/includes/SanctionsHooks.php index f02f361..fe64d0e 100644 --- a/includes/SanctionsHooks.php +++ b/includes/SanctionsHooks.php @@ -106,6 +106,29 @@ public static function onBeforeEchoEventInsert( EchoEvent $event ) { return true; } + /** + * Defining the events for this extension + * + * @param array &$notifs + * @param array &$categories + * @param array &$icons + */ + public static function onBeforeCreateEchoEvent( &$notifs, &$categories, &$icons ) { + $categories['sanctions-against-me'] = [ + 'priority' => 1, + 'no-dismiss' => [ 'web' ], + 'tooltip' => 'sanctions-pref-tooltip-sanctions-against-me', + ]; + + $notifs['sanctions-proposed'] = [ + 'category' => 'sanctions-against-me', + 'group' => 'negative', + 'section' => 'alert', + 'presentation-model' => ProposedPresentationModel::class, + 'user-locators' => [ [ 'EchoUserLocator::locateFromEventExtra', [ 'target-id' ] ] ], + ]; + } + /** * @param User $user * @return bool diff --git a/includes/notifications/ProposedPresentationModel.php b/includes/notifications/ProposedPresentationModel.php new file mode 100644 index 0000000..dd598ea --- /dev/null +++ b/includes/notifications/ProposedPresentationModel.php @@ -0,0 +1,36 @@ +event->getTitle(); + } + + /** + * @return string + */ + public function getIconType() { + return 'placeholder'; + } + + /** + * @return array + */ + public function getPrimaryLink() { + $link = $this->getPageLink( $this->event->getTitle(), '', true ); + return $link; + } + + /** + * @return Message + */ + public function getHeaderMessage() { + $event = $this->event; + if ( $event->getExtraParam( 'is-for-insulting-name' ) ) { + $msg = $this->getMessageWithAgent( 'notification-header-sanctions-proposed-against-insulting-name' ); + } else { + $msg = $this->getMessageWithAgent( 'notification-header-sanctions-proposed' ); + } + return $msg; + } +}