3 * Represents a hide-based boolean filter (used on ChangesListSpecialPage and descendants)
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.
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.
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
22 * @author Matthew Flaschen
25 use Wikimedia\Rdbms\IDatabase
;
28 * An individual filter in a boolean group
32 class ChangesListBooleanFilter
extends ChangesListFilter
{
34 * Name. Used as URL parameter
39 // This can sometimes be different on Special:RecentChanges
40 // and Special:Watchlist, due to the double-legacy hooks
41 // (SpecialRecentChangesFilters and SpecialWatchlistFilters)
43 // but there will be separate sets of ChangesListFilterGroup and ChangesListFilter instances
44 // for those pages (it should work even if they're both loaded
45 // at once, but that can't happen).
47 * Main unstructured UI i18n key
49 * @var string $showHide
54 * Whether there is a feature designed to replace this filter available on the
57 * @var bool $isReplacedInStructuredUi
59 protected $isReplacedInStructuredUi;
64 * @var bool $defaultValue
66 protected $defaultValue;
69 * Callable used to do the actual query modification; see constructor
71 * @var callable $queryCallable
73 protected $queryCallable;
76 * Create a new filter with the specified configuration.
78 * It infers which UI (it can be either or both) to display the filter on based on
79 * which messages are provided.
81 * If 'label' is provided, it will be displayed on the structured UI. If
82 * 'showHide' is provided, it will be displayed on the unstructured UI. Thus,
83 * 'label', 'description', and 'showHide' are optional depending on which UI
86 * @param array $filterDefinition ChangesListFilter definition
88 * $filterDefinition['name'] string Name. Used as URL parameter.
89 * $filterDefinition['group'] ChangesListFilterGroup Group. Filter group this
91 * $filterDefinition['label'] string i18n key of label for structured UI.
92 * $filterDefinition['description'] string i18n key of description for structured
94 * $filterDefinition['showHide'] string Main i18n key used for unstructured UI.
95 * $filterDefinition['isReplacedInStructuredUi'] bool Whether there is an
96 * equivalent feature available in the structured UI; this is optional, defaulting
97 * to true. It does not need to be set if the exact same filter is simply visible
99 * $filterDefinition['default'] bool Default
100 * $filterDefinition['priority'] int Priority integer. Higher value means higher
101 * up in the group's filter list.
102 * $filterDefinition['queryCallable'] callable Callable accepting parameters, used
103 * to implement filter's DB query modification. Callback parameters:
104 * string $specialPageClassName Class name of current special page
105 * IContextSource $context Context, for e.g. user
106 * IDatabase $dbr Database, for addQuotes, makeList, and similar
107 * array &$tables Array of tables; see IDatabase::select $table
108 * array &$fields Array of fields; see IDatabase::select $vars
109 * array &$conds Array of conditions; see IDatabase::select $conds
110 * array &$query_options Array of query options; see IDatabase::select $options
111 * array &$join_conds Array of join conditions; see IDatabase::select $join_conds
112 * Optional only for legacy filters that still use the query hooks directly
114 public function __construct( $filterDefinition ) {
115 parent
::__construct( $filterDefinition );
117 if ( isset( $filterDefinition['showHide'] ) ) {
118 $this->showHide
= $filterDefinition['showHide'];
121 if ( isset( $filterDefinition['isReplacedInStructuredUi'] ) ) {
122 $this->isReplacedInStructuredUi
= $filterDefinition['isReplacedInStructuredUi'];
124 $this->isReplacedInStructuredUi
= false;
127 if ( isset( $filterDefinition['default'] ) ) {
128 $this->defaultValue
= $filterDefinition['default'];
130 throw new MWException( 'You must set a default' );
133 if ( isset( $filterDefinition['queryCallable'] ) ) {
134 $this->queryCallable
= $filterDefinition['queryCallable'];
139 * @return bool|null Default value
141 public function getDefault() {
142 return $this->defaultValue
;
148 * @param bool Default value
150 public function setDefault( $defaultValue ) {
151 $this->defaultValue
= $defaultValue;
155 * @return string Main i18n key for unstructured UI
157 public function getShowHide() {
158 return $this->showHide
;
164 public function displaysOnUnstructuredUi() {
165 return !!$this->showHide
;
171 public function isFeatureAvailableOnStructuredUi() {
172 return $this->isReplacedInStructuredUi ||
173 parent
::isFeatureAvailableOnStructuredUi();
177 * Modifies the query to include the filter. This is only called if the filter is
178 * in effect (taking into account the default).
180 * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
181 * @param ChangesListSpecialPage $specialPage Current special page
182 * @param array &$tables Array of tables; see IDatabase::select $table
183 * @param array &$fields Array of fields; see IDatabase::select $vars
184 * @param array &$conds Array of conditions; see IDatabase::select $conds
185 * @param array &$query_options Array of query options; see IDatabase::select $options
186 * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
188 public function modifyQuery( IDatabase
$dbr, ChangesListSpecialPage
$specialPage,
189 &$tables, &$fields, &$conds, &$query_options, &$join_conds ) {
191 if ( $this->queryCallable
=== null ) {
195 call_user_func_array(
196 $this->queryCallable
,
198 get_class( $specialPage ),
199 $specialPage->getContext(),
213 public function getJsData() {
214 $output = parent
::getJsData();
216 $output['default'] = $this->defaultValue
;