MediaWiki  master
ListToggle.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Html;
24 
25 use OutputPage;
26 
35 class ListToggle {
37  private $output;
38 
39  public function __construct( OutputPage $output ) {
40  $this->output = $output;
41 
42  $output->addModules( 'mediawiki.checkboxtoggle' );
43  $output->addModuleStyles( 'mediawiki.checkboxtoggle.styles' );
44  }
45 
46  private function checkboxLink( $checkboxType ) {
47  return Html::element(
48  // CSS classes: mw-checkbox-all, mw-checkbox-none, mw-checkbox-invert
49  'a', [ 'class' => 'mw-checkbox-' . $checkboxType, 'role' => 'button', 'tabindex' => 0 ],
50  $this->output->msg( 'checkbox-' . $checkboxType )->text()
51  );
52  }
53 
57  public function getHTML() {
58  // Select: All, None, Invert
59  $links = [
60  $this->checkboxLink( 'all' ),
61  $this->checkboxLink( 'none' ),
62  $this->checkboxLink( 'invert' ),
63  ];
64 
65  return Html::rawElement(
66  'div',
67  [
68  'class' => 'mw-checkbox-toggle-controls',
69  ],
70  $this->output->msg( 'checkbox-select' )
71  ->rawParams( $this->output->getLanguage()->commaList( $links ) )->escaped()
72  );
73  }
74 }
75 
76 class_alias( ListToggle::class, 'ListToggle' );
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:219
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:240
Class for generating clickable toggle links for a list of checkboxes.
Definition: ListToggle.php:35
__construct(OutputPage $output)
Definition: ListToggle.php:39
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:60
addModuleStyles( $modules)
Load the styles of one or more style-only ResourceLoader modules on this page.
Definition: OutputPage.php:658
addModules( $modules)
Load one or more ResourceLoader modules on this page.
Definition: OutputPage.php:632