Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
GroupMembershipChangeLogFormatter | |
0.00% |
0 / 40 |
|
0.00% |
0 / 5 |
240 | |
0.00% |
0 / 1 |
makeGroupsList | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
72 | |||
makeGroupsListWithoutMetadata | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getMessageKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
extractParameters | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
getMessageParameters | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CentralAuth\LogFormatter; |
4 | |
5 | use LogFormatter; |
6 | |
7 | /** |
8 | * Handles the following log types: |
9 | * - gblrights/usergroups |
10 | */ |
11 | class GroupMembershipChangeLogFormatter extends LogFormatter { |
12 | |
13 | private function makeGroupsList( array $groups, array $metadata ): string { |
14 | $groupNames = []; |
15 | |
16 | $groups = array_combine( $groups, $metadata ); |
17 | |
18 | // Ensure temporary groups are displayed first, to avoid ambiguity like |
19 | // "first, second (expires at some point)" (unclear if only second expires or if both expire) |
20 | uasort( $groups, static function ( $first, $second ) { |
21 | if ( !$first['expiry'] && $second['expiry'] ) { |
22 | return 1; |
23 | } elseif ( $first['expiry'] && !$second['expiry'] ) { |
24 | return -1; |
25 | } else { |
26 | return 0; |
27 | } |
28 | } ); |
29 | |
30 | $language = $this->context->getLanguage(); |
31 | $user = $this->context->getUser(); |
32 | |
33 | foreach ( $groups as $group => $metadata ) { |
34 | $name = $group; |
35 | |
36 | if ( $metadata['expiry'] ) { |
37 | $name = $this->msg( 'rightslogentry-temporary-group' ) |
38 | ->params( $name, $language->userTimeAndDate( $metadata['expiry'], $user ) ) |
39 | ->escaped(); |
40 | } |
41 | |
42 | $groupNames[] = $name; |
43 | } |
44 | |
45 | return $groups !== [] |
46 | ? $this->formatParameterValue( 'list', $groupNames ) |
47 | : $this->msg( 'rightsnone' )->text(); |
48 | } |
49 | |
50 | /** |
51 | * @param array $groups |
52 | * |
53 | * @return array|string |
54 | */ |
55 | private function makeGroupsListWithoutMetadata( array $groups ) { |
56 | return $groups !== [] |
57 | ? $this->formatParameterValue( 'list', $groups ) |
58 | : $this->msg( 'rightsnone' )->text(); |
59 | } |
60 | |
61 | /** @inheritDoc */ |
62 | protected function getMessageKey() { |
63 | return 'logentry-gblrights-usergroups'; |
64 | } |
65 | |
66 | protected function extractParameters() { |
67 | if ( $this->entry->isLegacy() ) { |
68 | return parent::extractParameters(); |
69 | } |
70 | |
71 | $params = $this->entry->getParameters(); |
72 | |
73 | if ( isset( $params['oldMetadata'] ) ) { |
74 | return [ |
75 | 3 => $this->makeGroupsList( $params['oldGroups'], $params['oldMetadata'] ), |
76 | 4 => $this->makeGroupsList( $params['newGroups'], $params['newMetadata'] ), |
77 | ]; |
78 | } |
79 | |
80 | return [ |
81 | 3 => $this->makeGroupsListWithoutMetadata( $params['oldGroups'] ), |
82 | 4 => $this->makeGroupsListWithoutMetadata( $params['newGroups'] ), |
83 | ]; |
84 | } |
85 | |
86 | /** @inheritDoc */ |
87 | protected function getMessageParameters() { |
88 | $params = parent::getMessageParameters(); |
89 | // remove "User:" prefix |
90 | $params[2] = $this->formatParameterValue( 'user-link', $this->entry->getTarget()->getText() ); |
91 | return $params; |
92 | } |
93 | } |