Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
99.04% |
103 / 104 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
SpecialListFunctionsByTests | |
99.04% |
103 / 104 |
|
85.71% |
6 / 7 |
13 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getParameters | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
7 | |||
execute | |
100.00% |
34 / 34 |
|
100.00% |
1 / 1 |
1 | |||
getHeaderTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getHeaderForm | |
100.00% |
51 / 51 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * WikiLambda Special:ListFunctionsByTests page |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
8 | * @license MIT |
9 | */ |
10 | |
11 | namespace MediaWiki\Extension\WikiLambda\Special; |
12 | |
13 | use MediaWiki\Extension\WikiLambda\Pagers\FunctionsByTestsPager; |
14 | use MediaWiki\Extension\WikiLambda\Registry\ZLangRegistry; |
15 | use MediaWiki\Extension\WikiLambda\ZObjectStore; |
16 | use MediaWiki\HTMLForm\HTMLForm; |
17 | use MediaWiki\Languages\LanguageFallback; |
18 | use MediaWiki\SpecialPage\SpecialPage; |
19 | |
20 | class SpecialListFunctionsByTests extends SpecialPage { |
21 | |
22 | private ZObjectStore $zObjectStore; |
23 | private LanguageFallback $languageFallback; |
24 | private ZLangRegistry $langRegistry; |
25 | |
26 | /** |
27 | * @param ZObjectStore $zObjectStore |
28 | * @param LanguageFallback $languageFallback |
29 | */ |
30 | public function __construct( ZObjectStore $zObjectStore, LanguageFallback $languageFallback ) { |
31 | parent::__construct( 'ListFunctionsByTests' ); |
32 | $this->zObjectStore = $zObjectStore; |
33 | $this->languageFallback = $languageFallback; |
34 | $this->langRegistry = ZLangRegistry::singleton(); |
35 | } |
36 | |
37 | /** |
38 | * @inheritDoc |
39 | */ |
40 | protected function getGroupName() { |
41 | // Triggers use of message specialpages-group-wikilambda |
42 | return 'wikilambda'; |
43 | } |
44 | |
45 | /** |
46 | * @inheritDoc |
47 | */ |
48 | public function getDescription() { |
49 | return $this->msg( 'wikilambda-special-functionsbytests' ); |
50 | } |
51 | |
52 | /** |
53 | * Get and validate SpecialPage parameters from url |
54 | * |
55 | * @return array - int min, int max, bool connected, bool pending, bool pass, bool fail, bool excludePreDefined |
56 | */ |
57 | private function getParameters() { |
58 | // Get max test count from request |
59 | // Default: 0 (no lower limit) |
60 | $min = $this->getRequest()->getText( 'min' ); |
61 | $min = is_numeric( $min ) ? (int)$min : 0; |
62 | |
63 | // Get max test count from request |
64 | // Default: -1 (no upper limit) |
65 | $max = $this->getRequest()->getText( 'max' ); |
66 | $max = is_numeric( $max ) ? (int)$max : -1; |
67 | |
68 | // Get boolean value connected from request |
69 | // Default: false (filter by only connected tests) |
70 | $status = $this->getRequest()->getArray( 'status' ); |
71 | $connected = is_array( $status ) ? in_array( 'connected', $status ) : false; |
72 | $pending = is_array( $status ) ? in_array( 'pending', $status ) : false; |
73 | |
74 | // Get boolean value passing from request |
75 | // Default: false (filter by only passing tests) |
76 | $result = $this->getRequest()->getArray( 'result' ); |
77 | $pass = is_array( $result ) ? in_array( 'pass', $result ) : false; |
78 | $fail = is_array( $result ) ? in_array( 'fail', $result ) : false; |
79 | |
80 | $excludePreDefined = $this->getRequest()->getBool( 'excludePreDefined' ); |
81 | |
82 | return [ $min, $max, $connected, $pending, $pass, $fail, $excludePreDefined ]; |
83 | } |
84 | |
85 | /** |
86 | * @inheritDoc |
87 | */ |
88 | public function execute( $subpage ) { |
89 | // Get and validate page parameters |
90 | [ $min, $max, $connected, $pending, $pass, $fail, $excludePreDefined ] = $this->getParameters(); |
91 | |
92 | // Set headers |
93 | $this->setHeaders(); |
94 | $this->outputHeader( 'wikilambda-special-functionsbytests-summary' ); |
95 | |
96 | // Set output |
97 | $output = $this->getOutput(); |
98 | $output->enableOOUI(); |
99 | $output->addModuleStyles( [ |
100 | 'mediawiki.special', |
101 | 'ext.wikilambda.special.styles' |
102 | ] ); |
103 | |
104 | // TODO (T300519): Make this help page. |
105 | $this->addHelpLink( 'Help:Wikifunctions/Functions by Test status' ); |
106 | |
107 | // Get list of fallback language ZIDs |
108 | $languageZids = $this->langRegistry->getListOfFallbackLanguageZids( |
109 | $this->languageFallback, |
110 | $this->getLanguage()->getCode() |
111 | ); |
112 | |
113 | // Build FunctionsByTestsPager with the given filters |
114 | $filters = [ |
115 | 'min' => $min, |
116 | 'max' => $max, |
117 | 'connected' => $connected, |
118 | 'pending' => $pending, |
119 | 'pass' => $pass, |
120 | 'fail' => $fail |
121 | ]; |
122 | $pager = new FunctionsByTestsPager( |
123 | $this->getContext(), |
124 | $this->zObjectStore, |
125 | $languageZids, |
126 | $excludePreDefined, |
127 | $filters |
128 | ); |
129 | |
130 | // Add the header form |
131 | $output->addHTML( $this->getHeaderForm() ); |
132 | |
133 | // Add the top pagination controls |
134 | $output->addHTML( $pager->getNavigationBar() ); |
135 | // Add the item list body |
136 | $output->addWikiTextAsInterface( $pager->getBody() ); |
137 | // Add the bottom pagination controls |
138 | $output->addHTML( $pager->getNavigationBar() ); |
139 | |
140 | // Add bottom pagination controls |
141 | $output->addWikiTextAsInterface( $pager->getBottomLinks() ); |
142 | } |
143 | |
144 | /** |
145 | * Render the header for listing Functions filtered by their test status |
146 | * |
147 | * @return string - The wikitext for the header. |
148 | */ |
149 | private function getHeaderTitle() { |
150 | return $this->msg( 'wikilambda-special-functionsbytests-form-header' )->text(); |
151 | } |
152 | |
153 | /** |
154 | * Build the form to place at the head of the Special page |
155 | * |
156 | * @return string |
157 | */ |
158 | public function getHeaderForm() { |
159 | $formHeader = $this->getHeaderTitle(); |
160 | $formDescriptor = [ |
161 | 'min' => [ |
162 | 'label' => $this->msg( 'wikilambda-special-functionsbytests-form-min' )->text(), |
163 | 'help' => $this->msg( 'wikilambda-special-functionsbytests-form-min-help' )->escaped(), |
164 | 'type' => 'int', |
165 | 'name' => 'min', |
166 | 'cssclass' => 'ext-wikilambda-special-tests-min', |
167 | 'section' => 'matchrange' |
168 | ], |
169 | 'max' => [ |
170 | 'label' => $this->msg( 'wikilambda-special-functionsbytests-form-max' )->text(), |
171 | 'help' => $this->msg( 'wikilambda-special-functionsbytests-form-max-help' )->escaped(), |
172 | 'type' => 'int', |
173 | 'name' => 'max', |
174 | 'cssclass' => 'ext-wikilambda-special-tests-max', |
175 | 'section' => 'matchrange' |
176 | ], |
177 | 'status' => [ |
178 | 'type' => 'multiselect', |
179 | 'label' => $this->msg( 'wikilambda-special-functionsbytests-form-status' )->text(), |
180 | 'name' => 'status', |
181 | 'options' => [ |
182 | $this->msg( 'wikilambda-special-functionsbytests-form-status-connected' )->escaped() => 'connected', |
183 | $this->msg( 'wikilambda-special-functionsbytests-form-status-pending' )->escaped() => 'pending' |
184 | ], |
185 | 'default' => [], |
186 | ], |
187 | 'result' => [ |
188 | 'type' => 'multiselect', |
189 | 'label' => $this->msg( 'wikilambda-special-functionsbytests-form-result' )->text(), |
190 | 'name' => 'result', |
191 | 'options' => [ |
192 | $this->msg( 'wikilambda-special-functionsbytests-form-result-pass' )->escaped() => 'pass', |
193 | $this->msg( 'wikilambda-special-functionsbytests-form-result-fail' )->escaped() => 'fail' |
194 | ], |
195 | 'default' => [], |
196 | ], |
197 | 'excludePreDefined' => [ |
198 | 'type' => 'check', |
199 | 'label' => $this->msg( 'wikilambda-special-objectsbytype-form-excludepredefined' )->text(), |
200 | 'name' => 'excludePreDefined', |
201 | 'default' => false |
202 | ] |
203 | ]; |
204 | |
205 | $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
206 | ->setFormIdentifier( 'testfilters' ) |
207 | ->setWrapperLegend( $formHeader ) |
208 | ->setCollapsibleOptions( true ) |
209 | ->setMethod( 'get' ); |
210 | return $htmlForm->prepareForm()->getHTML( false ); |
211 | } |
212 | } |