Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| ThrottleFilterPresentationModel | |
100.00% |
27 / 27 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getIconType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| getHeaderMessage | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 | |||
| getSubjectMessage | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getPrimaryLink | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter; |
| 4 | |
| 5 | use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; |
| 6 | use MediaWiki\Extension\Notifications\Model\Event; |
| 7 | use MediaWiki\Language\Language; |
| 8 | use MediaWiki\Message\Message; |
| 9 | use MediaWiki\User\User; |
| 10 | |
| 11 | class ThrottleFilterPresentationModel extends EchoEventPresentationModel { |
| 12 | |
| 13 | private readonly int $filter; |
| 14 | /** @var string[] */ |
| 15 | private readonly array $disabledActions; |
| 16 | |
| 17 | /** |
| 18 | * @inheritDoc |
| 19 | */ |
| 20 | protected function __construct( Event $event, Language $language, User $user, $distributionType ) { |
| 21 | parent::__construct( $event, $language, $user, $distributionType ); |
| 22 | |
| 23 | // Extract the filter ID from Special:AbuseFilter/<filter> |
| 24 | $afTitleText = $this->event->getTitle()->getText(); |
| 25 | $this->filter = (int)explode( '/', $afTitleText, 2 )[1]; |
| 26 | |
| 27 | // BC: Default to an empty array for events created before Id989fb1 |
| 28 | $this->disabledActions = $this->event->getExtraParam( 'throttled-actions' ) ?? []; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @inheritDoc |
| 33 | */ |
| 34 | public function getIconType() { |
| 35 | return $this->disabledActions !== [] ? 'alert' : 'placeholder'; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @inheritDoc |
| 40 | */ |
| 41 | public function getHeaderMessage() { |
| 42 | if ( $this->disabledActions !== [] ) { |
| 43 | $specsFormatter = AbuseFilterServices::getSpecsFormatter(); |
| 44 | $specsFormatter->setMessageLocalizer( $this ); |
| 45 | $disabledActionsLocalized = []; |
| 46 | foreach ( $this->disabledActions as $action ) { |
| 47 | $disabledActionsLocalized[] = $specsFormatter->getActionMessage( $action )->text(); |
| 48 | } |
| 49 | return $this->msg( 'notification-header-throttle-filter-actions' ) |
| 50 | ->params( $this->getViewingUserForGender() ) |
| 51 | ->numParams( $this->filter ) |
| 52 | ->params( Message::listParam( $disabledActionsLocalized ) ) |
| 53 | ->params( count( $disabledActionsLocalized ) ); |
| 54 | } |
| 55 | |
| 56 | return $this->msg( 'notification-header-throttle-filter-no-actions' ) |
| 57 | ->params( $this->getViewingUserForGender() ) |
| 58 | ->numParams( $this->filter ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @inheritDoc |
| 63 | */ |
| 64 | public function getSubjectMessage() { |
| 65 | $msgKey = $this->disabledActions !== [] |
| 66 | ? 'notification-subject-throttle-filter-actions' |
| 67 | : 'notification-subject-throttle-filter-no-actions'; |
| 68 | return $this->msg( $msgKey )->numParams( $this->filter ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @inheritDoc |
| 73 | */ |
| 74 | public function getPrimaryLink() { |
| 75 | return [ |
| 76 | 'url' => $this->event->getTitle()->getFullURL(), |
| 77 | 'label' => $this->msg( 'notification-link-text-show-filter' )->text() |
| 78 | ]; |
| 79 | } |
| 80 | } |