2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
|
|
|
use EchoDiscussionParser;
|
2023-05-19 10:30:54 +00:00
|
|
|
use MediaWiki\Language\RawMessage;
|
2022-11-01 22:01:23 +00:00
|
|
|
use SpecialPage;
|
|
|
|
use User;
|
|
|
|
|
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();
|
2016-03-10 00:22:52 +00:00
|
|
|
$add = array_map(
|
2016-12-05 18:51:07 +00:00
|
|
|
[ $this->language, 'embedBidi' ],
|
|
|
|
$this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'add', [] ) ) )
|
2016-03-10 00:22:52 +00:00
|
|
|
);
|
|
|
|
$remove = array_map(
|
2016-12-05 18:51:07 +00:00
|
|
|
[ $this->language, 'embedBidi' ],
|
|
|
|
$this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'remove', [] ) ) )
|
2016-03-10 00:22:52 +00:00
|
|
|
);
|
2017-04-08 07:43:05 +00:00
|
|
|
$expiryChanged = array_map(
|
|
|
|
[ $this->language, 'embedBidi' ],
|
|
|
|
$this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'expiry-changed', [] ) ) )
|
|
|
|
);
|
|
|
|
if ( $expiryChanged ) {
|
|
|
|
$msg = $this->msg( 'notification-header-user-rights-expiry-change' );
|
|
|
|
$msg->params( $genderName );
|
|
|
|
$msg->params( $this->language->commaList( $expiryChanged ) );
|
|
|
|
$msg->params( count( $expiryChanged ) );
|
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
|
|
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 ) );
|
2016-01-29 21:07:39 +00:00
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
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 ) );
|
2016-01-29 21:07:39 +00:00
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
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 ) );
|
2016-01-29 21:07:39 +00:00
|
|
|
$msg->params( $this->getViewingUserForGender() );
|
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 ) {
|
|
|
|
$text = EchoDiscussionParser::getTextSnippet( $reason, $this->language );
|
|
|
|
return new RawMessage( "$1", [ $text ] );
|
|
|
|
}
|
|
|
|
return false;
|
2016-02-08 20:45:44 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 10:44:35 +00:00
|
|
|
private function getLocalizedGroupNames( array $names ) {
|
2017-06-20 02:41:30 +00:00
|
|
|
return array_map( function ( $name ) {
|
2016-01-28 16:42:21 +00:00
|
|
|
$msg = $this->msg( 'group-' . $name );
|
|
|
|
return $msg->isBlank() ? $name : $msg->text();
|
|
|
|
}, $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
|
|
|
}
|