Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AbuseLogHitFormatter | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMessageParameters | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter\LogFormatter; |
| 4 | |
| 5 | use MediaWiki\Extension\AbuseFilter\SpecsFormatter; |
| 6 | use MediaWiki\Logging\LogEntry; |
| 7 | use MediaWiki\Logging\LogFormatter; |
| 8 | use MediaWiki\Message\Message; |
| 9 | use MediaWiki\SpecialPage\SpecialPage; |
| 10 | |
| 11 | /** |
| 12 | * This class formats abuse log notifications. |
| 13 | * |
| 14 | * Uses logentry-abusefilter-hit |
| 15 | */ |
| 16 | class AbuseLogHitFormatter extends LogFormatter { |
| 17 | |
| 18 | public function __construct( |
| 19 | LogEntry $entry, |
| 20 | private readonly SpecsFormatter $specsFormatter |
| 21 | ) { |
| 22 | parent::__construct( $entry ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @return array |
| 27 | */ |
| 28 | protected function getMessageParameters() { |
| 29 | $entry = $this->entry->getParameters(); |
| 30 | $linkRenderer = $this->getLinkRenderer(); |
| 31 | $params = parent::getMessageParameters(); |
| 32 | |
| 33 | $filter_title = SpecialPage::getTitleFor( 'AbuseFilter', $entry['filter'] ); |
| 34 | $filter_caption = $this->msg( 'abusefilter-log-detailedentry-local' ) |
| 35 | ->params( $entry['filter'] ) |
| 36 | ->text(); |
| 37 | $log_title = SpecialPage::getTitleFor( 'AbuseLog', $entry['log'] ); |
| 38 | $log_caption = $this->msg( 'abusefilter-log-detailslink' )->text(); |
| 39 | |
| 40 | $params[4] = $entry['action']; |
| 41 | |
| 42 | if ( $this->plaintext ) { |
| 43 | $params[3] = '[[' . $filter_title->getPrefixedText() . '|' . $filter_caption . ']]'; |
| 44 | $params[8] = '[[' . $log_title->getPrefixedText() . '|' . $log_caption . ']]'; |
| 45 | } else { |
| 46 | $params[3] = Message::rawParam( $linkRenderer->makeLink( |
| 47 | $filter_title, |
| 48 | $filter_caption |
| 49 | ) ); |
| 50 | $params[8] = Message::rawParam( $linkRenderer->makeLink( |
| 51 | $log_title, |
| 52 | $log_caption |
| 53 | ) ); |
| 54 | } |
| 55 | |
| 56 | $actions_takenRaw = $entry['actions']; |
| 57 | if ( !strlen( trim( $actions_takenRaw ) ) ) { |
| 58 | $actions_taken = $this->msg( 'abusefilter-log-noactions' ); |
| 59 | } else { |
| 60 | $actions = explode( ',', $actions_takenRaw ); |
| 61 | $displayActions = []; |
| 62 | |
| 63 | $this->specsFormatter->setMessageLocalizer( $this->context ); |
| 64 | foreach ( $actions as $action ) { |
| 65 | $displayActions[] = $this->specsFormatter->getActionDisplay( $action ); |
| 66 | } |
| 67 | $actions_taken = $this->context->getLanguage()->commaList( $displayActions ); |
| 68 | } |
| 69 | $params[5] = Message::rawParam( $actions_taken ); |
| 70 | |
| 71 | // Bad things happen if the numbers are not in correct order |
| 72 | ksort( $params ); |
| 73 | |
| 74 | return $params; |
| 75 | } |
| 76 | } |