Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 58 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialEditEventRegistration | |
0.00% |
0 / 58 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
getFormMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
56 | |||
getValidationFlags | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getShowAlways | |
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\EditEventCommand; |
9 | use MediaWiki\Extension\CampaignEvents\Event\EventFactory; |
10 | use MediaWiki\Extension\CampaignEvents\Event\Store\EventNotFoundException; |
11 | use MediaWiki\Extension\CampaignEvents\Event\Store\IEventLookup; |
12 | use MediaWiki\Extension\CampaignEvents\Hooks\CampaignEventsHookRunner; |
13 | use MediaWiki\Extension\CampaignEvents\MWEntity\CampaignsCentralUserLookup; |
14 | use MediaWiki\Extension\CampaignEvents\MWEntity\MWAuthorityProxy; |
15 | use MediaWiki\Extension\CampaignEvents\MWEntity\PageURLResolver; |
16 | use MediaWiki\Extension\CampaignEvents\MWEntity\WikiLookup; |
17 | use MediaWiki\Extension\CampaignEvents\Organizers\OrganizersStore; |
18 | use MediaWiki\Extension\CampaignEvents\Permissions\PermissionChecker; |
19 | use MediaWiki\Extension\CampaignEvents\PolicyMessagesLookup; |
20 | use MediaWiki\Extension\CampaignEvents\Questions\EventQuestionsRegistry; |
21 | use MediaWiki\Extension\CampaignEvents\TrackingTool\TrackingToolRegistry; |
22 | use MediaWiki\WikiMap\WikiMap; |
23 | use OOUI\HtmlSnippet; |
24 | use OOUI\MessageWidget; |
25 | |
26 | class SpecialEditEventRegistration extends AbstractEventRegistrationSpecialPage { |
27 | public const PAGE_NAME = 'EditEventRegistration'; |
28 | |
29 | public function __construct( |
30 | IEventLookup $eventLookup, |
31 | EventFactory $eventFactory, |
32 | EditEventCommand $editEventCommand, |
33 | PermissionChecker $permissionChecker, |
34 | PolicyMessagesLookup $policyMessagesLookup, |
35 | OrganizersStore $organizersStore, |
36 | CampaignsCentralUserLookup $centralUserLookup, |
37 | TrackingToolRegistry $trackingToolRegistry, |
38 | EventQuestionsRegistry $eventQuestionsRegistry, |
39 | CampaignEventsHookRunner $hookRunner, |
40 | PageURLResolver $pageURLResolver, |
41 | WikiLookup $wikiLookup |
42 | ) { |
43 | parent::__construct( |
44 | self::PAGE_NAME, |
45 | '', |
46 | $eventLookup, |
47 | $eventFactory, |
48 | $editEventCommand, |
49 | $policyMessagesLookup, |
50 | $organizersStore, |
51 | $permissionChecker, |
52 | $centralUserLookup, |
53 | $trackingToolRegistry, |
54 | $eventQuestionsRegistry, |
55 | $hookRunner, |
56 | $pageURLResolver, |
57 | $wikiLookup |
58 | ); |
59 | } |
60 | |
61 | /** |
62 | * @inheritDoc |
63 | */ |
64 | protected function getFormMessages(): array { |
65 | return [ |
66 | 'details-section-subtitle' => 'campaignevents-edit-form-details-subtitle', |
67 | 'submit' => 'campaignevents-edit-form-submit', |
68 | ]; |
69 | } |
70 | |
71 | /** |
72 | * @inheritDoc |
73 | */ |
74 | public function execute( $par ): void { |
75 | if ( $par === null ) { |
76 | $this->outputErrorBox( 'campaignevents-edit-no-event-id-provided' ); |
77 | return; |
78 | } |
79 | $this->eventID = (int)$par; |
80 | if ( (string)$this->eventID !== $par ) { |
81 | $this->outputErrorBox( 'campaignevents-edit-invalid-id' ); |
82 | return; |
83 | } |
84 | try { |
85 | $this->event = $this->eventLookup->getEventByID( $this->eventID ); |
86 | } catch ( EventNotFoundException $_ ) { |
87 | $this->outputErrorBox( 'campaignevents-edit-event-notfound' ); |
88 | return; |
89 | } |
90 | |
91 | $mwAuthority = new MWAuthorityProxy( $this->getAuthority() ); |
92 | if ( !$this->permissionChecker->userCanEditRegistration( $mwAuthority, $this->event ) ) { |
93 | $this->outputErrorBox( 'campaignevents-edit-not-allowed-registration' ); |
94 | return; |
95 | } |
96 | |
97 | if ( $this->event->getDeletionTimestamp() !== null ) { |
98 | $this->outputErrorBox( 'campaignevents-edit-error-deleted' ); |
99 | return; |
100 | } |
101 | |
102 | $eventPage = $this->event->getPage(); |
103 | $wikiID = $eventPage->getWikiId(); |
104 | if ( $wikiID !== WikiAwareEntity::LOCAL ) { |
105 | $foreignEditURL = WikiMap::getForeignURL( $wikiID, 'Special:' . self::PAGE_NAME . "/{$this->eventID}" ); |
106 | |
107 | $this->setHeaders(); |
108 | $this->getOutput()->enableOOUI(); |
109 | |
110 | $messageWidget = new MessageWidget( [ |
111 | 'type' => 'notice', |
112 | 'label' => new HtmlSnippet( |
113 | $this->msg( 'campaignevents-edit-page-nonlocal' ) |
114 | ->params( [ |
115 | $foreignEditURL, WikiMap::getWikiName( $wikiID ) |
116 | ] )->parse() |
117 | ) |
118 | ] ); |
119 | |
120 | $this->getOutput()->addHTML( $messageWidget ); |
121 | return; |
122 | } |
123 | parent::execute( $par ); |
124 | } |
125 | |
126 | /** |
127 | * @inheritDoc |
128 | */ |
129 | protected function getValidationFlags(): int { |
130 | return EventFactory::VALIDATE_SKIP_DATES_PAST; |
131 | } |
132 | |
133 | /** |
134 | * @inheritDoc |
135 | */ |
136 | protected function getShowAlways(): bool { |
137 | return true; |
138 | } |
139 | } |