summaryrefslogtreecommitdiff
blob: cf09e1874a6d91aecb9c632a86038757b994f1ab (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 EchoWatchlistChangePresentationModel extends EchoEventPresentationModel {

	public function getIconType() {
		// @todo create an icon to use here
		return 'placeholder';
	}

	public function getHeaderMessage() {
		if ( $this->isMultiTypeBundle() ) {
			$status = "changed";
		} else {
			$status = $this->event->getExtraParam( 'status' );
		}
		if ( $this->isMultiUserBundle() ) {
			// Messages: notification-header-watchlist-multiuser-changed,
			// notification-header-watchlist-multiuser-created
			// notification-header-watchlist-multiuser-deleted
			// notification-header-watchlist-multiuser-moved
			// notification-header-watchlist-multiuser-restored
			$msg = $this->msg( "notification-header-watchlist-multiuser-" . $status );
		} else {
			// Messages: notification-header-watchlist-changed,
			// notification-header-watchlist-created
			// notification-header-watchlist-deleted
			// notification-header-watchlist-moved
			// notification-header-watchlist-restored
			$msg = $this->getMessageWithAgent( "notification-header-watchlist-" . $status );
		}
		$msg->params( $this->getTruncatedTitleText( $this->event->getTitle() ) );
		$msg->params( $this->getViewingUserForGender() );
		$msg->numParams( $this->getBundleCount() );
		return $msg;
	}

	public function getPrimaryLink() {
		if ( $this->isBundled() ) {
			return [
				'url' => $this->event->getTitle()->getLocalUrl(),
				'label' => $this->msg( 'notification-link-text-view-page' )->text()
			];
		}
		return [
			'url' => $this->getViewChangesUrl(),
			'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )
				->text(),
		];
	}

	public function getSecondaryLinks() {
		if ( $this->isBundled() ) {
			if ( $this->isMultiUserBundle() ) {
				return [];
			} else {
				return [ $this->getAgentLink() ];
			}
		} else {
			$viewChangesLink = [
				'url' => $this->getViewChangesUrl(),
				'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )
					->text(),
				'description' => '',
				'icon' => 'changes',
				'prioritized' => true,
			];
			return [ $this->getAgentLink(), $viewChangesLink ];
		}
	}

	private function isMultiUserBundle() {
		foreach ( $this->getBundledEvents() as $bundled ) {
			if ( !$bundled->getAgent()->equals( $this->event->getAgent() ) ) {
				return true;
			}
		}
		return false;
	}

	private function isMultiTypeBundle() {
		foreach ( $this->getBundledEvents() as $bundled ) {
			if ( $bundled->getExtraParam( 'status' ) !== $this->event->getExtraParam( 'status' ) ) {
				return true;
			}
		}
		return false;
	}

	private function getViewChangesUrl() {
		$revid = $this->event->getExtraParam( 'revid' );
		if ( $revid === 0 ) {
			$url = SpecialPage::getTitleFor( 'Log' )->getLocalUrl( [
				'logid' => $this->event->getExtraParam( 'logid' )
			] );
		} else {
			$url = $this->event->getTitle()->getLocalURL( [
				'oldid' => 'prev',
				'diff' => $revid
			] );
		}
		return $url;
	}
}