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