From 606a21cb14771fcac079e68f6eb3c34147358301 Mon Sep 17 00:00:00 2001 From: Luke Faraone Date: Thu, 7 Jan 2016 17:18:35 +0000 Subject: [PATCH] Add links to toggle checkbox selections in Special:Log This implements a new JavaScript module, mediawiki.checkboxtoggle. The module is suitable to be reused in any other list of checkboxes. Bug: T92230 Change-Id: I92141a7079fc7fcd7152ef418d82f4f7969b163b --- includes/specials/SpecialLog.php | 27 ++++++++++++++ languages/i18n/en.json | 4 ++ languages/i18n/qqq.json | 4 ++ resources/Resources.php | 8 ++++ .../mediawiki/mediawiki.checkboxtoggle.css | 3 ++ .../src/mediawiki/mediawiki.checkboxtoggle.js | 37 +++++++++++++++++++ 6 files changed, 83 insertions(+) create mode 100644 resources/src/mediawiki/mediawiki.checkboxtoggle.css create mode 100644 resources/src/mediawiki/mediawiki.checkboxtoggle.js diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index e44ce5f5b2..28ff1c77fa 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -258,6 +258,33 @@ class SpecialLog extends SpecialPage { $this->msg( 'log-edit-tags' )->text() ) . "\n"; } + + // Select: All, None, Invert + $links = array(); + $links[] = Html::element( + 'a', array( 'href' => '#', 'id' => 'checkbox-all' ), + $this->msg( 'checkbox-all' )->text() + ); + $links[] = Html::element( + 'a', array( 'href' => '#', 'id' => 'checkbox-none' ), + $this->msg( 'checkbox-none' )->text() + ); + $links[] = Html::element( + 'a', array( 'href' => '#', 'id' => 'checkbox-invert' ), + $this->msg( 'checkbox-invert' )->text() + ); + + $buttons .= Html::rawElement( 'p', + array( + 'class' => "mw-checkbox-toggle-controls" + ), + $this->msg( 'checkbox-select' ) + ->rawParams( $this->getLanguage()->commaList( $links ) )->escaped() + ); + + $this->getOutput()->addModules( 'mediawiki.checkboxtoggle' ); + $this->getOutput()->addModuleStyles( 'mediawiki.checkboxtoggle.styles' ); + $s .= $buttons . $formcontents . $buttons; $s .= Html::closeElement( 'form' ); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index f1c354a304..545fc34d9e 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1883,6 +1883,10 @@ "log-title-wildcard": "Search titles starting with this text", "showhideselectedlogentries": "Change visibility of selected log entries", "log-edit-tags": "Edit tags of selected log entries", + "checkbox-select": "Select: $1", + "checkbox-all": "All", + "checkbox-none": "None", + "checkbox-invert": "Invert", "allpages": "All pages", "allpages-summary": "", "nextpage": "Next page ($1)", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 06f4fe635a..406efb3626 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2058,6 +2058,10 @@ "log-title-wildcard": "* Appears in: [[Special:Log]]\n* Description: A check box to enable prefix search option", "showhideselectedlogentries": "Text of the button which brings up the [[mw:RevisionDelete|RevisionDelete]] menu on [[Special:Log]].", "log-edit-tags": "Text of button used to access change tagging interface. For more information on tags see [[mw:Manual:Tags]].", + "checkbox-select": "Parameters:\n* $1 - three links: {{msg-mw|checkbox-all}}, {{msg-mw|checkbox-none}}, and {{msg-mw|checkbox-invert}} which respectively selects all pages, de-selects all, and inverts the current selection state\npages\n{{Identical|Select}}", + "checkbox-all": "Text of button used to mark all revisions or log entries as selected in a list.", + "checkbox-none": "Text of button used to mark all revisions or log entries as unselected in a list.", + "checkbox-invert": "Text of button used to invert the currently-selected-state of all revisions or log entries in a list.", "allpages": "{{doc-special|AllPages}}\nFirst part of the navigation bar for the special page [[Special:AllPages]] and [[Special:PrefixIndex]].\nThe other parts are {{msg-mw|Prevpage}} and {{msg-mw|Nextpage}}.\n{{Identical|All pages}}", "allpages-summary": "{{doc-specialpagesummary|allpages}}", "nextpage": "Third part of the navigation bar for the special page [[Special:AllPages]] and [[Special:PrefixIndex]]. $1 is a page title. The other parts are {{msg-mw|Allpages}} and {{msg-mw|Prevpage}}.\n\n{{Identical|Next page}}", diff --git a/resources/Resources.php b/resources/Resources.php index 52a9564847..cd9810ce9b 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1342,6 +1342,14 @@ return array( 'position' => 'top', // For $wgPreloadJavaScriptMwUtil 'targets' => array( 'desktop', 'mobile' ), ), + 'mediawiki.checkboxtoggle' => array( + 'scripts' => 'resources/src/mediawiki/mediawiki.checkboxtoggle.js', + 'position' => 'top', + ), + 'mediawiki.checkboxtoggle.styles' => array( + 'styles' => 'resources/src/mediawiki/mediawiki.checkboxtoggle.css', + 'position' => 'top', + ), 'mediawiki.cookie' => array( 'scripts' => 'resources/src/mediawiki/mediawiki.cookie.js', 'dependencies' => 'jquery.cookie', diff --git a/resources/src/mediawiki/mediawiki.checkboxtoggle.css b/resources/src/mediawiki/mediawiki.checkboxtoggle.css new file mode 100644 index 0000000000..3da0d438ce --- /dev/null +++ b/resources/src/mediawiki/mediawiki.checkboxtoggle.css @@ -0,0 +1,3 @@ +.client-nojs .mw-checkbox-toggle-controls { + display: none; +} diff --git a/resources/src/mediawiki/mediawiki.checkboxtoggle.js b/resources/src/mediawiki/mediawiki.checkboxtoggle.js new file mode 100644 index 0000000000..4be4a8da0d --- /dev/null +++ b/resources/src/mediawiki/mediawiki.checkboxtoggle.js @@ -0,0 +1,37 @@ +/*! + * Allows users to perform all / none / invert operations on a list of + * checkboxes on the page. + * + * @licence GNU GPL v2+ + * @author Luke Faraone + * + * Based on ext.nuke.js from https://www.mediawiki.org/wiki/Extension:Nuke by + * Jeroen De Dauw + */ + +( function ( mw, $ ) { + 'use strict'; + + var $checkboxes = $( 'li input[type=checkbox]' ); + + function selectAll( check ) { + $checkboxes.prop( 'checked', check ); + } + + $( '#checkbox-all' ).click( function ( e ) { + selectAll( true ); + e.preventDefault(); + } ); + $( '#checkbox-none' ).click( function ( e ) { + selectAll( false ); + e.preventDefault(); + } ); + $( '#checkbox-invert' ).click( function ( e ) { + $checkboxes.each( function () { + $( this ).prop( 'checked', !$( this ).is( ':checked' ) ); + } ); + e.preventDefault(); + } ); + +}( mediaWiki, jQuery ) ); + -- 2.20.1