Follows-up606a21c,79414f8,870c5e2. * Mention class name in PHP source. Since there is no obvious link between "mediawiki.checkboxtoggle.js" and "ListToggle.php" these comments make it possible to find the PHP class. Previously these css classes had 0 matches across all source code, thus risking accidental removing. * Quote attribute selector. * Ensure default prevented before instead of after the handler. These toggles have no fallback (href="#"). As such, navigation should be prevented regardless of whether the JS fails or succeeds. * Remove use of is(':checked'). These is no need to reach out to the selector engine to determine whether 'checked' property is true or false. Instead, use prop('checked') for both getting and setting. * Simplify code by using this.checked directly instead of $().prop(). * Simplify code by using one loop (from $.prop) instead of two loops ($.prop inside $.each). This pattern is also used by selectAll(). Test by using "All", "None" and "Invert" on Special:Log. Bug: T131318 Change-Id: Idfc43f094c6147d69104416b3f8622eabb20b824
69 lines
2 KiB
PHP
69 lines
2 KiB
PHP
<?php
|
|
/**
|
|
* Class for generating clickable toggle links for a list of checkboxes.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
/**
|
|
* Class for generating clickable toggle links for a list of checkboxes.
|
|
*
|
|
* This is only supported on clients that have JavaScript enabled; it is hidden
|
|
* for clients that have it disabled.
|
|
*
|
|
* @since 1.27
|
|
*/
|
|
class ListToggle {
|
|
/** @var OutputPage */
|
|
private $output;
|
|
|
|
public function __construct( OutputPage $output ) {
|
|
$this->output = $output;
|
|
|
|
$output->addModules( 'mediawiki.checkboxtoggle' );
|
|
$output->addModuleStyles( 'mediawiki.checkboxtoggle.styles' );
|
|
}
|
|
|
|
private function checkboxLink( $checkboxType ) {
|
|
return Html::element(
|
|
// CSS classes: mw-checkbox-all, mw-checkbox-none, mw-checkbox-invert
|
|
'a', [ 'href' => '#', 'class' => 'mw-checkbox-' . $checkboxType ],
|
|
$this->output->msg( 'checkbox-' . $checkboxType )->text()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getHTML() {
|
|
// Select: All, None, Invert
|
|
$links = [
|
|
$this->checkboxLink( 'all' ),
|
|
$this->checkboxLink( 'none' ),
|
|
$this->checkboxLink( 'invert' ),
|
|
];
|
|
|
|
return Html::rawElement( 'div',
|
|
[
|
|
'class' => 'mw-checkbox-toggle-controls'
|
|
],
|
|
$this->output->msg( 'checkbox-select' )
|
|
->rawParams( $this->output->getLanguage()->commaList( $links ) )->escaped()
|
|
);
|
|
}
|
|
}
|