Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ListToggle | |
100.00% |
20 / 20 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| checkboxLink | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getHTML | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Class for generating clickable toggle links for a list of checkboxes. |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Html; |
| 10 | |
| 11 | use MediaWiki\Output\OutputPage; |
| 12 | |
| 13 | /** |
| 14 | * Class for generating clickable toggle links for a list of checkboxes. |
| 15 | * |
| 16 | * This is only supported on clients that have JavaScript enabled; it is hidden |
| 17 | * for clients that have it disabled. |
| 18 | * |
| 19 | * @since 1.27 |
| 20 | */ |
| 21 | class ListToggle { |
| 22 | /** @var OutputPage */ |
| 23 | private $output; |
| 24 | |
| 25 | public function __construct( OutputPage $output ) { |
| 26 | $this->output = $output; |
| 27 | |
| 28 | $output->addModules( 'mediawiki.checkboxtoggle' ); |
| 29 | $output->addModuleStyles( 'mediawiki.checkboxtoggle.styles' ); |
| 30 | } |
| 31 | |
| 32 | private function checkboxLink( string $checkboxType ): string { |
| 33 | return Html::element( |
| 34 | // CSS classes: mw-checkbox-all, mw-checkbox-none, mw-checkbox-invert |
| 35 | 'a', [ 'class' => 'mw-checkbox-' . $checkboxType, 'role' => 'button', 'tabindex' => 0 ], |
| 36 | $this->output->msg( 'checkbox-' . $checkboxType )->text() |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @return string |
| 42 | */ |
| 43 | public function getHTML() { |
| 44 | // Select: All, None, Invert |
| 45 | $links = [ |
| 46 | $this->checkboxLink( 'all' ), |
| 47 | $this->checkboxLink( 'none' ), |
| 48 | $this->checkboxLink( 'invert' ), |
| 49 | ]; |
| 50 | |
| 51 | return Html::rawElement( |
| 52 | 'div', |
| 53 | [ |
| 54 | 'class' => 'mw-checkbox-toggle-controls', |
| 55 | ], |
| 56 | $this->output->msg( 'checkbox-select' ) |
| 57 | ->rawParams( $this->output->getLanguage()->commaList( $links ) )->escaped() |
| 58 | ); |
| 59 | } |
| 60 | } |