Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| WikibaseEntitySelector | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| getJavaScriptClassName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getConfig | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\Math\Widget; |
| 4 | |
| 5 | use MediaWiki\Logger\LoggerFactory; |
| 6 | use OOUI\SearchInputWidget; |
| 7 | |
| 8 | class WikibaseEntitySelector extends SearchInputWidget { |
| 9 | |
| 10 | /** @var string */ |
| 11 | protected $paramType = 'item'; |
| 12 | |
| 13 | // This should be \Wikimedia\ParamValidator\ParamValidator::PARAM_TYPE of the target API |
| 14 | private const ALLOWED_TYPES = [ 'entity-schema', 'form', 'item', 'lexeme', 'property', 'sense' ]; |
| 15 | |
| 16 | public function __construct( array $config = [] ) { |
| 17 | parent::__construct( $config ); |
| 18 | $paramType = $config['paramType'] ?? false; |
| 19 | if ( $paramType ) { |
| 20 | if ( in_array( $paramType, self::ALLOWED_TYPES, true ) ) { |
| 21 | $this->paramType = $paramType; |
| 22 | } else { |
| 23 | LoggerFactory::getInstance( 'Math' )->warning( |
| 24 | 'Invalid type', [ $paramType ] ); |
| 25 | } |
| 26 | } |
| 27 | $this->addClasses( [ 'mw-math-widget-wb-entity-selector' ] ); |
| 28 | } |
| 29 | |
| 30 | protected function getJavaScriptClassName(): string { |
| 31 | return 'mw.widgets.MathWbEntitySelector'; |
| 32 | } |
| 33 | |
| 34 | /** @inheritDoc */ |
| 35 | public function getConfig( &$config ) { |
| 36 | $config['paramType'] = $this->paramType; |
| 37 | return parent::getConfig( $config ); |
| 38 | } |
| 39 | } |