Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 63 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
SpecialMyEvents | |
0.00% |
0 / 63 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
showFormAndEvents | |
0.00% |
0 / 53 |
|
0.00% |
0 / 1 |
12 | |||
getGroupName | |
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\Extension\CampaignEvents\MWEntity\CampaignsCentralUserLookup; |
8 | use MediaWiki\Extension\CampaignEvents\MWEntity\MWAuthorityProxy; |
9 | use MediaWiki\Extension\CampaignEvents\MWEntity\UserNotGlobalException; |
10 | use MediaWiki\Extension\CampaignEvents\Pager\EventsPagerFactory; |
11 | use MediaWiki\Extension\CampaignEvents\Pager\EventsTablePager; |
12 | use MediaWiki\Html\Html; |
13 | use MediaWiki\HTMLForm\HTMLForm; |
14 | use MediaWiki\SpecialPage\SpecialPage; |
15 | |
16 | class SpecialMyEvents extends SpecialPage { |
17 | public const PAGE_NAME = 'MyEvents'; |
18 | |
19 | private EventsPagerFactory $eventsPagerFactory; |
20 | private CampaignsCentralUserLookup $centralUserLookup; |
21 | |
22 | /** |
23 | * @param EventsPagerFactory $eventsPagerFactory |
24 | * @param CampaignsCentralUserLookup $centralUserLookup |
25 | */ |
26 | public function __construct( |
27 | EventsPagerFactory $eventsPagerFactory, |
28 | CampaignsCentralUserLookup $centralUserLookup |
29 | ) { |
30 | parent::__construct( self::PAGE_NAME ); |
31 | $this->eventsPagerFactory = $eventsPagerFactory; |
32 | $this->centralUserLookup = $centralUserLookup; |
33 | } |
34 | |
35 | /** |
36 | * @inheritDoc |
37 | */ |
38 | public function execute( $subPage ): void { |
39 | $this->requireNamedUser(); |
40 | $this->setHeaders(); |
41 | $this->addHelpLink( 'Extension:CampaignEvents' ); |
42 | $this->getOutput()->addModuleStyles( [ 'ext.campaignEvents.specialPages.styles' ] ); |
43 | $this->getOutput()->addModules( [ 'ext.campaignEvents.specialPages' ] ); |
44 | $this->showFormAndEvents(); |
45 | } |
46 | |
47 | private function showFormAndEvents(): void { |
48 | $request = $this->getRequest(); |
49 | $searchedVal = $request->getVal( 'wpSearch', '' ); |
50 | $status = $request->getVal( 'wpStatus', EventsTablePager::STATUS_ANY ); |
51 | |
52 | try { |
53 | $centralUser = $this->centralUserLookup->newFromAuthority( new MWAuthorityProxy( $this->getAuthority() ) ); |
54 | } catch ( UserNotGlobalException $_ ) { |
55 | $this->getOutput()->addHTML( Html::errorBox( |
56 | $this->msg( 'campaignevents-myevents-need-central-account' )->escaped() |
57 | ) ); |
58 | return; |
59 | } |
60 | $pager = $this->eventsPagerFactory->newTablePager( |
61 | $this->getContext(), |
62 | $this->getLinkRenderer(), |
63 | $searchedVal, |
64 | $status, |
65 | $centralUser |
66 | ); |
67 | |
68 | $formDescriptor = [ |
69 | 'Search' => [ |
70 | 'type' => 'text', |
71 | 'label-message' => 'campaignevents-myevents-label-search', |
72 | 'default' => $searchedVal, |
73 | ], |
74 | 'Status' => [ |
75 | 'type' => 'select', |
76 | 'label-message' => 'campaignevents-myevents-label-status', |
77 | 'options-messages' => [ |
78 | 'campaignevents-myevents-field-status-any' => EventsTablePager::STATUS_ANY, |
79 | 'campaignevents-myevents-field-status-open' => EventsTablePager::STATUS_OPEN, |
80 | 'campaignevents-myevents-field-status-closed' => EventsTablePager::STATUS_CLOSED |
81 | ], |
82 | 'default' => $status, |
83 | 'cssclass' => 'ext-campaignevents-myevents-filter-field' |
84 | ], |
85 | 'Limit' => [ |
86 | // NOTE: This has to be called 'limit' because the pager expects that name. |
87 | 'name' => 'limit', |
88 | 'type' => 'select', |
89 | 'label-message' => 'campaignevents-myevents-label-events-per-page', |
90 | 'options' => $pager->getLimitSelectList(), |
91 | 'default' => $pager->getLimit(), |
92 | 'cssclass' => 'ext-campaignevents-myevents-filter-field' |
93 | ], |
94 | ]; |
95 | $form = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
96 | ->setWrapperLegendMsg( 'campaignevents-myevents-filter-legend' ) |
97 | ->setMethod( 'get' ) |
98 | ->setId( 'ext-campaignevents-myevents-form' ); |
99 | $curSort = $this->getRequest()->getVal( 'sort' ); |
100 | if ( $curSort ) { |
101 | $form->addHiddenField( 'sort', $curSort ); |
102 | } |
103 | $form->prepareForm() |
104 | ->displayForm( false ); |
105 | $this->getOutput()->addParserOutputContent( $pager->getFullOutput() ); |
106 | $this->getOutput()->addModules( $pager->getModules() ); |
107 | } |
108 | |
109 | /** |
110 | * @inheritDoc |
111 | */ |
112 | protected function getGroupName(): string { |
113 | return 'campaignevents'; |
114 | } |
115 | } |