logging: Inject services into AbuseLogHitFormatter

Bug: T356468
Change-Id: I42023b7dcdaf80aeb3367d82068e1de47f8ae424
This commit is contained in:
Umherirrender 2024-03-29 21:38:41 +01:00
parent 09d6a0cc79
commit 13cf3eb20a
2 changed files with 20 additions and 5 deletions

View file

@ -115,7 +115,12 @@
"abusefilter": "abusefilter-log-header"
},
"LogActionsHandlers": {
"abusefilter/hit": "MediaWiki\\Extension\\AbuseFilter\\LogFormatter\\AbuseLogHitFormatter",
"abusefilter/hit": {
"class": "MediaWiki\\Extension\\AbuseFilter\\LogFormatter\\AbuseLogHitFormatter",
"services": [
"AbuseFilterSpecsFormatter"
]
},
"abusefilter/modify": "MediaWiki\\Extension\\AbuseFilter\\LogFormatter\\AbuseFilterModifyLogFormatter",
"abusefilter/create": "MediaWiki\\Extension\\AbuseFilter\\LogFormatter\\AbuseFilterModifyLogFormatter",
"abusefilterblockeddomainhit/*": "MediaWiki\\Extension\\AbuseFilter\\LogFormatter\\AbuseFilterBlockedDomainHitLogFormatter",

View file

@ -2,8 +2,9 @@
namespace MediaWiki\Extension\AbuseFilter\LogFormatter;
use LogEntry;
use LogFormatter;
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
use MediaWiki\SpecialPage\SpecialPage;
use Message;
@ -14,6 +15,16 @@ use Message;
*/
class AbuseLogHitFormatter extends LogFormatter {
private SpecsFormatter $specsFormatter;
public function __construct(
LogEntry $entry,
SpecsFormatter $specsFormatter
) {
parent::__construct( $entry );
$this->specsFormatter = $specsFormatter;
}
/**
* @return array
*/
@ -52,10 +63,9 @@ class AbuseLogHitFormatter extends LogFormatter {
$actions = explode( ',', $actions_takenRaw );
$displayActions = [];
$specsFormatter = AbuseFilterServices::getSpecsFormatter();
$specsFormatter->setMessageLocalizer( $this->context );
$this->specsFormatter->setMessageLocalizer( $this->context );
foreach ( $actions as $action ) {
$displayActions[] = $specsFormatter->getActionDisplay( $action );
$displayActions[] = $this->specsFormatter->getActionDisplay( $action );
}
$actions_taken = $this->context->getLanguage()->commaList( $displayActions );
}