| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
namespace MediaWiki\Extension\DiscussionTools\Notifications; |
| 11 |
|
| 12 |
use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; |
| 13 |
use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection; |
| 14 |
use MediaWiki\Extension\Notifications\Model\Event; |
| 15 |
use MediaWiki\Language\Language; |
| 16 |
use MediaWiki\Language\RawMessage; |
| 17 |
use MediaWiki\Message\Message; |
| 18 |
use MediaWiki\Revision\RevisionRecord; |
| 19 |
use MediaWiki\User\User; |
| 20 |
|
| 21 |
class CommentThanksPresentationModel extends EchoEventPresentationModel { |
| 22 |
|
| 23 |
use DiscussionToolsEventTrait; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
private $section; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
protected function __construct( Event $event, Language $language, User $user, $distributionType ) { |
| 34 |
parent::__construct( $event, $language, $user, $distributionType ); |
| 35 |
$this->section = new EchoPresentationModelSection( $event, $user, $language ); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function getIconType() { |
| 42 |
return 'thanks'; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function canRender() { |
| 49 |
return (bool)$this->event->getTitle(); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function getPrimaryLink() { |
| 56 |
return [ |
| 57 |
'url' => $this->getCommentLink() ?: $this->event->getTitle()->getFullURL(), |
| 58 |
'label' => $this->msg( 'discussiontools-notification-subscribed-new-comment-view' )->text() |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
protected function getCommentLink(): ?string { |
| 68 |
if ( !$this->userCan( RevisionRecord::DELETED_TEXT ) ) { |
| 69 |
return null; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
$commentId = $this->event->getExtraParam( 'comment-id' ); |
| 74 |
if ( !$commentId ) { |
| 75 |
return null; |
| 76 |
} |
| 77 |
$title = $this->event->getTitle(); |
| 78 |
return $title->createFragmentTarget( $commentId )->getFullURL(); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
protected function getHeaderMessageKey() { |
| 85 |
if ( $this->isBundled() ) { |
| 86 |
return 'discussiontools-notification-comment-thank-header-bundled'; |
| 87 |
} else { |
| 88 |
return 'discussiontools-notification-comment-thank-header'; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public function getHeaderMessage() { |
| 96 |
$title = $this->section->getTruncatedSectionTitle(); |
| 97 |
if ( !$title ) { |
| 98 |
|
| 99 |
|
| 100 |
$title = $this->event->getTitle()->getPrefixedText(); |
| 101 |
} |
| 102 |
if ( $this->isBundled() ) { |
| 103 |
$count = $this->getNotificationCountForOutput(); |
| 104 |
$msg = $this->msg( $this->getHeaderMessageKey() ); |
| 105 |
|
| 106 |
|
| 107 |
$msg->numParams( $count ); |
| 108 |
$msg->plaintextParams( $title ); |
| 109 |
$msg->params( $this->getViewingUserForGender() ); |
| 110 |
return $msg; |
| 111 |
} else { |
| 112 |
$msg = parent::getHeaderMessage(); |
| 113 |
|
| 114 |
$msg->plaintextParams( $title ); |
| 115 |
$msg->params( $this->getViewingUserForGender() ); |
| 116 |
return $msg; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public function getCompactHeaderMessage() { |
| 124 |
$msg = $this->getMessageWithAgent( 'discussiontools-notification-comment-thank-header-compact' ); |
| 125 |
|
| 126 |
$msg->params( $this->getViewingUserForGender() ); |
| 127 |
return $msg; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public function getBodyMessage() { |
| 134 |
if ( !$this->isBundled() ) { |
| 135 |
return new RawMessage( '$1', [ Message::plaintextParam( $this->getContentSnippet() ) ] ); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public function getSecondaryLinks() { |
| 143 |
$pageLink = $this->getPageLink( $this->event->getTitle(), '', true ); |
| 144 |
if ( $this->isBundled() ) { |
| 145 |
return [ $pageLink ]; |
| 146 |
} else { |
| 147 |
return [ $this->getAgentLink(), $pageLink ]; |
| 148 |
} |
| 149 |
} |
| 150 |
} |