Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
ChangeRegistrationSpecialPageBase | |
0.00% |
0 / 50 |
|
0.00% |
0 / 7 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
30 | |||
checkRegistrationPrecondition | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDisplayFormat | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMessagePrefix | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare( strict_types=1 ); |
4 | |
5 | namespace MediaWiki\Extension\CampaignEvents\Special; |
6 | |
7 | use MediaWiki\DAO\WikiAwareEntity; |
8 | use MediaWiki\Extension\CampaignEvents\Event\ExistingEventRegistration; |
9 | use MediaWiki\Extension\CampaignEvents\Event\Store\EventNotFoundException; |
10 | use MediaWiki\Extension\CampaignEvents\Event\Store\IEventLookup; |
11 | use MediaWiki\Extension\CampaignEvents\MWEntity\CampaignsCentralUserLookup; |
12 | use MediaWiki\Html\Html; |
13 | use MediaWiki\SpecialPage\FormSpecialPage; |
14 | use MediaWiki\WikiMap\WikiMap; |
15 | use OOUI\HtmlSnippet; |
16 | use OOUI\MessageWidget; |
17 | |
18 | abstract class ChangeRegistrationSpecialPageBase extends FormSpecialPage { |
19 | private IEventLookup $eventLookup; |
20 | |
21 | protected CampaignsCentralUserLookup $centralUserLookup; |
22 | protected ?ExistingEventRegistration $event = null; |
23 | |
24 | /** |
25 | * @param string $name |
26 | * @param IEventLookup $eventLookup |
27 | * @param CampaignsCentralUserLookup $centralUserLookup |
28 | */ |
29 | public function __construct( |
30 | string $name, |
31 | IEventLookup $eventLookup, |
32 | CampaignsCentralUserLookup $centralUserLookup |
33 | ) { |
34 | parent::__construct( $name ); |
35 | $this->eventLookup = $eventLookup; |
36 | $this->centralUserLookup = $centralUserLookup; |
37 | } |
38 | |
39 | /** |
40 | * @inheritDoc |
41 | */ |
42 | public function execute( $par ): void { |
43 | $this->requireNamedUser(); |
44 | $this->addHelpLink( 'Extension:CampaignEvents' ); |
45 | if ( $par === null ) { |
46 | $this->setHeaders(); |
47 | $this->getOutput()->addHTML( Html::errorBox( |
48 | $this->msg( 'campaignevents-register-error-no-event' )->escaped() |
49 | ) ); |
50 | return; |
51 | } |
52 | $eventID = (int)$par; |
53 | try { |
54 | $this->event = $this->eventLookup->getEventByID( $eventID ); |
55 | } catch ( EventNotFoundException $_ ) { |
56 | $this->setHeaders(); |
57 | $this->getOutput()->addHTML( Html::errorBox( |
58 | $this->msg( 'campaignevents-register-error-event-not-found' )->escaped() |
59 | ) ); |
60 | return; |
61 | } |
62 | |
63 | $eventPage = $this->event->getPage(); |
64 | $wikiID = $eventPage->getWikiId(); |
65 | if ( $wikiID !== WikiAwareEntity::LOCAL ) { |
66 | $foreignEditURL = WikiMap::getForeignURL( |
67 | $wikiID, 'Special:' . SpecialRegisterForEvent::PAGE_NAME . "/{$eventID}" |
68 | ); |
69 | |
70 | $this->setHeaders(); |
71 | $messageWidget = new MessageWidget( [ |
72 | 'type' => 'notice', |
73 | 'label' => new HtmlSnippet( |
74 | $this->msg( 'campaignevents-register-page-nonlocal' ) |
75 | ->params( [ |
76 | $foreignEditURL, WikiMap::getWikiName( $wikiID ) |
77 | ] )->parse() |
78 | ) |
79 | ] ); |
80 | |
81 | $this->getOutput()->addHTML( $messageWidget ); |
82 | return; |
83 | } |
84 | |
85 | $preconditionResult = $this->checkRegistrationPrecondition(); |
86 | if ( is_string( $preconditionResult ) ) { |
87 | $this->setHeaders(); |
88 | $this->getOutput()->addHTML( Html::errorBox( |
89 | $this->msg( $preconditionResult )->escaped() |
90 | ) ); |
91 | return; |
92 | } |
93 | parent::execute( $par ); |
94 | } |
95 | |
96 | /** |
97 | * Checks whether the user can perform this action. In particular, this is used to show an error if the user |
98 | * is not registered for this event and they try to cancel their registration. |
99 | * |
100 | * @return string|true Error message key, or true if OK. |
101 | */ |
102 | protected function checkRegistrationPrecondition() { |
103 | return true; |
104 | } |
105 | |
106 | /** |
107 | * @inheritDoc |
108 | */ |
109 | protected function getDisplayFormat(): string { |
110 | return 'ooui'; |
111 | } |
112 | |
113 | /** |
114 | * @inheritDoc |
115 | */ |
116 | protected function getGroupName(): string { |
117 | return 'campaignevents'; |
118 | } |
119 | |
120 | /** |
121 | * @inheritDoc |
122 | */ |
123 | public function doesWrites(): bool { |
124 | return true; |
125 | } |
126 | |
127 | /** |
128 | * @inheritDoc |
129 | */ |
130 | protected function getMessagePrefix() { |
131 | return ''; |
132 | } |
133 | } |