Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
InvitationFeatureAccessTrait
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 checkInvitationFeatureAccess
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2declare( strict_types=1 );
3
4namespace MediaWiki\Extension\CampaignEvents\Special;
5
6use MediaWiki\Config\Config;
7use MediaWiki\Extension\CampaignEvents\MWEntity\ICampaignsAuthority;
8use MediaWiki\Extension\CampaignEvents\Permissions\PermissionChecker;
9use MediaWiki\Message\Message;
10use MediaWiki\Output\OutputPage;
11use OOUI\MessageWidget;
12
13/**
14 * @property PermissionChecker $permissionChecker
15 * @method Config getConfig()
16 * @method Message msg($key, ...$params)
17 * @method void requireNamedUser($reasonMsg = '', $titleMsg = '', $alwaysRedirectToLoginPage = true)
18 */
19trait InvitationFeatureAccessTrait {
20    /**
21     * @param OutputPage $out
22     * @param ICampaignsAuthority $mwAuthority
23     * @return bool
24     */
25    public function checkInvitationFeatureAccess( OutputPage $out, ICampaignsAuthority $mwAuthority ): bool {
26        if ( !$this->getConfig()->get( 'CampaignEventsEnableEventInvitation' ) ) {
27            $out->enableOOUI();
28            $messageWidget = new MessageWidget( [
29                'type' => 'notice',
30                'label' => $this->msg( 'campaignevents-invitation-list-disabled' )->text()
31            ] );
32            $out->addHTML( $messageWidget );
33            return false;
34        }
35        $this->requireNamedUser();
36        if ( !$this->permissionChecker->userCanUseInvitationLists( $mwAuthority ) ) {
37            $out->enableOOUI();
38            $messageWidget = new MessageWidget( [
39                'type' => 'error',
40                'label' => $this->msg( 'campaignevents-invitation-list-not-allowed' )->text()
41            ] );
42            $out->addHTML( $messageWidget );
43            return false;
44        }
45        return true;
46    }
47}