2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
2016-01-28 16:42:21 +00:00
|
|
|
list( $formattedName, $genderName ) = $this->getAgentForOutput();
|
2016-03-10 00:22:52 +00:00
|
|
|
$add = array_map(
|
|
|
|
array( $this->language, 'embedBidi' ),
|
|
|
|
$this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'add', array() ) ) )
|
|
|
|
);
|
|
|
|
$remove = array_map(
|
|
|
|
array( $this->language, 'embedBidi' ),
|
|
|
|
$this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'remove', array() ) ) )
|
|
|
|
);
|
2016-01-28 16:42:21 +00:00
|
|
|
if ( $add && !$remove ) {
|
|
|
|
$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' );
|
|
|
|
return $reason ? $this->msg( 'notification-body-user-rights' )->params( $reason ) : false;
|
|
|
|
}
|
|
|
|
|
2016-01-28 16:42:21 +00:00
|
|
|
private function getLocalizedGroupNames( $names ) {
|
|
|
|
return array_map( function( $name ) {
|
|
|
|
$msg = $this->msg( 'group-' . $name );
|
|
|
|
return $msg->isBlank() ? $name : $msg->text();
|
|
|
|
}, $names );
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrimaryLink() {
|
2016-09-23 00:05:33 +00:00
|
|
|
$addedGroups = array_values( $this->event->getExtraParam( 'add', array() ) );
|
|
|
|
$removedGroups = array_values( $this->event->getExtraParam( 'remove', array() ) );
|
|
|
|
if ( count( $addedGroups ) >= 1 && count( $removedGroups ) === 0 ) {
|
|
|
|
$fragment = $addedGroups[0];
|
|
|
|
} elseif ( count( $addedGroups ) === 0 && count( $removedGroups ) >= 1 ) {
|
|
|
|
$fragment = $removedGroups[0];
|
|
|
|
} else {
|
|
|
|
$fragment = '';
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
return array(
|
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()
|
2015-08-19 20:22:45 +00:00
|
|
|
);
|
|
|
|
}
|
2015-12-22 15:57:13 +00:00
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
2016-02-24 16:36:22 +00:00
|
|
|
return array( $this->getAgentLink(), $this->getLogLink() );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getLogLink() {
|
|
|
|
$affectedUserPage = User::newFromId( $this->event->getExtraParam( 'user' ) )->getUserPage();
|
|
|
|
$query = array(
|
|
|
|
'type' => 'rights',
|
|
|
|
'page' => $affectedUserPage->getPrefixedText(),
|
|
|
|
'user' => $this->event->getAgent()->getName(),
|
|
|
|
);
|
|
|
|
return array(
|
|
|
|
'label' => $this->msg( 'echo-log' )->text(),
|
|
|
|
'url' => SpecialPage::getTitleFor( 'Log' )->getFullURL( $query ),
|
|
|
|
'description' => '',
|
|
|
|
'icon' => false,
|
|
|
|
'prioritized' => true,
|
|
|
|
);
|
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
|
|
|
}
|