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