| 1 | <?php |
| 2 | |
| 3 | use MediaWiki\Html\FormOptions; |
| 4 | use MediaWiki\SpecialPage\ChangesListSpecialPage; |
| 5 | use Wikimedia\Rdbms\IReadableDatabase; |
| 6 | |
| 7 | /** |
| 8 | * If the group is active, any unchecked filters will |
| 9 | * translate to hide parameters in the URL. E.g. if 'Human (not bot)' is checked, |
| 10 | * but 'Bot' is unchecked, hidebots=1 will be sent. |
| 11 | * |
| 12 | * @since 1.29 |
| 13 | * @ingroup RecentChanges |
| 14 | * @method ChangesListBooleanFilter[] getFilters() |
| 15 | */ |
| 16 | class ChangesListBooleanFilterGroup extends ChangesListFilterGroup { |
| 17 | /** |
| 18 | * Type marker, used by JavaScript |
| 19 | */ |
| 20 | public const TYPE = 'send_unselected_if_any'; |
| 21 | |
| 22 | /** |
| 23 | * Create a new filter group with the specified configuration |
| 24 | * |
| 25 | * @param array $groupDefinition Configuration of group |
| 26 | * * $groupDefinition['name'] string Group name |
| 27 | * * $groupDefinition['title'] string i18n key for title (optional, can be omitted |
| 28 | * only if none of the filters in the group display in the structured UI) |
| 29 | * * $groupDefinition['priority'] int Priority integer. Higher means higher in the |
| 30 | * group list. |
| 31 | * * $groupDefinition['filters'] array Numeric array of filter definitions, each of which |
| 32 | * is an associative array to be passed to the filter constructor. However, |
| 33 | * 'priority' is optional for the filters. Any filter that has priority unset |
| 34 | * will be put to the bottom, in the order given. |
| 35 | * * $groupDefinition['whatsThisHeader'] string i18n key for header of "What's |
| 36 | * This" popup (optional). |
| 37 | * * $groupDefinition['whatsThisBody'] string i18n key for body of "What's This" |
| 38 | * popup (optional). |
| 39 | * * $groupDefinition['whatsThisUrl'] string URL for main link of "What's This" |
| 40 | * popup (optional). |
| 41 | * * $groupDefinition['whatsThisLinkText'] string i18n key of text for main link of |
| 42 | * "What's This" popup (optional). |
| 43 | */ |
| 44 | public function __construct( array $groupDefinition ) { |
| 45 | $groupDefinition['isFullCoverage'] = true; |
| 46 | $groupDefinition['type'] = self::TYPE; |
| 47 | |
| 48 | parent::__construct( $groupDefinition ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @inheritDoc |
| 53 | */ |
| 54 | protected function createFilter( array $filterDefinition ) { |
| 55 | return new ChangesListBooleanFilter( $filterDefinition ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Registers a filter in this group |
| 60 | * |
| 61 | * @param ChangesListBooleanFilter $filter |
| 62 | * @suppress PhanParamSignaturePHPDocMismatchHasParamType,PhanParamSignatureMismatch |
| 63 | */ |
| 64 | public function registerFilter( ChangesListBooleanFilter $filter ) { |
| 65 | $this->filters[$filter->getName()] = $filter; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @inheritDoc |
| 70 | */ |
| 71 | public function modifyQuery( IReadableDatabase $dbr, ChangesListSpecialPage $specialPage, |
| 72 | &$tables, &$fields, &$conds, &$query_options, &$join_conds, |
| 73 | FormOptions $opts, $isStructuredFiltersEnabled |
| 74 | ) { |
| 75 | /** @var ChangesListBooleanFilter $filter */ |
| 76 | foreach ( $this->getFilters() as $filter ) { |
| 77 | if ( $filter->isActive( $opts, $isStructuredFiltersEnabled ) ) { |
| 78 | $filter->modifyQuery( $dbr, $specialPage, $tables, $fields, $conds, |
| 79 | $query_options, $join_conds ); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @inheritDoc |
| 86 | */ |
| 87 | public function addOptions( FormOptions $opts, $allowDefaults, $isStructuredFiltersEnabled ) { |
| 88 | /** @var ChangesListBooleanFilter $filter */ |
| 89 | foreach ( $this->getFilters() as $filter ) { |
| 90 | $defaultValue = $allowDefaults ? $filter->getDefault( $isStructuredFiltersEnabled ) : false; |
| 91 | $opts->add( $filter->getName(), $defaultValue ); |
| 92 | } |
| 93 | } |
| 94 | } |