summaryrefslogtreecommitdiff
blob: 42e56f81c9b11d49447269f3845809e9b1d613e6 (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
<?php

class EchoForeignPresentationModel extends EchoEventPresentationModel {
	public function getIconType() {
		return 'global';
	}

	public function getPrimaryLink() {
		return false;
	}

	protected function getHeaderMessageKey() {
		$data = $this->event->getExtra();
		$section = $data['section'] == 'message' ? 'notice' : $data['section'];

		// notification-header-foreign-alert
		// notification-header-foreign-notice
		// notification-header-foreign-all
		return "notification-header-foreign-{$section}";
	}

	public function getHeaderMessage() {
		$msg = parent::getHeaderMessage();

		$data = $this->event->getExtra();
		$firstWiki = reset( $data['wikis'] );
		$names = $this->getWikiNames( [ $firstWiki ] );
		$msg->params( $names[0] );
		$msg->numParams( count( $data['wikis'] ) - 1 );
		$msg->numParams( count( $data['wikis'] ) );

		return $msg;
	}

	public function getBodyMessage() {
		$data = $this->event->getExtra();
		$msg = wfMessage( 'notification-body-foreign' );
		$msg->params( $this->language->listToText( $this->getWikiNames( $data['wikis'] ) ) );
		return $msg;
	}

	protected function getWikiNames( array $wikis ) {
		$data = EchoForeignNotifications::getApiEndpoints( $wikis );
		$names = [];
		foreach ( $wikis as $wiki ) {
			$names[] = $data[$wiki]['title'];
		}
		return $names;
	}
}