Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
IPInfoLogFormatter | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getMessageParameters | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | namespace MediaWiki\IPInfo\Logging; |
4 | |
5 | use LogEntry; |
6 | use LogFormatter; |
7 | use MediaWiki\Linker\Linker; |
8 | use MediaWiki\Message\Message; |
9 | use MediaWiki\User\UserFactory; |
10 | |
11 | class IPInfoLogFormatter extends LogFormatter { |
12 | |
13 | private UserFactory $userFactory; |
14 | |
15 | public function __construct( |
16 | LogEntry $entry, |
17 | UserFactory $userFactory |
18 | ) { |
19 | parent::__construct( $entry ); |
20 | $this->userFactory = $userFactory; |
21 | } |
22 | |
23 | /** @inheritDoc */ |
24 | protected function getMessageParameters() { |
25 | $params = parent::getMessageParameters(); |
26 | |
27 | // Update the log line depending on if the user had their access enabled or disabled |
28 | if ( $this->entry->getSubtype() === 'change_access' ) { |
29 | // Message keys used: |
30 | // - 'ipinfo-change-access-level-enable' |
31 | // - 'ipinfo-change-access-level-disable' |
32 | $params[3] = $this->msg( 'ipinfo-change-access-level-' . $params[3], $params[1] ); |
33 | } |
34 | |
35 | if ( |
36 | $this->entry->getSubtype() === 'view_infobox' || |
37 | $this->entry->getSubtype() === 'view_popup' |
38 | ) { |
39 | // Replace an IP user page link with IP contributions page link. |
40 | // Don't use the LogFormatter::makeUserLink function, because that adds tools links. |
41 | $ip = $this->entry->getTarget()->getText(); |
42 | $params[2] = Message::rawParam( |
43 | Linker::userLink( 0, $this->userFactory->newAnonymous( $ip ) ) |
44 | ); |
45 | |
46 | // Replace access level parameter with the message. |
47 | // Message keys used: |
48 | // - 'ipinfo-log-access-level-ipinfo-view-basic' |
49 | // - 'ipinfo-log-access-level-ipinfo-view-full' |
50 | $params[3] = $this->msg( 'ipinfo-log-access-level-' . $params[3] ); |
51 | } |
52 | |
53 | return $params; |
54 | } |
55 | } |