Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ProtectedVarsAccessLogFormatter | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMessageKey | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getMessageParameters | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter\LogFormatter; |
| 4 | |
| 5 | use MediaWiki\Extension\AbuseFilter\ProtectedVarsAccessLogger; |
| 6 | use MediaWiki\Linker\Linker; |
| 7 | use MediaWiki\Logging\LogEntry; |
| 8 | use MediaWiki\Logging\LogFormatter; |
| 9 | use MediaWiki\Message\Message; |
| 10 | use MediaWiki\User\UserFactory; |
| 11 | |
| 12 | class ProtectedVarsAccessLogFormatter extends LogFormatter { |
| 13 | |
| 14 | public function __construct( |
| 15 | LogEntry $entry, |
| 16 | private readonly UserFactory $userFactory |
| 17 | ) { |
| 18 | parent::__construct( $entry ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @inheritDoc |
| 23 | */ |
| 24 | protected function getMessageKey() { |
| 25 | $key = parent::getMessageKey(); |
| 26 | $params = $this->entry->getParameters(); |
| 27 | if ( isset( $params['variables'] ) && count( $params['variables'] ) > 0 ) { |
| 28 | return 'logentry-abusefilter-protected-vars-view-protected-var-value-varnames'; |
| 29 | } |
| 30 | |
| 31 | return $key; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @inheritDoc |
| 36 | */ |
| 37 | protected function getMessageParameters() { |
| 38 | $params = parent::getMessageParameters(); |
| 39 | |
| 40 | // Replace temporary user page link with contributions page link. |
| 41 | // Don't use LogFormatter::makeUserLink, because that adds tools links. |
| 42 | if ( $this->entry->getSubtype() === ProtectedVarsAccessLogger::ACTION_VIEW_PROTECTED_VARIABLE_VALUE ) { |
| 43 | $tempUserName = $this->entry->getTarget()->getText(); |
| 44 | $params[2] = Message::rawParam( |
| 45 | Linker::userLink( 0, $this->userFactory->newUnsavedTempUser( $tempUserName ) ) |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | $logParams = $this->entry->getParameters(); |
| 50 | |
| 51 | if ( isset( $logParams['variables'] ) && count( $logParams['variables'] ) > 0 ) { |
| 52 | $params[3] = count( $logParams['variables'] ); |
| 53 | $params[4] = $this->formatParameterValue( 'list', $logParams['variables'] ); |
| 54 | } |
| 55 | |
| 56 | return $params; |
| 57 | } |
| 58 | } |