2015-08-11 15:12:36 +00:00
|
|
|
<?php
|
2017-12-28 15:17:33 +00:00
|
|
|
|
2015-08-11 15:12:36 +00:00
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
|
|
2024-01-02 18:01:20 +00:00
|
|
|
use OOUI\CheckboxInputWidget;
|
|
|
|
|
use OOUI\Exception;
|
|
|
|
|
use OOUI\FieldLayout;
|
|
|
|
|
use OOUI\Widget;
|
|
|
|
|
|
2015-08-11 15:12:36 +00:00
|
|
|
/**
|
|
|
|
|
* Namespace input widget. Displays a dropdown box with the choice of available namespaces, plus two
|
|
|
|
|
* checkboxes to include associated namespace or to invert selection.
|
2017-12-28 15:17:33 +00:00
|
|
|
*
|
|
|
|
|
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
|
|
|
* @license MIT
|
2015-08-11 15:12:36 +00:00
|
|
|
*/
|
2024-01-02 18:01:20 +00:00
|
|
|
class ComplexNamespaceInputWidget extends Widget {
|
2015-08-11 15:12:36 +00:00
|
|
|
|
|
|
|
|
protected $config;
|
|
|
|
|
protected $namespace;
|
|
|
|
|
protected $associated = null;
|
|
|
|
|
protected $associatedLabel = null;
|
|
|
|
|
protected $invert = null;
|
|
|
|
|
protected $invertLabel = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $config Configuration options
|
2018-01-07 10:38:43 +00:00
|
|
|
* - array $config['namespace'] Configuration for the NamespaceInputWidget
|
|
|
|
|
* dropdown with list of namespaces
|
|
|
|
|
* - string $config['namespace']['includeAllValue'] If specified,
|
|
|
|
|
* add an "all namespaces" option to the dropdown, and use this as the input value for it
|
|
|
|
|
* - array|null $config['invert'] Configuration for the "invert selection"
|
|
|
|
|
* CheckboxInputWidget. If null, the checkbox will not be generated.
|
|
|
|
|
* - array|null $config['associated'] Configuration for the "include associated namespace"
|
|
|
|
|
* CheckboxInputWidget. If null, the checkbox will not be generated.
|
|
|
|
|
* - array $config['invertLabel'] Configuration for the FieldLayout with label
|
|
|
|
|
* wrapping the "invert selection" checkbox
|
|
|
|
|
* - string $config['invertLabel']['label'] Label text for the label
|
|
|
|
|
* - array $config['associatedLabel'] Configuration for the FieldLayout with label
|
|
|
|
|
* wrapping the "include associated namespace" checkbox
|
|
|
|
|
* - string $config['associatedLabel']['label'] Label text for the label
|
2024-01-02 18:01:20 +00:00
|
|
|
*
|
|
|
|
|
* @throws Exception
|
2015-08-11 15:12:36 +00:00
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public function __construct( array $config = [] ) {
|
2015-08-11 15:12:36 +00:00
|
|
|
// Configuration initialization
|
|
|
|
|
$config = array_merge(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-08-11 15:12:36 +00:00
|
|
|
// Config options for nested widgets
|
2016-02-17 09:09:32 +00:00
|
|
|
'namespace' => [],
|
|
|
|
|
'invert' => [],
|
|
|
|
|
'invertLabel' => [],
|
|
|
|
|
'associated' => [],
|
|
|
|
|
'associatedLabel' => [],
|
|
|
|
|
],
|
2015-08-11 15:12:36 +00:00
|
|
|
$config
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
parent::__construct( $config );
|
|
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
|
$this->config = $config;
|
|
|
|
|
|
|
|
|
|
$this->namespace = new NamespaceInputWidget( $config['namespace'] );
|
|
|
|
|
if ( $config['associated'] !== null ) {
|
2024-01-02 18:01:20 +00:00
|
|
|
$this->associated = new CheckboxInputWidget( array_merge(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'value' => '1' ],
|
2015-08-11 15:12:36 +00:00
|
|
|
$config['associated']
|
|
|
|
|
) );
|
|
|
|
|
// TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
|
2024-01-02 18:01:20 +00:00
|
|
|
$this->associatedLabel = new FieldLayout(
|
2015-08-11 15:12:36 +00:00
|
|
|
$this->associated,
|
|
|
|
|
array_merge(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'align' => 'inline' ],
|
2015-08-11 15:12:36 +00:00
|
|
|
$config['associatedLabel']
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ( $config['invert'] !== null ) {
|
2024-01-02 18:01:20 +00:00
|
|
|
$this->invert = new CheckboxInputWidget( array_merge(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'value' => '1' ],
|
2015-08-11 15:12:36 +00:00
|
|
|
$config['invert']
|
|
|
|
|
) );
|
|
|
|
|
// TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
|
2024-01-02 18:01:20 +00:00
|
|
|
$this->invertLabel = new FieldLayout(
|
2015-08-11 15:12:36 +00:00
|
|
|
$this->invert,
|
|
|
|
|
array_merge(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'align' => 'inline' ],
|
2015-08-11 15:12:36 +00:00
|
|
|
$config['invertLabel']
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
|
$this
|
2016-02-17 09:09:32 +00:00
|
|
|
->addClasses( [ 'mw-widget-complexNamespaceInputWidget' ] )
|
2015-08-11 15:12:36 +00:00
|
|
|
->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getJavaScriptClassName() {
|
|
|
|
|
return 'mw.widgets.ComplexNamespaceInputWidget';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getConfig( &$config ) {
|
|
|
|
|
$config = array_merge(
|
|
|
|
|
$config,
|
|
|
|
|
array_intersect_key(
|
|
|
|
|
$this->config,
|
2015-09-26 18:19:00 +00:00
|
|
|
array_fill_keys(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-09-26 18:19:00 +00:00
|
|
|
'namespace',
|
|
|
|
|
'invert',
|
|
|
|
|
'invertLabel',
|
|
|
|
|
'associated',
|
|
|
|
|
'associatedLabel'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-09-26 18:19:00 +00:00
|
|
|
true
|
|
|
|
|
)
|
2015-08-11 15:12:36 +00:00
|
|
|
)
|
|
|
|
|
);
|
2018-01-02 22:25:01 +00:00
|
|
|
$config['namespace']['dropdown']['$overlay'] = true;
|
2015-08-11 15:12:36 +00:00
|
|
|
return parent::getConfig( $config );
|
|
|
|
|
}
|
|
|
|
|
}
|