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

/**
 * Formatter for 'user-rights' notifications
 */
class EchoUserRightsFormatter extends EchoBasicFormatter {

	/**
	 * @param $event EchoEvent
	 * @param $param string
	 * @param $message Message
	 * @param $user User
	 */
	protected function processParam( $event, $param, $message, $user ) {
		$extra = $event->getExtra();

		switch ( $param ) {
			// List of user rights that are granted or revoked
			case 'user-rights-list':
				global $wgLang;

				$list = array();

				foreach ( array( 'add', 'remove' ) as $action ) {
					if ( isset( $extra[$action] ) && $extra[$action] ) {

						// Get the localized group names, bug 55338
						$groups = array();
						foreach( $extra[$action] as $group ) {
							$msg = $this->getMessage( 'group-' . $group );
							$groups[] = $msg->isBlank() ? $group : $msg->escaped();
						}

						// Messages that can be used here:
						// * notification-user-rights-add
						// * notification-user-rights-remove
						$list[] = $this->getMessage( 'notification-user-rights-' . $action )
							->params( $wgLang->commaList( $groups ), count( $groups ) )
							->escaped();
					}
				}
				$message->params( $wgLang->semicolonList( $list ) );
				break;

			default:
				parent::processParam( $event, $param, $message, $user );
				break;
		}
	}

	/**
	 * Helper function for getLink()
	 *
	 * @param EchoEvent $event
	 * @param User $user The user receiving the notification
	 * @param String $destination The destination type for the link
	 * @return Array including target and query parameters
	 */
	protected function getLinkParams( $event, $user, $destination ) {
		$target = null;
		$query = array();
		// Set up link parameters based on the destination (or pass to parent)
		switch ( $destination ) {
			case 'user-rights-list':
				$target = SpecialPage::getTitleFor( 'Listgrouprights' );
				break;
			default:
				return parent::getLinkParams( $event, $user, $destination );
		}
		return array( $target, $query );
	}
}