2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DiscussionParser;
|
2023-05-19 10:30:54 +00:00
|
|
|
use MediaWiki\Language\RawMessage;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
|
|
|
use MediaWiki\User\User;
|
2022-11-01 22:01:23 +00:00
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
/**
|
|
|
|
* Formatter for 'user-rights' notifications
|
|
|
|
*/
|
|
|
|
class EchoUserRightsPresentationModel extends EchoEventPresentationModel {
|
|
|
|
|
|
|
|
public function getIconType() {
|
2016-01-13 04:24:11 +00:00
|
|
|
return 'user-rights';
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeaderMessage() {
|
2022-11-08 16:41:24 +00:00
|
|
|
[ $formattedName, $genderName ] = $this->getAgentForOutput();
|
2024-07-05 18:18:56 +00:00
|
|
|
$viewingUser = $this->getViewingUserForGender();
|
2016-03-10 00:22:52 +00:00
|
|
|
$add = array_map(
|
2016-12-05 18:51:07 +00:00
|
|
|
[ $this->language, 'embedBidi' ],
|
2024-07-05 18:18:56 +00:00
|
|
|
$this->getLocalizedGroupNames( $this->event->getExtraParam( 'add', [] ), $viewingUser )
|
2016-03-10 00:22:52 +00:00
|
|
|
);
|
|
|
|
$remove = array_map(
|
2016-12-05 18:51:07 +00:00
|
|
|
[ $this->language, 'embedBidi' ],
|
2024-07-05 18:18:56 +00:00
|
|
|
$this->getLocalizedGroupNames( $this->event->getExtraParam( 'remove', [] ), $viewingUser )
|
2016-03-10 00:22:52 +00:00
|
|
|
);
|
2017-04-08 07:43:05 +00:00
|
|
|
$expiryChanged = array_map(
|
|
|
|
[ $this->language, 'embedBidi' ],
|
2024-07-05 18:18:56 +00:00
|
|
|
$this->getLocalizedGroupNames( $this->event->getExtraParam( 'expiry-changed', [] ), $viewingUser )
|
2017-04-08 07:43:05 +00:00
|
|
|
);
|
|
|
|
if ( $expiryChanged ) {
|
|
|
|
$msg = $this->msg( 'notification-header-user-rights-expiry-change' );
|
|
|
|
$msg->params( $genderName );
|
|
|
|
$msg->params( $this->language->commaList( $expiryChanged ) );
|
|
|
|
$msg->params( count( $expiryChanged ) );
|
2024-07-05 18:18:56 +00:00
|
|
|
$msg->params( $viewingUser );
|
2017-04-08 07:43:05 +00:00
|
|
|
return $msg;
|
|
|
|
} elseif ( $add && !$remove ) {
|
2016-01-28 16:42:21 +00:00
|
|
|
$msg = $this->msg( 'notification-header-user-rights-add-only' );
|
|
|
|
$msg->params( $genderName );
|
2016-02-08 13:44:26 +00:00
|
|
|
$msg->params( $this->language->commaList( $add ) );
|
2016-01-28 16:42:21 +00:00
|
|
|
$msg->params( count( $add ) );
|
2024-07-05 18:18:56 +00:00
|
|
|
$msg->params( $viewingUser );
|
2016-01-28 16:42:21 +00:00
|
|
|
return $msg;
|
|
|
|
} elseif ( !$add && $remove ) {
|
|
|
|
$msg = $this->msg( 'notification-header-user-rights-remove-only' );
|
|
|
|
$msg->params( $genderName );
|
2016-02-08 13:44:26 +00:00
|
|
|
$msg->params( $this->language->commaList( $remove ) );
|
2016-01-28 16:42:21 +00:00
|
|
|
$msg->params( count( $remove ) );
|
2024-07-05 18:18:56 +00:00
|
|
|
$msg->params( $viewingUser );
|
2016-01-28 16:42:21 +00:00
|
|
|
return $msg;
|
|
|
|
} else {
|
|
|
|
$msg = $this->msg( 'notification-header-user-rights-add-and-remove' );
|
|
|
|
$msg->params( $genderName );
|
2016-02-08 13:44:26 +00:00
|
|
|
$msg->params( $this->language->commaList( $add ) );
|
2016-01-28 16:42:21 +00:00
|
|
|
$msg->params( count( $add ) );
|
2016-02-08 13:44:26 +00:00
|
|
|
$msg->params( $this->language->commaList( $remove ) );
|
2016-01-28 16:42:21 +00:00
|
|
|
$msg->params( count( $remove ) );
|
2024-07-05 18:18:56 +00:00
|
|
|
$msg->params( $viewingUser );
|
2016-01-28 16:42:21 +00:00
|
|
|
return $msg;
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
2016-01-28 16:42:21 +00:00
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
|
2016-02-08 20:45:44 +00:00
|
|
|
public function getBodyMessage() {
|
|
|
|
$reason = $this->event->getExtraParam( 'reason' );
|
2018-01-09 13:41:21 +00:00
|
|
|
if ( $reason ) {
|
2022-11-12 07:19:00 +00:00
|
|
|
$text = DiscussionParser::getTextSnippet( $reason, $this->language );
|
2018-01-09 13:41:21 +00:00
|
|
|
return new RawMessage( "$1", [ $text ] );
|
|
|
|
}
|
|
|
|
return false;
|
2016-02-08 20:45:44 +00:00
|
|
|
}
|
|
|
|
|
2024-06-28 09:41:53 +00:00
|
|
|
/**
|
|
|
|
* @param string[] $names
|
|
|
|
* @param string $genderName
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
private function getLocalizedGroupNames( array $names, string $genderName ) {
|
|
|
|
return array_map(
|
|
|
|
fn ( $name ) => $this->language->getGroupMemberName( $name, $genderName ),
|
|
|
|
array_values( $names )
|
|
|
|
);
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrimaryLink() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$addedGroups = array_values( $this->event->getExtraParam( 'add', [] ) );
|
|
|
|
$removedGroups = array_values( $this->event->getExtraParam( 'remove', [] ) );
|
2018-06-17 16:59:03 +00:00
|
|
|
if ( $addedGroups !== [] && $removedGroups === [] ) {
|
2016-09-23 00:05:33 +00:00
|
|
|
$fragment = $addedGroups[0];
|
2018-06-17 16:59:03 +00:00
|
|
|
} elseif ( $addedGroups === [] && $removedGroups !== [] ) {
|
2016-09-23 00:05:33 +00:00
|
|
|
$fragment = $removedGroups[0];
|
|
|
|
} else {
|
|
|
|
$fragment = '';
|
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2016-09-23 00:05:33 +00:00
|
|
|
'url' => SpecialPage::getTitleFor( 'Listgrouprights', false, $fragment )->getFullURL(),
|
2015-12-16 16:52:02 +00:00
|
|
|
'label' => $this->msg( 'echo-learn-more' )->text()
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
2015-12-22 15:57:13 +00:00
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ $this->getAgentLink(), $this->getLogLink() ];
|
2016-02-24 16:36:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getLogLink() {
|
|
|
|
$affectedUserPage = User::newFromId( $this->event->getExtraParam( 'user' ) )->getUserPage();
|
2016-12-05 18:51:07 +00:00
|
|
|
$query = [
|
2016-02-24 16:36:22 +00:00
|
|
|
'type' => 'rights',
|
|
|
|
'page' => $affectedUserPage->getPrefixedText(),
|
|
|
|
'user' => $this->event->getAgent()->getName(),
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
|
|
|
return [
|
2016-02-24 16:36:22 +00:00
|
|
|
'label' => $this->msg( 'echo-log' )->text(),
|
|
|
|
'url' => SpecialPage::getTitleFor( 'Log' )->getFullURL( $query ),
|
|
|
|
'description' => '',
|
|
|
|
'icon' => false,
|
|
|
|
'prioritized' => true,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-12-22 15:57:13 +00:00
|
|
|
}
|
2016-05-05 13:05:03 +00:00
|
|
|
|
|
|
|
protected function getSubjectMessageKey() {
|
|
|
|
return 'notification-user-rights-email-subject';
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|