Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
GroupMembershipChangeLogFormatter | |
0.00% |
0 / 36 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
makeGroupsList | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 | |||
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, |
21 | static fn ( $first, $second ) => (bool)$second['expiry'] <=> (bool)$first['expiry'] |
22 | ); |
23 | |
24 | $language = $this->context->getLanguage(); |
25 | $user = $this->context->getUser(); |
26 | |
27 | foreach ( $groups as $group => $metadata ) { |
28 | $name = $group; |
29 | |
30 | if ( $metadata['expiry'] ) { |
31 | $name = $this->msg( 'rightslogentry-temporary-group' ) |
32 | ->params( $name, $language->userTimeAndDate( $metadata['expiry'], $user ) ) |
33 | ->escaped(); |
34 | } |
35 | |
36 | $groupNames[] = $name; |
37 | } |
38 | |
39 | return $groups !== [] |
40 | ? $this->formatParameterValue( 'list', $groupNames ) |
41 | : $this->msg( 'rightsnone' )->text(); |
42 | } |
43 | |
44 | /** |
45 | * @param array $groups |
46 | * |
47 | * @return array|string |
48 | */ |
49 | private function makeGroupsListWithoutMetadata( array $groups ) { |
50 | return $groups !== [] |
51 | ? $this->formatParameterValue( 'list', $groups ) |
52 | : $this->msg( 'rightsnone' )->text(); |
53 | } |
54 | |
55 | /** @inheritDoc */ |
56 | protected function getMessageKey() { |
57 | return 'logentry-gblrights-usergroups'; |
58 | } |
59 | |
60 | protected function extractParameters() { |
61 | if ( $this->entry->isLegacy() ) { |
62 | return parent::extractParameters(); |
63 | } |
64 | |
65 | $params = $this->entry->getParameters(); |
66 | |
67 | if ( isset( $params['oldMetadata'] ) ) { |
68 | return [ |
69 | 3 => $this->makeGroupsList( $params['oldGroups'], $params['oldMetadata'] ), |
70 | 4 => $this->makeGroupsList( $params['newGroups'], $params['newMetadata'] ), |
71 | ]; |
72 | } |
73 | |
74 | return [ |
75 | 3 => $this->makeGroupsListWithoutMetadata( $params['oldGroups'] ), |
76 | 4 => $this->makeGroupsListWithoutMetadata( $params['newGroups'] ), |
77 | ]; |
78 | } |
79 | |
80 | /** @inheritDoc */ |
81 | protected function getMessageParameters() { |
82 | $params = parent::getMessageParameters(); |
83 | // remove "User:" prefix |
84 | $params[2] = $this->formatParameterValue( 'user-link', $this->entry->getTarget()->getText() ); |
85 | return $params; |
86 | } |
87 | } |