| 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 | namespace MediaWiki\Html; |
| 24 | |
| 25 | use MediaWiki\Output\OutputPage; |
| 26 | |
| 27 | /** |
| 28 | * Class for generating clickable toggle links for a list of checkboxes. |
| 29 | * |
| 30 | * This is only supported on clients that have JavaScript enabled; it is hidden |
| 31 | * for clients that have it disabled. |
| 32 | * |
| 33 | * @since 1.27 |
| 34 | */ |
| 35 | class ListToggle { |
| 36 | /** @var OutputPage */ |
| 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 | |
| 54 | /** |
| 55 | * @return string |
| 56 | */ |
| 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 | /** @deprecated class alias since 1.40 */ |
| 77 | class_alias( ListToggle::class, 'ListToggle' ); |