Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
Notify when a sanction against the user is proposed (#112)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0426c1b)
  • Loading branch information
lens0021 committed Dec 15, 2020
1 parent 2307b13 commit 3f9b5ee
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 8 deletions.
8 changes: 7 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand All @@ -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" ]
},
Expand Down
14 changes: 9 additions & 5 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)]]",
Expand Down Expand Up @@ -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.",
Expand All @@ -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",
Expand All @@ -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."
}
6 changes: 5 additions & 1 deletion i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -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|나에}} 대한 편집 차단 건의가 있습니다."
}
6 changes: 5 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
11 changes: 11 additions & 0 deletions includes/Sanction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 23 additions & 0 deletions includes/SanctionsHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions includes/notifications/ProposedPresentationModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

class ProposedPresentationModel extends EchoEventPresentationModel {

public function canRender() {
return (bool)$this->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;
}
}

0 comments on commit 3f9b5ee

Please sign in to comment.