Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
11.63% |
5 / 43 |
|
14.29% |
1 / 7 |
CRAP | |
0.00% |
0 / 1 |
| HTMLTagFilter | |
11.90% |
5 / 42 |
|
14.29% |
1 / 7 |
148.00 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getTableRow | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| getDiv | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| getOOUI | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| getInputHTML | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getInputOOUI | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| shouldInfuseOOUI | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\HTMLForm\Field; |
| 4 | |
| 5 | use MediaWiki\ChangeTags\ChangeTags; |
| 6 | use MediaWiki\HTMLForm\HTMLFormField; |
| 7 | |
| 8 | /** |
| 9 | * Wrapper for ChangeTags::buildTagFilterSelector to use in HTMLForm |
| 10 | * |
| 11 | * @stable to extend |
| 12 | */ |
| 13 | class HTMLTagFilter extends HTMLFormField { |
| 14 | /** @var array */ |
| 15 | protected $tagFilter; |
| 16 | |
| 17 | /** @var bool */ |
| 18 | protected $activeOnly = ChangeTags::TAG_SET_ACTIVE_ONLY; |
| 19 | |
| 20 | /** @var bool */ |
| 21 | protected $useAllTags = ChangeTags::USE_ALL_TAGS; |
| 22 | |
| 23 | /** |
| 24 | * @inheritDoc |
| 25 | * |
| 26 | * Supported parameters: |
| 27 | * - activeOnly: true to filter for tags actively used (has hits), false for all |
| 28 | * - useAllTags: true to use all on-wiki tags, false to use software-defined tags only |
| 29 | */ |
| 30 | public function __construct( $params ) { |
| 31 | parent::__construct( $params ); |
| 32 | |
| 33 | if ( array_key_exists( 'activeOnly', $params ) ) { |
| 34 | $this->activeOnly = $params['activeOnly']; |
| 35 | } |
| 36 | if ( array_key_exists( 'useAllTags', $params ) ) { |
| 37 | $this->useAllTags = $params['useAllTags']; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** @inheritDoc */ |
| 42 | public function getTableRow( $value ) { |
| 43 | $this->tagFilter = ChangeTags::buildTagFilterSelector( |
| 44 | $value, |
| 45 | false, |
| 46 | $this->mParent->getContext(), |
| 47 | $this->activeOnly, |
| 48 | $this->useAllTags |
| 49 | ); |
| 50 | if ( $this->tagFilter ) { |
| 51 | return parent::getTableRow( $value ); |
| 52 | } |
| 53 | return ''; |
| 54 | } |
| 55 | |
| 56 | /** @inheritDoc */ |
| 57 | public function getDiv( $value ) { |
| 58 | $this->tagFilter = ChangeTags::buildTagFilterSelector( |
| 59 | $value, |
| 60 | false, |
| 61 | $this->mParent->getContext(), |
| 62 | $this->activeOnly, |
| 63 | $this->useAllTags |
| 64 | ); |
| 65 | if ( $this->tagFilter ) { |
| 66 | return parent::getDiv( $value ); |
| 67 | } |
| 68 | return ''; |
| 69 | } |
| 70 | |
| 71 | /** @inheritDoc */ |
| 72 | public function getOOUI( $value ) { |
| 73 | $this->tagFilter = ChangeTags::buildTagFilterSelector( |
| 74 | $value, |
| 75 | true, |
| 76 | $this->mParent->getContext(), |
| 77 | $this->activeOnly, |
| 78 | $this->useAllTags |
| 79 | ); |
| 80 | if ( $this->tagFilter ) { |
| 81 | return parent::getOOUI( $value ); |
| 82 | } |
| 83 | return new \OOUI\FieldLayout( new \OOUI\Widget() ); |
| 84 | } |
| 85 | |
| 86 | /** @inheritDoc */ |
| 87 | public function getInputHTML( $value ) { |
| 88 | if ( $this->tagFilter ) { |
| 89 | // we only need the select field, HTMLForm should handle the label |
| 90 | return $this->tagFilter[1]; |
| 91 | } |
| 92 | return ''; |
| 93 | } |
| 94 | |
| 95 | /** @inheritDoc */ |
| 96 | public function getInputOOUI( $value ) { |
| 97 | if ( $this->tagFilter ) { |
| 98 | // we only need the select field, HTMLForm should handle the label |
| 99 | return $this->tagFilter[1]; |
| 100 | } |
| 101 | return ''; |
| 102 | } |
| 103 | |
| 104 | /** @inheritDoc */ |
| 105 | protected function shouldInfuseOOUI() { |
| 106 | return true; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** @deprecated class alias since 1.42 */ |
| 111 | class_alias( HTMLTagFilter::class, 'HTMLTagFilter' ); |