ListToggle.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Class for generating clickable toggle links for a list of checkboxes.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. */
  22. /**
  23. * Class for generating clickable toggle links for a list of checkboxes.
  24. *
  25. * This is only supported on clients that have JavaScript enabled; it is hidden
  26. * for clients that have it disabled.
  27. *
  28. * @since 1.27
  29. */
  30. class ListToggle {
  31. /** @var OutputPage */
  32. private $output;
  33. public function __construct( OutputPage $output ) {
  34. $this->output = $output;
  35. $output->addModules( 'mediawiki.checkboxtoggle' );
  36. $output->addModuleStyles( 'mediawiki.checkboxtoggle.styles' );
  37. }
  38. private function checkboxLink( $checkboxType ) {
  39. return Html::element(
  40. // CSS classes: mw-checkbox-all, mw-checkbox-none, mw-checkbox-invert
  41. 'a', [ 'class' => 'mw-checkbox-' . $checkboxType, 'role' => 'button', 'tabindex' => 0 ],
  42. $this->output->msg( 'checkbox-' . $checkboxType )->text()
  43. );
  44. }
  45. /**
  46. * @return string
  47. */
  48. public function getHTML() {
  49. // Select: All, None, Invert
  50. $links = [
  51. $this->checkboxLink( 'all' ),
  52. $this->checkboxLink( 'none' ),
  53. $this->checkboxLink( 'invert' ),
  54. ];
  55. return Html::rawElement( 'div',
  56. [
  57. 'class' => 'mw-checkbox-toggle-controls'
  58. ],
  59. $this->output->msg( 'checkbox-select' )
  60. ->rawParams( $this->output->getLanguage()->commaList( $links ) )->escaped()
  61. );
  62. }
  63. }