Debian Codegraph @

extensions/Echo/includes/Formatters/EchoEditUserTalkPresentationModel.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications\Formatters;
4
5 use MediaWiki\Extension\Notifications\Model\Event;
6 use MediaWiki\Language\Language;
7 use MediaWiki\MediaWikiServices;
8 use MediaWiki\User\User;
9
10 class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel {
11
12 /**
13 * @var EchoPresentationModelSection
14 */
15 protected $section;
16
17 /**
18 * @inheritDoc
19 */
20 protected function __construct( Event $event, Language $language, User $user, $distributionType ) {
21 parent::__construct( $event, $language, $user, $distributionType );
22 $this->section = new EchoPresentationModelSection( $event, $user, $language );
23 }
24
25 public function canRender() {
26 return (bool)$this->event->getTitle();
27 }
28
29 public function getIconType() {
30 return 'edit-user-talk';
31 }
32
33 public function getPrimaryLink() {
34 return [
35 // Need FullURL so the section is included
36 'url' => $this->section->getTitleWithSection()->getFullURL(),
37 'label' => $this->msg( 'notification-link-text-view-message' )->text()
38 ];
39 }
40
41 public function getSecondaryLinks() {
42 $diffLink = [
43 'url' => $this->getDiffLinkUrl(),
44 'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(),
45 'description' => '',
46 'icon' => 'changes',
47 'prioritized' => true
48 ];
49
50 if ( $this->isBundled() ) {
51 return [ $diffLink ];
52 } else {
53 return [ $this->getAgentLink(), $diffLink ];
54 }
55 }
56
57 public function getHeaderMessage() {
58 if ( $this->isBundled() ) {
59 $msg = $this->msg( 'notification-bundle-header-edit-user-talk-v2' );
60 $count = $this->getNotificationCountForOutput();
61
62 // Repeat is B/C until unused parameter is removed from translations
63 $msg->numParams( $count, $count );
64 $msg->params( $this->getViewingUserForGender() );
65 return $msg;
66 } elseif ( $this->section->exists() ) {
67 $msg = $this->getMessageWithAgent( 'notification-header-edit-user-talk-with-section' );
68 $msg->params( $this->getViewingUserForGender() );
69 $msg->plaintextParams( $this->section->getTruncatedSectionTitle() );
70 return $msg;
71 } else {
72 // Messages: notification-header-edit-user-talk
73 $msg = parent::getHeaderMessage();
74 $msg->params( $this->getViewingUserForGender() );
75 return $msg;
76 }
77 }
78
79 public function getCompactHeaderMessage() {
80 $hasSection = $this->section->exists();
81 $key = $hasSection
82 ? 'notification-compact-header-edit-user-talk-with-section'
83 : 'notification-compact-header-edit-user-talk';
84 $msg = $this->getMessageWithAgent( $key );
85 $msg->params( $this->getViewingUserForGender() );
86 if ( $hasSection ) {
87 $msg->params( $this->section->getTruncatedSectionTitle() );
88 }
89 return $msg;
90 }
91
92 public function getBodyMessage() {
93 $sectionText = $this->event->getExtraParam( 'section-text' );
94 if ( !$this->isBundled() && $this->section->exists() && is_string( $sectionText ) ) {
95 $msg = $this->msg( 'notification-body-edit-user-talk-with-section' );
96 // section-text is safe to use here, because section->exists() returns false if the revision is deleted
97 $msg->plaintextParams( $sectionText );
98 return $msg;
99 } else {
100 return false;
101 }
102 }
103
104 private function getDiffLinkUrl() {
105 $revId = $this->event->getExtraParam( 'revid' );
106 $oldId = $this->isBundled() ? $this->getRevBeforeFirstNotification() : 'prev';
107 $query = [
108 'oldid' => $oldId,
109 'diff' => $revId,
110 ];
111 return $this->event->getTitle()->getFullURL( $query );
112 }
113
114 private function getRevBeforeFirstNotification() {
115 $events = $this->getBundledEvents();
116 $firstNotificationRevId = end( $events )->getExtraParam( 'revid' );
117 $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
118 $revisionRecord = $revisionLookup->getRevisionById( $firstNotificationRevId );
119 $previousRevision = $revisionRecord ? $revisionLookup->getPreviousRevision( $revisionRecord ) : null;
120 return $previousRevision ? $previousRevision->getId() : 0;
121 }
122
123 protected function getSubjectMessageKey() {
124 return 'notification-edit-talk-page-email-subject2';
125 }
126 }
127
128 class_alias( EchoEditUserTalkPresentationModel::class, 'EchoEditUserTalkPresentationModel' );