summaryrefslogtreecommitdiff
blob: b950bd46e41e107624ef36966616ae3bf4184eca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php

class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel {
	use EchoPresentationModelSectionTrait;

	public function canRender() {
		return (bool)$this->event->getTitle();
	}

	public function getIconType() {
		return 'edit-user-talk';
	}

	public function getPrimaryLink() {
		return [
			// Need FullURL so the section is included
			'url' => $this->getTitleWithSection()->getFullURL(),
			'label' => $this->msg( 'notification-link-text-view-message' )->text()
		];
	}

	public function getSecondaryLinks() {
		$diffLink = [
			'url' => $this->getDiffLinkUrl(),
			'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(),
			'description' => '',
			'icon' => 'changes',
			'prioritized' => true
		];

		if ( $this->isBundled() ) {
			return [ $diffLink ];
		} else {
			return [ $this->getAgentLink(), $diffLink ];
		}
	}

	public function getHeaderMessage() {
		if ( $this->isBundled() ) {
			$msg = $this->msg( "notification-bundle-header-{$this->type}-v2" );
			$count = $this->getNotificationCountForOutput();

			// Repeat is B/C until unused parameter is removed from translations
			$msg->numParams( $count, $count );
			$msg->params( $this->getViewingUserForGender() );
			return $msg;
		} elseif ( $this->hasSection() ) {
			$msg = $this->getMessageWithAgent( "notification-header-{$this->type}-with-section" );
			$msg->params( $this->getViewingUserForGender() );
			$msg->plaintextParams( $this->getTruncatedSectionTitle() );
			return $msg;
		} else {
			$msg = parent::getHeaderMessage();
			$msg->params( $this->getViewingUserForGender() );
			return $msg;
		}
	}

	public function getCompactHeaderMessage() {
		$hasSection = $this->hasSection();
		$key = $hasSection
			? "notification-compact-header-{$this->type}-with-section"
			: "notification-compact-header-{$this->type}";
		$msg = $this->getMessageWithAgent( $key );
		$msg->params( $this->getViewingUserForGender() );
		if ( $hasSection ) {
			$msg->params( $this->getTruncatedSectionTitle() );
		}
		return $msg;
	}

	public function getBodyMessage() {
		$sectionText = $this->event->getExtraParam( 'section-text' );
		if ( !$this->isBundled() && $this->hasSection() && $sectionText !== null ) {
			$msg = $this->msg( 'notification-body-edit-user-talk-with-section' );
			// section-text is safe to use here, because hasSection() returns false if the revision is deleted
			$msg->plaintextParams( $sectionText );
			return $msg;
		} else {
			return false;
		}
	}

	private function getDiffLinkUrl() {
		$revId = $this->event->getExtraParam( 'revid' );
		$oldId = $this->isBundled() ? $this->getRevBeforeFirstNotification() : 'prev';
		$query = [
			'oldid' => $oldId,
			'diff' => $revId,
		];
		return $this->event->getTitle()->getFullURL( $query );
	}

	private function getRevBeforeFirstNotification() {
		$events = $this->getBundledEvents();
		$firstNotificationRevId = end( $events )->getExtraParam( 'revid' );
		return $this->event->getTitle()->getPreviousRevisionID( $firstNotificationRevId );
	}

	protected function getSubjectMessageKey() {
		return 'notification-edit-talk-page-email-subject2';
	}
}