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